当K有数据后,就一直在刷新显示,P30和P31并没有改变P的内容,他们产生的a的显示瞬间被P覆盖了吧。
下载贤集网APP入驻自媒体
请问为什么从键盘矩阵按下的数 不能通过独立按键 进行加减 #include#include "Delay.h" #include "LCD1602.h" #include "MatrixKey.h" unsigned char k=0; //k=通过键盘矩阵得到的数 unsigned int p,count,a; //p=进位得到的数 count=加的次数 a=通过独立按键加减得到的数 void main() { LCD_Init(); LCD_ShowString(1,1,"Password:"); LCD_ShowNum(2,1,k,4); while(1) { k=MatrixKey(); if(k) { if(k<=10) { if(count<4) { p*=10; p+=k%10; count++; } LCD_ShowNum(2,1,p,4); //显示 } } if(P3_0==0) { a=k; a++; if(a>17) { a=1; } LCD_ShowNum(2,1,a,4); } if(P3_1==0) { a=k; a--; if(a<0) { a=16; } LCD_ShowNum(2,1,a,4); } } }