#include<reg52.h>/0:0x3f 1:0x06 2:0x5b 3:0x4f 4:0x66 5:0x6d 6:0x7d 7:0x07 8:0x7f 9:0x6fA:0x77 B:0x7c C:0x39 D:0x5e E:0x79 F:0x71/void delay (unsigned int z){ int x,y; for(x=z;x>0;x–) for(y=114;y>0;y–);}sbit we=P2^7; sbit du=P2^6;int keyvalue=0; const int display[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};int scan(){ P3=0xf0; if(P3 !=0xf0) { delay(20); if(P3 != 0xf0) { switch(P3) { case 0xe0: keyvalue=0; break; case 0xd0: keyvalue=1; break; case 0xb0: keyvalue=2; break; case 0x70: keyvalue=3; break; } P3=0X0f; switch(P3) { case 0x0e: keyvalue=keyvalue; break; case 0x0d: keyvalue=keyvalue+4; break; case 0x0b: keyvalue=keyvalue+8; break; case 0x07: keyvalue=keyvalue+12; break; } } }}void main(){ we=1; P0=0xfe;
we=0; while(1) { scan(); du=1; P0=display[keyvalue]; du=0; } }
实现效果:矩阵键盘的S5-S20对应0-f这16个数字
矩阵键盘
最新推荐文章于 2024-04-05 15:14:34 发布