#include<reg52.h>
#define uint unsigned int
unsigned char code SMG[18]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,
0x82,0xf8,0x80,0x90,0x88,0x80,
0xc6,0xc0,0x86,0x8e,0xbf,0x7f
};
sbit S7=P3^0;
sbit S6=P3^1;
sbit S5=P3^2;
sbit S4=P3^3;
void delay(uint time)
{
uint i,j;
for(i=time;i>0;i--)
for(j=114;j>0;j--);
}
void SelectHC573(unsigned char n)
{
switch(n)
{
case 4:
P2=(P2 & 0x1f) | 0x80;
break;
case 5:
P2=(P2 & 0x1f) | 0xa0;
break;
case 6:
P2=(P2 & 0x1f) | 0xc0;
break;
case 7:
P2=(P2 & 0x1f) | 0xe0;
break;
}
}
void Show_SMG_Bit(unsigned char dat,unsigned char pos)
{
SelectHC573(6);
P0=0x01<<pos;
SelectHC573(7);
P0=dat;
}
void ScanKeys_Alone()
{
if(S7==0)
{
delay(10);
if(S7==0)
{
while(S7==0);
Show_SMG_Bit(SMG[1],0);
}
}
if(S6==0)
{
delay(10);
if(S6==0)
{
while(S6==0);
Show_SMG_Bit(SMG[2],0);
}
}
if(S5==0)
{
delay(10);
if(S5==0)
{
while(S5==0);
Show_SMG_Bit(SMG[3],0);
}
}
if(S4==0)
{
delay(10);
if(S4==0)
{
while(S4==0);
Show_SMG_Bit(SMG[4],0);
}
}
}
void Init()
{
SelectHC573(5);
P0=0x00;
SelectHC573(4);
P0=0xff;
}
void main()
{
Init();
while(1)
{
ScanKeys_Alone();
}
}
独立按键的基本操作
最新推荐文章于 2023-09-05 17:41:21 发布