#include<reg51.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit duan=P2^0;
sbit wei=P2^1;
sbit wr=P3^0;
sbit rd=P3^1;
sbit cs=P3^2;
sbit intr=P3^3;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay1ms(uint t)
{
uint i,j;
for(i=0;i<t;i++)
for(j=0;j<110;j++);
}
void display(uchar bai,uchar shi,uchar ge)
{
wei=1;
P0=0x7e;
wei=0;
P0=0xff;
duan=1;
P0=table[bai];
duan=0;
delay1ms(5);
wei=1;
P0=0x7d;
wei=0;
P0=0xff;
duan=1;
P0=table[shi];
duan=0;
delay1ms(5);
wei=1;
P0=0x7b;
wei=0;
P0=0xff;
duan=1;
P0=table[ge];
duan=0;
delay1ms(5);
}
void main()
{
uchar a,A1,A2,A3,adval;
cs=0;
wei=1;
P0=0x7f;
wei=0;
while(1)
{
wr=1;
_nop_();
wr=0;
_nop_();
wr=1;
while(intr);
for(a=10;a>0;a--)
{
display(A1,A2,A3);
}
P1=0xff;
rd=1;
_nop_();
rd=0;
_nop_();
adval=P1;
rd=1;
A1=adval/100;
A2=adval%100/10;
A3=adval%100%10;
display(A1,A2,A3);
}
}
|