已知BUG:显示”液晶12864驱动程序“乱码,就是中文和西文必须分开显示 代码: 主函数main.c #include <msp430g2553.h> #include "lcd12864.h" void main() { WDTCTL = WDTPW + WDTHOLD;
BCSCTL1 = CALBC1_8MHZ; // 多谐2楼指导 DCOCTL = CALDCO_8MHZ; P1DIR|=0xff; P2DIR|=0xff;
lcdreset(); //初始化LCD12864屏 clrscreen();
write_com(0x80); //位置控制 printstring("液晶12864");
write_com(0x90); //位置控制 write_swcom(0x8a);//写单个数控制字 write_swdat(0x35); write_swdat(0x36);
write_com(0x95); //位置控制 write_swdat(0x38);
write_com(0x88); //位置控制 printstring("液晶12864"); while(1); }
12864.c #include <msp430g2553.h> //包含库文件
#define uint unsigned int #define uchar unsigned char uchar LCD_table1[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};//0123456789
//sbit LCD_RS = P2.0; //sbit LCD_RW = P2.1; //sbit LCD_EN = P2.2; //sbit LCD_PSB= P2.3; //sbit LCD_RST= P2.4;
#define LCD_DataIn P1DIR=0x00;//数据口方向设置为输入 #define LCD_DataOut P1DIR=0xff;//数据口方向为输出 #define LCD2MCU_Data P1IN #define MCU2LCD_Data P1OUT
#define LCD_RS_L P2OUT&=0xfe; #define LCD_RS_H P2OUT|=0x01; #define LCD_RW_L P2OUT&=0xfd; #define LCD_RW_H P2OUT|=0x02; #define LCD_EN_L P2OUT&=0xfb; #define LCD_EN_H P2OUT|=0x04; #define LCD_PSB_L P2OUT&=0xf7; #define LCD_PSB_H P2OUT|=0x08; #define LCD_RST_L P2OUT&=0xef; #define LCD_RST_H P2OUT|=0x10;
void delay_1ms() { uint i; for(i=0;i<1140;i++); }
void delay_nms(uint n) { uint j; for(j=0;j<n;j++) delay_1ms(); } /*------------------检查忙位-----------------------------*/ void chk_busy() { uchar lcdtemp=0;
LCD_RS_L; LCD_RW_H; LCD_DataIn; do { LCD_EN_H; _NOP(); lcdtemp = LCD2MCU_Data; LCD_EN_L; } while(lcdtemp&0x80); LCD_DataOut; }
/*------------------写命令到LCD------------------------------*/ void write_com(uchar cmdcode) { chk_busy(); LCD_RW_L; MCU2LCD_Data = cmdcode; LCD_EN_H; _NOP(); LCD_EN_L; }
/*-------------------写数据到LCD----------------------------*/ void write_data(uchar Dispdata) { chk_busy(); LCD_RS_H; LCD_RW_L;
MCU2LCD_Data = Dispdata; LCD_EN_H; _NOP(); LCD_EN_L; }
/*------------------初始化LCD屏--------------------------*/ void lcdreset() { LCD_RST_L; delay_nms(60); LCD_RST_H; delay_nms(1); LCD_PSB_H;
delay_nms(600); write_com(0x30); delay_nms(10); //选择基本指令集 write_com(0x02); //地址归位 delay_nms(5); write_com(0x0c); //开显示(无游标、不反白) delay_nms(10); write_com(0x01); //清除显示,并且设定地址指针为00H delay_nms(500); write_com(0x06); //指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位 delay_nms(10); }
/*------------------显示字符串--------------------------*/ void printstring(uchar *s) { while(*s>0) { write_data(*s); s++; delay_nms(5); } }
/*------------------清屏命令--------------------------*/ void clrscreen() { write_com(0x01); delay_nms(10); }
void write_swcom(uchar com) { LCD_RS_L; LCD_RW_L; delay_nms(1); MCU2LCD_Data=com; LCD_EN_L; delay_nms(1); }
void write_swdat(uchar dat) { chk_busy(); LCD_RS_H; LCD_RW_L; delay_nms(1); MCU2LCD_Data=dat; LCD_EN_H; delay_nms(1); LCD_EN_L; delay_nms(1); }
12864.h #ifndef LCD12864_H_ #define LCD12864_H_ #define uint unsigned int #define uchar unsigned char
extern void delay_1ms(); extern void delay_nms(uint n); extern void chk_busy(); extern void write_com(uchar cmdcode); extern void write_data(uchar Dispdata); extern void lcdreset(); extern void printstring(uchar *s); extern void clrscreen(); extern void write_swcom(uchar com); extern void write_swdat(uchar dat);
#endif /* LCD12864_H_ */
[ 本帖最后由 李晓航Elijah 于 2012-7-15 16:43 编辑 ]
|