用52单片机的4x4矩阵键盘的前八个键分别控制8个LED灯

2020-08-22 体育 247阅读
#include "reg51.h"
#define uchar unsigned charconst tab[]={0xee,0xde,0xbe,0x7e,0xed,0xdd,0xbd,0x7d};
const uchar led[]={0x01,0x01,0x04,0x08,0x10,0x20,0x40,0x80};
void delay()
{
uchar i;
for(i=0;i<10;i++){;}
}
void keyscan()
{
uchar a,b,c,i;
P3=0x0f;
a=P3;
delay();
P3=0xf0;
b=P3;
delay();
c=a+b; for(i=0;i<8;i++)
if(c==tab[i]) P2=led[i];
if(c==0xeb) P2=0xff;
}
void main()
{ P2=0x00; while(1)
{
keyscan();
}
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com