#include "reg52.h"
#define GPIO_KEY P1
#define GPIO_DIG P0
typedef unsigned char u8;
typedef unsigned int u16;
sbit LSA = P2^2;
sbit LSB = P2^3;
sbit LSC = P2^4;
u8 code smgduan[]=
{
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71
};
u8 keyValue=0;
void delayus(u16 i)
{
while(i--);
}
void keyDown()
{
u8 a =0;
GPIO_KEY = 0x0f;
if (GPIO_KEY != 0x0f)
{
delayus(1000);
if(GPIO_KEY != 0X0F)
{
GPIO_KEY = 0x0f;
switch(GPIO_KEY)
{
case(0x07): keyValue=0;break;
case(0x0b): keyValue=1;break;
case(0x0d): keyValue=2;break;
case(0x0e): keyValue=3;break;
}
GPIO_KEY=0xf0;
switch(GPIO_KEY)
{
case(0x70): keyValue=keyValue;break;
case(0xb0): keyValue=keyValue+4;break;
case(0xd0): keyValue=keyValue+8;break;
case(0xe0): keyValue=keyValue+12;break;
}
while(a<50 && GPIO_KEY!=0xf0)
{
delayus(1000);
}
}
}
}
void main()
{
LSA=0;
LSB=0;
LSC=0;
while(1)
{
keyDown();
GPIO_DIG=smgduan[keyValue];
}
}
版权声明:本文为CSDN博主「acktomas」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/acktomas/article/details/104165912
暂无评论