|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区
您需要 登录 才可以下载或查看,没有账号?立即注册
×
# include <reg52.h>
# include <intrins.h>
# define uchar unsigned char
# define uint unsigned int
sbit CLOCK=P3^6;
sbit START=P3^7;
sbit EOC=P3^4;
sbit OE=P3^5;
sbit ALE=P3^3;
sbit A=P3^2;
sbit B1=P3^1;
sbit C=P3^0;
long x,y,shu,ge,fen1,fen2,fen3,jia,j;
void delay(int z)
{
int a ,b;
for(a=z;a>0;a--)
for(b=110;b>0;b--);
}
uchar code table[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
uchar code table1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void display(uint ge,fen1,fen2,fen3)
{
if(jia%2!=0)
{
P0=0x40;
P2=0xfe;
delay(1);
P2=0xff;
P0=table1[ge];
P2=0xfd;
delay(1);
P2=0xff;
P0=table[fen1];
P2=0xfb;
delay(1);
P2=0xff;
P0=table1[fen2];
P2=0xf7;
delay(1);
P2=0xff;
// P0=table1[fen3];
// P2=0xf7;
// delay(5);
// P2=0xff;
}
if(jia%2==0)
{
P0=table1[ge];
P2=0xef;
delay(1);
P2=0xff;
P0=table[fen1];
P2=0xdf;
delay(1);
P2=0xff;
P0=table1[fen2];
P2=0xbf;
delay(1);
P2=0xff;
P0=table1[fen3];
P2=0x7f;
delay(1);
P2=0xff;
}
}
void main()
{
TMOD=0x11;
TH0=(65536-10)/256;
TL0=(65536-10)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
ET1=1;
TR1=1;
ALE=0;
START=0;
OE=0;
while(1)
{
ALE=1;
START=0;
_nop_();
START=1;
ALE=0;
START=0;
display(ge,fen1,fen2,fen3);
while(EOC==0);
P1=0xff;
OE=1;
x=P1;
shu=x*196;
ge=(shu*5)/100000;
fen1=(shu*5)/10000%10;
fen2=(shu*5)/1000%10;
fen3=(shu*5)/100%10;
}
}
void time() interrupt 1
{
TH0=(65536-10)/256;
TL0=(65536-10)%256;
CLOCK=~CLOCK;
}
void time2() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
j++;
if(j>59)
{
j=0;
jia++;
if(jia%2==0)
A=B1=C=0;
if(jia%2!=0)
{
B1=C=0;
A=1;
}
}
} |
|