预览加载中,请您耐心等待几秒...
1/5
2/5
3/5
4/5
5/5

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

#include<reg51.h> #include<intrins.h> #defineucharunsignedchar #definekeyportP1 sbitRS=P2^4; sbitRW=P2^5; sbitEN=P2^6; ucharcodetab[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; bitkeyflag; voiddelayus(uchart) { while(--t); } voiddelayms(uchart) { while(t--) { delayus(245); delayus(245); } } voidLCD_readbusy(void) { P0=0Xff; RS=0; RW=1; EN=1; while(P0&0x80); _nop_(); EN=0; } voidLCD_write_com(ucharcom) { LCD_readbusy(); RS=0; RW=0; EN=1; P0=com; _nop_(); EN=0; } voidLCD_write_Data(ucharData) { LCD_readbusy(); RS=1; RW=0; EN=1; P0=Data; _nop_(); EN=0; } voidLCD_clear(void) { LCD_write_com(0x01); delayms(5); } voidLCD_write_char(ucharx,uchary,ucharData) { if(y==0) { LCD_write_com(0x80+x); } else { LCD_write_com(0xc0+x); } LCD_write_Data(Data); } voidLCD_write_string(ucharx,uchary,uchar*p) { if(y==0) { LCD_write_com(0x80+x); } else { LCD_write_com(0xc0+x); } while(*p) { LCD_write_Data(*p); p++; } } voidLCD_init(void) { LCD_write_com(0x38); delayms(5); LCD_write_com(0x38); delayms(5); LCD_write_com(0x38); delayms(5); LCD_write_com(0x38); LCD_write_com(0x08); LCD_write_com(0x01); LCD_write_com(0x06); delayms(5); LCD_write_com(0x0c); } ucharkeyscan(void) { ucharh,l; P1=0xf0; if(P1!=0xf0) { delayms(15); if(P1!=0xf0) { P1=0x0f; h=P1&0x0f; P1=0xf0; l=P1&0xf0; while(P1!=0xf0); return(h+l); } return(0xff); } } ucharkeypro(void) { switch(keyscan()) { case0x7e:return0;break;//0按下相应的键显示相对应的码值 case0xbe:return1;break;//1 case0xde:return2;break;//2 case0xee:return3;break;//3 case0x7d:return4;break;//4 case0xbd:return5;break;//5 case0xdd:return6;break;//6 case0xed:return7;break;//7 case0x7b:return8;break;//8 case0xbb:return9;break;//9 case0xdb:return10;break;//a case0xeb:return11;break;//b case0x77:return12;break;//c case0xb7:return13;break;//d case0xd7:return14;break;//e case0xe7:return15;break;//f default:return0xff;break; } } voidp_INT0()interrupt0 { keyflag=1; } voidmain() { ucharnum; uchari=0,j=0; LCD_init(); EA=1;//全局中断开 EX0=1;//外部中断0