|
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code segdate[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar time;
uchar sec;
uchar scon;
uchar keycon;
delay()
{
uchar i,j;
for(i=0;i<4;i++)
for(j=0;j<250;j++);
}
main()
{
TMOD=0x01;
ET0=1;
EA=1;
EX0=1;
IT0=1;
sec=0;
scon=0;
keycon=0;
while(1)
{
P2=0xfe;
P0=segdate[sec%10];
delay();
P2=0xfd;
P0=segdate[sec/10];
delay();
}
}
void t0(void) interrupt 1 using 0
{
TH0=0x3c;
TL0=0xb0;
scon++;
if(scon==20)
{
scon=0;
sec++;
if(sec==31)
{sec=0;}
}
}
void int0(void) interrupt 0 using 1
{
keycon++;
switch(keycon)
{
case 1:TH0=0x3c;TL0=0xb0;TR0=1; break;
case 2:TR0=0; break;
case 3:keycon=0;sec=0; break;
}
}
|
-
-
秒表.rar
39.99 KB, 下载次数: 16, 下载积分: 黑币 -5
倒计时
|