如题,请大神们看看是不是程序的问题!#include <pic18.h>#include <stdio.h>#include <stdlib.h>
#define uint unsigned int#define uchar unsigned char #define res PORTCbits.RC5#define sce PORTCbits.RC4 //片选PORTAbits.RA0 #define dc PORTCbits.RC3 //1些数据,0写指令#define sdin PORTCbits.RC6 //数据#define sclk PORTCbits.RC7 //时钟
void LCD_init(void);void init(void);void LCD_write_byte(unsigned char dt,unsigned char command);void delay(uint x);void LCD_set_XY(unsigned char X,unsigned char Y);void LCD_clear(void);void LCD_write_char(unsigned char x,unsigned char y,unsigned char c);void LCD_write_english_string(unsigned char X,unsigned char Y,char *s);
void main(void){ init(); LCD_init();//初始化LCD模块 LCD_clear();//清屏 while(1) { LCD_write_english_string(0,0," Welcome to "); LCD_write_english_string(0,1," Amy studio "); LCD_write_english_string(0,2,"amy-studio.com"); LCD_write_english_string(0,3," Nokia5110 LCD"); }// while(1) // {// asm("CLRWDT");// }}
void init(void) //
单片机初始化{ asm("CLRWDT"); ADCON1=0x06; TRISC=0x00; PORTB=0x00;}
void LCD_write_byte(unsigned char dt,unsigned char command){ unsigned char i; sce = 0; //片选 dc = command; //1写数据,0写指令 for(i=0;i<8;i++) //循环传送8个bit { if(dt&0x80) sdin=1; else sdin=0; dt=dt<<1; sclk = 0; asm("CLRWDT"); asm("CLRWDT"); sclk=1; //在时钟上升沿采样 } dc=1; sce=1; sdin=1;}
void LCD_init(void) //LCD初始化{ res=0; delay(10); res=1; sce=0; //sce为高时,串行口被初始化。sce为高时忽略始时钟信号。 delay(10); sce=1; LCD_write_byte(0x21,0);//0b0010 0001LCD功能设置:
芯片活动,水平寻址,使用扩展指令 LCD_write_byte(0xc6,0);//设置VOP值 LCD_write_byte(0x06,0);//温度校正 LCD_write_byte(0x13,0);//1:48 LCD_write_byte(0x20,0);//LCD功能设置:新品活动,水平寻址,使用基本指令 LCD_clear(); LCD_write_byte(0x0c,0);//设定显示配置:普通模式
sce=0;}
void LCD_set_XY(unsigned char X,unsigned char Y)// 位置选择{ LCD_write_byte(0x40|Y,0); LCD_write_byte(0x80|X,0);}
void LCD_clear(void) //清屏{ unsigned char t; unsigned char k; LCD_set_XY(0,0); for(t=0;t<6;t++) { for(k=0;k<84;k++) { LCD_write_byte(0x00,1); asm("CLRWDT"); } }}
void LCD_write_char(unsigned char x,unsigned char y,unsigned char c)//写数据{ unsigned char line; c -= 32; LCD_set_XY(x*6,y); for(line=0;line<6;line++) LCD_write_byte(font6x8[c][line],1);}
void delay(uint x)//延时程序{ uint a,b; for(a=x;a>0;a--) for(b=110;b>0;b--);}
void LCD_write_english_string(unsigned char X,unsigned char Y,char *s){ LCD_set_XY(X,Y); while(*s) { LCD_write_char(X,Y,*s); s++; }}
- #include <pic18.h>
- #include <stdio.h>
- #include <stdlib.h>
- #define uint unsigned int
- #define uchar unsigned char
- #define res PORTCbits.RC5
- #define sce PORTCbits.RC4 //片选PORTAbits.RA0
- #define dc PORTCbits.RC3 //1些数据,0写指令
- #define sdin PORTCbits.RC6 //数据
- #define sclk PORTCbits.RC7 //时钟
- void LCD_init(void);
- void init(void);
- void LCD_write_byte(unsigned char dt,unsigned char command);
- void delay(uint x);
- void LCD_set_XY(unsigned char X,unsigned char Y);
- void LCD_clear(void);
- void LCD_write_char(unsigned char x,unsigned char y,unsigned char c);
- void LCD_write_english_string(unsigned char X,unsigned char Y,char *s);
- void main(void)
- {
- init();
- LCD_init();//初始化LCD模块
- LCD_clear();//清屏
- while(1)
- {
- LCD_write_english_string(0,0," Welcome to ");
- LCD_write_english_string(0,1," Amy studio ");
- LCD_write_english_string(0,2,"amy-studio.com");
- LCD_write_english_string(0,3," Nokia5110 LCD");
- }
- // while(1)
- // {
- // asm("CLRWDT");
- // }
- }
- void init(void) //单片机初始化
- {
- asm("CLRWDT");
- ADCON1=0x06;
- TRISC=0x00;
- PORTB=0x00;
- }
- void LCD_write_byte(unsigned char dt,unsigned char command)
- {
- unsigned char i;
- sce = 0; //片选
- dc = command; //1写数据,0写指令
- for(i=0;i<8;i++) //循环传送8个bit
- {
- if(dt&0x80)
- sdin=1;
- else
- sdin=0;
- dt=dt<<1;
- sclk = 0;
- asm("CLRWDT");
- asm("CLRWDT");
- sclk=1; //在时钟上升沿采样
- }
- dc=1;
- sce=1;
- sdin=1;
- }
- void LCD_init(void) //LCD初始化
- {
- res=0;
- delay(10);
- res=1;
- sce=0; //sce为高时,串行口被初始化。sce为高时忽略始时钟信号。
- delay(10);
- sce=1;
- LCD_write_byte(0x21,0);//0b0010 0001LCD功能设置:芯片活动,水平寻址,使用扩展指令
- LCD_write_byte(0xc6,0);//设置VOP值
- LCD_write_byte(0x06,0);//温度校正
- LCD_write_byte(0x13,0);//1:48
- LCD_write_byte(0x20,0);//LCD功能设置:新品活动,水平寻址,使用基本指令
- LCD_clear();
- LCD_write_byte(0x0c,0);//设定显示配置:普通模式
- sce=0;
- }
- void LCD_set_XY(unsigned char X,unsigned char Y)// 位置选择
- {
- LCD_write_byte(0x40|Y,0);
- LCD_write_byte(0x80|X,0);
- }
- void LCD_clear(void) //清屏
- {
- unsigned char t;
- unsigned char k;
- LCD_set_XY(0,0);
- for(t=0;t<6;t++)
- {
- for(k=0;k<84;k++)
- {
- LCD_write_byte(0x00,1);
- asm("CLRWDT");
- }
- }
- }
- void LCD_write_char(unsigned char x,unsigned char y,unsigned char c)//写数据
- {
- unsigned char line;
- c -= 32;
- LCD_set_XY(x*6,y);
- for(line=0;line<6;line++)
- LCD_write_byte(font6x8[c][line],1);
- }
- void delay(uint x)//延时程序
- {
- uint a,b;
- for(a=x;a>0;a--)
- for(b=110;b>0;b--);
- }
- void LCD_write_english_string(unsigned char X,unsigned char Y,char *s)
- {
- LCD_set_XY(X,Y);
- while(*s)
- {
- LCD_write_char(X,Y,*s);
- s++;
- }
- }
复制代码一周热门 更多>