单片机如何实现99999倒计时?这个程序有问题,#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define duan P1
sbit wei1 = P0^5;
sbit wei2 = P0^4;
sbit wei3 = P0^3;
sbit wei4 = P0^2;
sbit wei5 = P0^1;
sbit wei6 = P0^0;
uchar shu, z, ge, shi, bai, qian, wan, sw;
uchar code table[]={0xc0,0xF9,0xA4,0xb0,0x99,0x92,0x82,0xF8,0x80,0x90};
void timer1()
{
shu = 999;
TMOD = 0x01;
TH1 = (65536 – 50000)/256;
TL1 = (65536 – 50000)%256;
ET1 = 1;
TR1 = 1;
EA = 1;
}
void delay(int t)
{
int i,j;
for(j=0;j<t;j++)
{
for(i=0;i<122;i++); //空跑122次为1ms
}
}
void display (uchar shu)
{
ge = shu%10;
shi = shu/10%10;
bai = shu/100%10;
qian = shu/1000%10;
wan = shu/10000%10;
sw = shu/100000/10;
duan = table[ge]; //数码管显示秒数个位,即P0^3;
wei1 = 0;
delay(1);
wei1 = 1;
duan = table[shi]; //数码管显示秒数个位,即P0^3;
wei2 = 0;
delay(1);
wei2 = 1;
duan = table[bai]; //数码管显示秒数个位,即P0^3;
wei3 = 0;
delay(1);
wei3 = 1;
}
void main ()
{
timer1();
while(1)
{
display(shu);
}
}
void T_timer1(void) interrupt 3
{
TH1 = (65536 – 50000)/256;
TL1 = (65536 – 50000)%256;
z++;
if(z == 10)
{
shu–; //999999ge %10
if(shu == 0)
{
TR1 = 0;
}
}
}