# include <reg52.h> //输入一个6字符显示在数码管上
# define uint unsigned int
# define uchar unsigned char
sbit dula = P2^6;
sbit wela = P2^7;
uchar a, i, k;
uchar shuwei[6];
char code temp_dula[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x67,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
char code weixuan[]={
0xdf,0xef,0xf7,0xfb,
0xfd,0xfe
};
char code temp_shu[]={
'0','1','2','3',
'4','5','6','7',
'8','9'
};
uchar code zifu[] = {
0x30, 0x31, 0x32, 0x33,
0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62,
0x63, 0x64, 0x65, 0x66,
};
void init();
void delay(uint k);
void display();
void shiliu_shuma();
void main()
{
init();
while(1)
{
display();
}
}
void init()
{
TMOD = 0x20;
TH1 = 0xfd;
TL1 = 0xfd;
TR1 = 1;
EA = 1;
ES = 1;
SM0 = 0;
SM1 = 1;
REN = 1;
i = 0;
k = 1;
}
void ser () interrupt 4
{
shiliu_shuma();
}
void delay(uint k) //软件延时
{
uint x, y;
for(x=k;x>0;x--)
for(y=10000;y>0;y--);
}
void shiliu_shuma()
{
uchar j, x, y, z;
if(RI == 1)
{
RI = 0;
a = SBUF;
if(a == 0x6e) //当a==n时,只显示当前输入字符,并且重新排序
{
for(x=0,y=i-1;x<y;x++,y--)
{
z = shuwei[x];
shuwei[x] = shuwei[y];
shuwei[y] = z;
}
k = i;
i = 0;
}
else
{
for(j=0;j<16;j++)
{
if(zifu[j] == a)
shuwei[i] = j;
}
j = 0;
k++;
i++;
}
}
}
void display() //动态显示窗口
{
uchar u;
for(u=0;u<k;u++)
{
delay(1);
{
wela = 1;
P0 = weixuan[u];
wela = 0;
dula = 1;
P0 = temp_dula[shuwei[u]];
dula = 0;
}
}
}
|