单片机倒计时程序
#include <reg52.h>
typedef unsigned char u8;
typedef unsigned int u16;
sbit wei=P3^0;
void delay(u16 i)
{
while(i--);
}
u16 icount,count;
u8 code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,
0x88,0x83,0xc6,0xa1,0x86,0x8e};
void main ()
{
icount=0;
count=9876;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
P1=0x00;
while (1)
{
wei=1;
P1=0x08;
wei=0;
P1=table[count%10];
delay(1000);
wei=1;
P1=0x04;
wei=0;
P1=table[count/10%10];
delay(1000);
wei=1;
P1=0x02;
wei=0;
P1=table[count/100%10];
delay(1000);
wei=1;
P1=0x01;
wei=0;
P1=table[count/1000];
delay(1000);
}
}
void inter0()interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
icount++;
if(icount==10)
{
count--;
if(count==0)
{count=9999;}
}
} |