1. 实验任务 <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
(1. 开机时,显示12:00:00的时间开始计时;
(2. P0.0/AD0控制“秒”的调整,每按一次加1秒;
(3. P0.1/AD1控制“分”的调整,每按一次加1分;
(4. P0.2/AD2控制“时”的调整,每按一次加1个小时;
#include<reg51.h>
unsigned char code table1[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f};
unsigned char table2[]={0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f};
sbit a="P1"^0;
sbit b="P1"^1;
sbit c="P1"^2;
unsigned char t,z,k,n,m;
unsigned char s,h;
unsigned char second,minute,shi;
unsigned int i,d=500;
void delay(z)
{
int i,j;
for(i=0;i<z;i++)
for(j=0;j<100;j++);
}
void uint()
{
shi="12";
TMOD="0x01";
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA="1";
ET0=1;
TR0=1;
}
void display()
{
P2=table2[4];
P0=table1;
delay(10);
P2=table2[5];
P0=table1[k];
delay(10);
P2=table2[2];
P0=table1[m];
delay(10);
P2=table2[3];
P0=table1[n];
delay(10);
P2=table2[0];
P0=table1;
delay(10);
P2=table2[1];
P0=table1[h];
delay(10);
}
void main()
{
uint();
while(1)
{
if(a==0)
{
delay(100);
if(a==0)
{
second++;
i="second/10";
k="second"%10;
TR0=0;
P2=table2[4];
P0=table1;
delay(100);
P2=table2[5];
P0=table1[k];
delay(10);
}
while(a==0);
TR0=1;
if(second==60)
{
second="0";
minute++;
if(minute==60)
minute="0";
}
}
if(b==0)
{
delay(100);
if(b==0)
{
minute++;
m="minute/10";
n="minute"%10;
TR0=0;
P2=table2[2];
P0=table1[m];
delay(100);
P2=table2[3];
P0=table1[n];
delay(10);
}
while(b==0);
TR0=1;
if(minute==60)
{
minute="0";
m="minute/10";
n="minute"%10;
shi++;
if(shi==24)
shi="0";
}
}
if(c==0)
{
delay(100);
if(c==0)
{
shi++;
s="shi/10";
h="shi"%10;
TR0=0;
P2=table2[0];
P0=table1;
delay(100);
P2=table2[1];
P0=table1[h];
delay(10);
}
while(c==0);
TR0=1;
if(shi==24)
{
shi="0";
s="shi/10";
h="shi"%10;
}
}
display();
}
}
void time0(void) interrupt 1 using 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t++;
if(t==20)
{
t="0";
second++;
if(second==60)
{
second="0";
minute++;
if(minute==60)
{
shi++;
if(shi==24)
shi="0";
}
}
}
i="second/10";
k="second"%10;
m="minute/10";
n="minute"%10;
s="shi/10";
h="shi"%10;
}
用户1457811 2009-3-26 20:15