用proteus仿真实现时钟
时钟程序源码:#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit du = P2^6;
sbit we = P2^7;
uchar code wei_i[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80 };
uchar code table_d[] = {0X3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F,0X00,0X40};
uchar s,g,num,shi,fen,miao;
void delays(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void init()
{
P0 = 0;
du = 0;
we = 0;
}
void display(uchar wei,uchar duan)
{
P0=~wei_i[wei];
we=1;
we=0;
P0=table_d[duan];
du=1;
du=0;
delays(3);
P0=0xdb;
we=1;
we=0;
P0=0x40;
du=1;
du=0;
delays(3);
}
void T0_time() interrupt 1
{
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
num++;
if(num==20)
{
num = 0;
miao++;
if(miao>=60)
{
fen++;
miao=0;
}
if(fen>=60)
{
fen=0;
shi++;
}
if(shi>=24)
shi=0;
}
}
void main()
{
init();
TMOD = 0x01;
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
EA = 1;
ET0 = 1;
TR0 = 1;
while(1)
{
s = miao / 10;
g = miao % 10;
display(6,s);
display(7,g);
s = fen /10;
g = fen %10;
display(3,s);
display(4,g);
s = shi / 10;
g = shi % 10;
display(0,s);
display(1,g);
}
}
|