#include<reg52.h>
typedef unsigned char uchar;
typedef unsigned int uint;
sbit a=P1^0;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
void delay(uint x);
uchar temp,key,disnum;
void main()
{
a=0; //接通第一个数码管
disnum=16; //在没按按键时,数码管什么都不显示
while(1) //大循环
{
P3=0xf0; //P3=11110000 列全为1,行全为0
temp=P3; //在没有按键按下时temp=11110000,当有按键被按下时,temp!=11110000
temp=temp&0xf0; //将temp的低四位全为0
if(temp!=0xf0) //检测是否有按键被按下
{
delay(10); //延时,消抖
if(temp!=0xf0) //检测是否有按键被按下
{
temp=P3; //将P3口实时的值赋给temp,此时的temp高四位有一位为0,低四位全为0
temp=temp|0x0f; //将temp低四位全置1
P3=temp; //将temp值赋给P3口
key=P3; //用key读取P3口的值
switch(key) //拿key的值与case后面的值进行对比
{
cas
51单片机矩阵键盘程序
最新推荐文章于 2024-04-18 12:30:25 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)