在P1口接的4*4键盘,P0口接一位8段共阴极数码管,P2.0接公共阴极,想在按下某个键后,数码管显示对应的数字.程序如下,(结果编译可以通过但在实验板上实验时不显示数字,请帮忙指出错误,谢谢!!!!!) #include<reg52.h> #define uint unsigned int #define uchar unsigned char uchar wordcode[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; void delay(uint delaytime) { uint i; for(;delaytime>0;delaytime--) { for(i=0;i<125;i++) {;;} } }
keyscan( ) { uint scancode,temp; while(1) { P1=0xf0; if((P1&0xf0)!=0xf0) { delay(10); if((P1&0xf0)!=0xf0) { scancode=0xfe; while((P1&0x10)!=0) { P1=scancode; if((P1&0xf0)!=0xf0) { temp=P1; return(temp); } else scancode=(scancode<<1)|0x01; } } } } }
uchar getkeyvalue( ) { uint i,k; k=keyscan(); switch (k) { case 0xee: i==0; break; case 0xde: i==1; break; case 0xbe: i==2; break; case 0x7e: i==3; break; case 0xed: i==4; break; case 0xdd: i==5; break; case 0xbd: i==6; break; case 0x7d: i==7; break; case 0xeb: i==8; break; case 0xdb: i==9; break; default: break; } return (i); } void main() { uchar j; P2=0xfe; j=getkeyvalue(); P0=wordcode[j]; } |