利用51单片机设计一个秒表
刚做的一个现实最小是0.1秒的,给你参考吧,0.01的也做过不过已经删除了,因为最后一位现实出来几乎都看不清楚,变化太快了。
#include<reg51.h>
#define uchar unsigned char
uchar ledtab[]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6,0xfe,0x3e,0x9c,0x7a,0x9e,0x8e,0x00};
uchar keyval,dat,scanled,clk;
uchar disdat[4];
void ext0(void) interrupt 0
{
keyval++;
keyval%=3;
}
void t0isr(void) interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
clk++;
if(clk>1)
{
clk=0;
disdat[3]++;
if(disdat[3]>9)
{
disdat[3]=0;
disdat[2]++;
if(disdat[2]>9)
{
disdat[2]=0;
disdat[1]++;
if(disdat[1]>9)
{
disdat[1]=0;
disdat[0]++;
if(disdat[0]>9)disdat[0]=0;
}
}
}
}
}
void t1isr(void) interrupt 3
{
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
P2=0x01<<scanled;
dat=ledtab[disdat[scanled]];
if((scanled==0)||(scanled==2))dat|=0x01;
P0=~dat;
scanled++;
scanled%=4;
}
main()
{
uchar i;
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
keyval=2;
scanled=0;
clk=0;
IT0=1;
EX0=1;
ET0=1;
TR1=1;
ET1=1;
EA=1;
while(1)
{
switch(keyval)
{
case 0:TR0=1;break;
case 1:TR0=0;break;
case 2:for(i=0;i<4;i++)disdat[i]=0;break;
default:break;
}
}
}