#define uint unsigned int #define uchar unsigned char #include #include #include #define LCD_databus P0 sbit rs=P3^0; sbit e=P3^1; sbit cs2=P3^2; sbit cs1=P3^3; sbit rw = P2^0; sbit key1 = P3^5; void delay(uint x) //?¨®¨º¡À { uchar i; while(x--) for(i=0;i<120;i++); } void wr_busy() //?D?|P0^7 { rs = 0; rw = 1; P0 = 0x00; e = 1; while(P0 & 0x80); e = 0; } void wr_12864(uchar dat,uchar i,uchar b) // ?¨¹¨¢?/¨ºy?Y/?¨¢D¡ä { wr_busy(); e=0; rs = dat; rw = b; LCD_databus = i; _nop_(); e = 1; _nop_(); e = 0; } void xuanping(uchar ping)//???¨¢ { switch(ping) { case 0:cs1=0;cs2=0;break; case 1:cs1=1;cs2=0;break; case 2:cs1=0;cs2=1;break; } } void qingping(uchar ping)//i=0¦Ì?¨º¡Ào¨°¡ê?¡ä¨®0¨°3¦Ì?0~7DD¦Ì?¦Ì¨²0¨¢D?a¨º?¨¦¡§?¨¨???¨¢ { uchar i,j; xuanping(ping); for(i=0;i<8;i++) { wr_12864(0,0xb8|i,0); wr_12864(0,0x40,0); for(j=0;j<64;j++) wr_12864(1,0x00,0); } } void init_12864()//3?¨º??¡¥ { wr_12864(0,0x3e,0); wr_12864(0,0x3f,0); qingping(0); } void lcd_12864(char ping,char ye,lie,char *p) //¨¦¡§?¨¨??¨º? { char i; xuanping(ping); wr_12864(0,0xb8|ye,0); //0xb8¨°3¨º¡Á?¡¤ wr_12864(0,0x40|lie,0); //0x40¨¢D¦Ì??¡¤ for(i=0;i<16;i++) wr_12864(1,p[i],0); wr_12864(0,0xb8|ye+1,0); wr_12864(0,0x40|lie,0); for(i=16;i<31;i++) wr_12864(1,p[i],0); } void disp() { init_12864(); lcd_12864(2,0,3*16,yi); } void disp_1() //2?¦Ì£¤1¡êo???| { init_12864(); lcd_12864(2,0,3*16,ge);//2=¡Á¨®¡ã??¨¢¨®DD¡ì¡ê?0=¦Ì¨²0¨°3¡ê?2=¦Ì¨²1¨¢D¡ê?ge¨¦¡§?¨¨ lcd_12864(1,0,0*16,ji); } void disp_2() //2?¦Ì£¤2:??¨°3 { init_12864(); lcd_12864(2,0,3*16,xia); lcd_12864(1,0,0*16,ye); } void disp_3() { init_12864(); lcd_12864(2,0,3*16,chui); lcd_12864(1,0,0*16,ji); } void main() { char one=0; while(1) { if(key1 == 0) { while(key1 == 0); one++; } switch(one)//key1¡ã¡ä?£¤ { case 0: disp();delay(100); break; case 1: disp_1();delay(100);break; case 2: disp_2();delay(100);break; case 3: disp_3();delay(100);break; case 4: one = 0; break; } } }