求救高手帮忙,4*4键盘,4位数码管实现任意四位数的显示。以下是我的程序,只能实现单个数字的移位显示,希望能有高手帮忙修改,在此谢过!
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar Pre_KeyNO = 16,KeyNO = 16;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code wema[]={0xf1,0xf2,0xf4,0xf8};
uchar code DSY_CODE[]=
{
0xC0, // 0
0xF9, // 1
0xA4, // 2
0xB0, // 3
0x99, // 4
0x92, // 5
0x82, // 6
0xF8, // 7
0x80, // 8
0x90, // 9
0x88, // A
0x83, // B
0xC6, // C
0xA1, // D
0x86, // E
0x8E // F
};
void delay(uint x)
{
uchar i;
while(x--)
for(i=0;i<110;i++);
}
void Keys_Scan()
{ uchar Tmp;
P1 = 0x0f;
Tmp = P1 ^ 0x0f;
switch(Tmp)
{
case 1: KeyNO = 0; break;
case 2: KeyNO = 1; break;
case 4: KeyNO = 2; break;
case 8: KeyNO = 3; break;
default: KeyNO = 16;
}
P1 = 0xf0;
Tmp = P1 >> 4 ^ 0x0f;
switch(Tmp)
{
case 1: KeyNO += 0; break;
case 2: KeyNO += 4; break;
case 4: KeyNO += 8; break;
case 8: KeyNO += 12;
}
}
void main()
{ int m;
while(1)
{ P0 = 0x00;
while(1)
{
P1 = 0xf0;
if(P1 != 0xf0)
Keys_Scan();
{ if(Pre_KeyNO != KeyNO)
{
if(m==4)
m=0;
P2=wema[m++];
P0=DSY_CODE[KeyNO];
delay(200);
Pre_KeyNO = KeyNO;
}
delay(100);
}
}
}
}
一周热门 更多>