#include #include "NumTable.h" #include "type.h" #define Lcd_CE_h P1OUT|=BIT5 #define Lcd_CE_l P1OUT&=~BIT5 #define Lcd_RST_h P2OUT|=BIT0 #define Lcd_RST_l P2OUT&=~BIT0 #define Lcd_DC_h P1OUT|=BIT4 #define Lcd_DC_l P1OUT&=~BIT4 #define Lcd_DN_h P1OUT|=BIT3 #define Lcd_DN_l P1OUT&=~BIT3 #define Lcd_SCLK_h P1OUT|=BIT2 #define Lcd_SCLK_l P1OUT&=~BIT2 //void Lcd_led(int o); void msgbox(uchar myData,uchar myCOMMON); void Lcd_Init(); void Lcd_Goto(uchar x,uchar y); void Lcd_Cls(); void Lcd_Black(); void Lcd_Num_Write(char a,char x,char y); void Lcd_Char_Write(char a,char x,char y); void LCD_write_char(unsigned char c); //************************************************************************* // LCD背光开关 //************************************************************************* /*void Lcd_led(int o) { if(!!o) {Led_on;} else {Led_off;} }*/ //************************************************************************* // LCD5110数据/命令写入 //************************************************************************* void msgbox(uchar myData,uchar myCOMMON) { uchar i; Lcd_CE_l; if(myCOMMON==0) Lcd_DC_l; else Lcd_DC_h; for(i=0;i<8;i++) { if(myData&0x80) Lcd_DN_h; else Lcd_DN_l; myData=myData<<1; Lcd_SCLK_l; Lcd_SCLK_h; } Lcd_DC_h; Lcd_DN_h; Lcd_CE_h; } //************************************************************************* // LCD5110初始化函数 //************************************************************************* void Lcd_Init() { Lcd_RST_l; delay_us(250); Lcd_RST_h; Lcd_CE_h; Lcd_DN_h; Lcd_DC_h; Lcd_SCLK_h; msgbox(0x21,0); delay_us(100); msgbox(0xc0,0); delay_us(100); msgbox(0x20,0); delay_us(100); msgbox(0x0c,0); delay_us(100); } //************************************************************************* // LCD5110坐标函数 //************************************************************************* void Lcd_Goto(uchar x,uchar y) { msgbox(0x40|y,0);//列 msgbox(0x80|x,0);//行 } //************************************************************************* // LCD5110清屏函数 //************************************************************************* void Lcd_Cls() { uchar i,j; Lcd_Goto(0,0); //坐标归位 for(i=6;i>0;i--) { for(j=84;j>0;j--) { msgbox(0x00,1); } } } //************************************************************************* // LCD5110黑屏函数 //************************************************************************* void Lcd_Black() { uchar i,j; Lcd_Goto(0,0); //坐标归位 for(i=6;i>0;i--) { for(j=84;j>0;j--) { msgbox(0xff,1); } } } //写字符 void Display_char(unsigned char hang,unsigned char lie,char *s) { unsigned char line; Lcd_Goto(hang,lie); while(*s) { for(line=0;line<6;line++) { Lcd_DC_h; // *s- =32; msgbox(font6x8[*s - 32][line],1); } s++; } Lcd_CE_h; } //************************************************************************* // LCD5110汉字写入 //************************************************************************* void Lcd_Char_Write(char a,char x,char y) { Lcd_Goto(x*16,y*2); uchar i; for(i=0;i<16;i++) { msgbox(type[a*2][i],1); } Lcd_Goto(x*16,y*2+1); for(i=0;i<16;i++) { msgbox(type[a*2+1][i],1); } } void main( ) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; P1DIR|=0xff; P2DIR|=BIT0; Lcd_Init(); Lcd_Cls(); delay_us(250); Display_char(4,4,"A"); while(1); }