本帖最后由 武进伟 于 2016-2-15 23:29 编辑
#include<reg52.h>
#define unchar unsigned char
#define unint unsigned int
int c,b,s,g;
sbit cs=P0^7;
sbit duan=P2^6;
sbit wei=P2^7;
sbit wr=P3^6;
sbit rd=P3^7;
sbit led=P2^5;
unchar code table[]=
{
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7b,0x07,
0x7f,0x6f
};
void delay(unint x)
{
unint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void display(unchar bai,unchar shi,unchar ge)
{
duan=1;
P0=table[bai];
duan=0;
P0=0xff;
wei=1;
P0=0x7e;
wei=0;
delay(1);
duan=1;
P0=table[shi];
duan=0;
P0=0xff;
wei=1;
P0=0x7d;
wei=0;
delay(1);
duan=1;
P0=table[ge];
duan=0;
P0=0xff;
wei=1;
P0=0x7b;
wei=0;
delay(1);
}
void main()
{
cs=0;
led=1;
while(1)
{
wr=1;
wr=0;
wr=1;
delay(100);
rd=1;
rd=0;
delay(2);
rd=1;
delay(2);
c=P1;
b=c/100;
s=c%100/10;
g=c%100%10;
display(b,s,g);
}
}
|