单片机作业。通过矩阵键盘输入,在七段数码管上显示按键编码

发布时间:2019-08-09 15:17:41

单片机作业。通过矩阵键盘输入,在七段数码管上显示按键编码

推荐回答

#include<reg52.h>#define uchar unsigned charuchar i;uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};void main(){while(1){P2 = 0x00;P1 = 0XF0;i = P1;i&=P1;P1 = 0X0F;i|=P1;switch(i){case 0xee:P0 = table[0];break;case 0xde:P0 = table[1];break;case 0xbe:P0 = table[2];break;case 0x7e:P0 = table[3];break;case 0xed:P0 = table[4];break;case 0xdd:P0 = table[5];break;case 0xbd:P0 = table[6];break;case 0x7d:P0 = table[7];break;case 0xeb:P0 = table[8];break;case 0xdb:P0 = table[9];break;case 0xbb:P0 = table[10];break;case 0x7b:P0 = table[11];break;case 0xe7:P0 = table[12];break;case 0xd7:P0 = table[13];break;case 0xb7:P0 = table[14];break;case 0x77:P0 = table[15];break;}} }
以上问题属网友观点,不代表本站立场,仅供参考!