完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
请问下边的代码哪有问题啊,下到板子上按键全是乱的,不按也是乱的 #include #define KEY P1 unsigned char display[10]; int data_a; short keynum; ***it LCD_1602_RW = P2^5; ***it LCD_1602_RS = P2^6; ***it LCD_1602_E = P2^7; void delay1ms(unsigned char c) { unsigned char a,b; for (; c>0; c--) { for (b=199;b>0;b--) { for(a=1;a>0;a--); } } } void LCDWriteCom(unsigned char com) { LCD_1602_E=0; LCD_1602_RW=0; LCD_1602_RS=0; P0=com; delay1ms(1); LCD_1602_E=1; delay1ms(1); LCD_1602_E=0; P0=com<<4; delay1ms(1); LCD_1602_E=1; delay1ms(1); LCD_1602_E=0; } void LCDWriteData(unsigned char dat) { LCD_1602_E=0; LCD_1602_RW=0; LCD_1602_RS=1; P0=dat; delay1ms(1); LCD_1602_E=1; delay1ms(1); LCD_1602_E=0; P0=dat<<4; delay1ms(1); LCD_1602_E=1; delay1ms(1); LCD_1602_E=0; } void IniLCD() { LCDWriteCom(0x32); LCDWriteCom(0x28); LCDWriteCom(0x0c); LCDWriteCom(0x06); LCDWriteCom(0x01); } void display_a() { unsigned char i; display[3]=data_a/1000; display[2]=(data_a%1000)/100; display[1]=(data_a%100)/10; display[0]=data_a%10; for(i=0;i<=3;i++) { LCDWriteCom(0x80+i); LCDWriteData('0'+display[3-i]); } } void keyscan() { unsigned char a,keynum; KEY=0x0f; if(KEY!=0x0f) { delay1ms(1); //延时进行消抖 if(KEY!=0x0f) { KEY=0x0f; switch(KEY) { case 0x0e:keynum=3;break; case 0x0d:keynum=2;break; case 0x0b:keynum=1;break; case 0x07:keynum=0;break; } KEY=0xf0; switch(KEY) { case 0xe0:keynum=keynum+12;break; case 0xd0:keynum=keynum+8;break; case 0xb0:keynum=keynum+4;break; case 0x70:keynum=keynum;break; } while((a<50)&&(KEY!=0xf0)) //检测按键松手检测 { delay1ms(1); a++; } } } } unsigned char numpro(unsigned char a) { switch(a) { case 0:return 7;break; case 1:return 8;break; case 2:return 9;break; case 3:return 0x0d;break; //按键/ case 4:return 4;break; case 5:return 5;break; case 6:return 6;break; case 7:return 0x0c;break; //按键* case 8:return 1;break; case 9:return 2;break; case 10:return 3;break; case 11:return 0x0b;break; //按键- case 12:return 0;break; case 13:return 0x0f;break; //按键CE case 14:return 0x0a;break; //按键+ case 15:return 0x0e;break; //按键= default:return 0xff; } } void main() { unsigned char b=0xff; IniLCD(); data_a=0; display_a(); while(1) { keyscan(); b=numpro(keynum); if(b!=0xff) { if(b<10) { data_a=b+data_a*10; display_a(); } } } } |
|
相关推荐
3个回答
|
|
分太少了吗?第一次提问不太明白应该多少分,求大神解答一下吧
|
|
|
|
找到原因了,谢谢,因为变量溢出了
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
111 浏览 0 评论
【xG24 Matter开发套件试用体验】10-Bluetooth示例1
176 浏览 0 评论
474 浏览 0 评论
【xG24 Matter开发套件试用体验】power specification电源规格参数配置
438 浏览 0 评论
403 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
10804 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-21 21:21 , Processed in 0.847687 second(s), Total 90, Slave 68 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191