全程序
- #include<reg52.h>
- #include<intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- #include "4.h"
- uchar table []=" 4.c ";
- uchar table1[]=" asdasdas ";
- uchar table2[]=" SDASDSDD ";
- uchar table3[]=" ò»¶tèyËÄ ";
- uchar k;
- uchar key1num,key2num;
- sbit LCD_SID=P0^6;
- sbit LCD_SCLK=P0^5;
- sbit key1=P1^1;
- sbit key2=P1^3;
- void delay_ms(uint z)
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- void sendbyte(unsigned char bbyte)
- {
- unsigned char i;
- for(i=0;i<8;i++)
- {
- LCD_SID=bbyte&0x80;
- LCD_SCLK=1;
- LCD_SCLK=0;
- bbyte<<=1; //×óòÆ
- }
- }
- void write(bit start, unsigned char ddata)
- {
- unsigned char start_data,Hdata,Ldata;
- if(start==0)
- start_data=0xf8;
- else
- start_data=0xfa;
-
- Hdata=ddata&0xf0;
- Ldata=(ddata<<4)&0xf0;
- sendbyte(start_data);
- delay_ms(1); //Ñóê±
- sendbyte(Hdata);
- delay_ms(1);
- sendbyte(Ldata);
- delay_ms(1);
- }
- void chinese(uchar x,uchar y,uchar k,uchar *p)
- {
- uchar hang,out,i;
- y=y-1;
- switch(x)
- {
- case 1:hang=0x80;break;
- case 2:hang=0x90;break;
- case 3:hang=0x88;break;
- case 4:hang=0x98;break;
- }
- out=hang+y;
- write(0,out);
- for(i=0;i<k*2;i++) {
- write(1,*p);
- p++;
- }
- //write(1,p);
- }
- void english(uchar x,uchar y,uchar k,uchar *p)
- {
- uchar hang,out,i;
- y=y-1;
-
- switch(x)
- {
- case 1:hang=0x80;break;
- case 2:hang=0x90;break;
- case 3:hang=0x88;break;
- case 4:hang=0x98;break;
- }
- out=hang+y;
- write(0,out);
- for(i=0;i<k;i++) {
- write(1,*p);
- p++;
- }
- // write(1,p);
- }
- void lcd_init()
- {
- write(0,0x30);
- write(0,0x0F);
- write(0,0x01);
- delay_ms(10);
- }
- void display1()
- {
- write(0,0x01);
- english(1,1,15,table);
- english(2,1,15,table);
- english(3,1,15,table);
- english(4,1,15,table);
- }
- void display2()
- {
- write(0,0x01);
- english(1,1,15,table2);
- english(2,1,15,table2);
- english(3,1,15,table2);
- english(4,1,15,table2);
- }
- void display3()
- {
- write(0,0x01);
- english(1,1,15,table3);
- english(2,1,15,table3);
- english(3,1,15,table3);
- english(4,1,15,table3);
- }
- void main()
- {
- lcd_init();
- while(1)
-
- if(key1==0)
- {
- delay_ms(1);
- if(key1==0)
- {
- while(!key1);
- k++;
- }
- }
- if(key2==0)
- {
- delay_ms(1);
- if(key2==0)
- {
- while(!key2);
- k--;
- }
- }
- switch(k)
- {
- case 1:display1();break;
- case 2:display2();break;
- case 3:display3();break;
- }
- }
复制代码
|