- #include<reg52.h>
- #define LCD1602_DB P0
- sbit LCD1602_RS=P1^0;
- sbit LCD1602_RW=P1^1;
- sbit LCD1602_E=P1^5;
- void InitLcd1602();
- void delay_ms(unsigned int d);
- void ScanKeyboard();
- void LcdShowStr(unsigned char x,unsigned char y,unsigned char*str);
- void LcdShowDat(unsigned char x,unsigned char y,unsigned char dat);
- unsigned char cnt=0;
- unsigned char w=0,key=0;
- unsigned char code KeyCode[]=
- {0xe7,0xd7,0xb7,0x77,0xeb,0xdb,0xbb,0x7b,0xed,0xdd,0xdb,0xbd,0x7d,0xee,0xde,0xbe,0x7e};
- void main()
- {
- unsigned char temp;
- unsigned char str[]="hello";
- TMOD=0X01;
- TH0=0X4C;
- TL0=0X00;
- IE=0X82;
- TR0=1;
- InitLcd1602();
- LcdShowStr(2,0,str);
- while(1);
- {
- ScanKeyboard();
- temp=w;
- LcdShowDat(4,1,temp);
- }
- }
- void LcdWaitReady()
- {
- unsigned char sta;
- LCD1602_DB=0XFF;
- LCD1602_RS=0;
- LCD1602_RW=1;
- do{
- LCD1602_E=1;
- sta=LCD1602_DB;
- LCD1602_E=0;
- }
- while(sta&0x80);
- }
- void LcdWriteCmd(unsigned char cmd)
- {
- LcdWaitReady();
- LCD1602_RS=0;
- LCD1602_RW=0;
- LCD1602_DB=cmd;
- LCD1602_E=1;
- LCD1602_E=0;
- }
- void LcdWriteDat(unsigned char dat)
- {
- LcdWaitReady();
- LCD1602_RS=1;
- LCD1602_RW=0;
- LCD1602_DB=dat;
- LCD1602_E=1;
- LCD1602_E=0;
- }
- void LcdSetCursor(unsigned char x,unsigned char y)
- {
- unsigned char addr;
- if(y==0)
- addr=0x00+x;
- else
- addr=0x40+x;
- LcdWriteCmd(addr|0x80);
- }
- void LcdShowStr(unsigned char x,unsigned char y,unsigned char*str)
- {
- LcdSetCursor(x,y);
- while(*str!='\0')
- {
- LcdWriteDat(*str++);
- }
- }
- void InitLcd1602()
- {
- LcdWriteCmd(0x38);
- LcdWriteCmd(0x0c);
- LcdWriteCmd(0x06);
- LcdWriteCmd(0x01);
- }
- void ScanKeyboard()
- {
- unsigned char scan1,scan2,keyboard;
- unsigned char i;
- P2=0xf0;
- scan1=P2;
- if((scan1&0xf0)!=0xf0)
- {
- delay_ms(10);
- scan1=P2;
- if((scan1&0xf0)!=0xf0)
- {
- P2=0xf0;
- scan2=P2;
- keyboard=scan1|scan2;
- while((P2&0x0f)!=0x0f)
- for(i=0;i<=15;i++)
- {
- if(keyboard==KeyCode[i])
- key=i;
- }
- }
- }
- }
- void clock()interrupt 1
- {
- unsigned char i,r;
- cnt++;
- TH0=0X4C;
- TL0=0X00;
- if(i==1)
- {
- w=0x20;
- }
- if(i==2)
- {
- for(r=0;cnt<=20;r++)
- {
- w=0x61+0x01;
- if(r==3)
- {
- r=0;
- w=0x61;
- }
- }
- }
- }
- void delay_ms(unsigned int d)
- {
- unsigned char i;
- while(d--)
- {
- for(i=0;i<=110;i++);
- }
- }
复制代码
ABC.C(90): warning C206: 'ScanKeyboard': missing function-prototype
|