编程实现60秒的倒计时器程序,到最后10秒的时候数码管开始闪烁递减知道为0!请教这个闪烁子程序怎么编呢?

#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar time,temp,shi,ge;
sbit duan=P2^2; //定义锁存使能端口 段锁存
sbit wei=P2^3; //定义锁存使能端口 位锁存
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};

void delay(uint z)
{
int x,y;
for(x=z;x>0;x--)
for(y=200;y>0;y--);
}

void init() //初始化子程序
{
duan=0;
wei=0;
time=0;
temp=20;
TMOD=0x01;//采用定时器T0,定时方式、方式1
TH0=(65536-50000)/256;//50毫秒;20次为1秒。
TL0=(65536-50000)%256;
EA=1; //开总中断
ET0=1; //T0溢出中断允许位。为1是打开,为0时禁止
TR0=1; //启动T0定时器
}

void display(uchar shi,uchar ge)
{

duan=1;
P0=table[shi];
duan=0;
P0=0xff;
wei=1;
P0=0xfe;
wei=0;
delay(1);

duan=1;
P0=table[ge];
duan=0;
P0=0xff;
wei=1;
P0=0xfd;
wei=0;
delay(1);

}

void display_shanshuo(uchar shi,uchar ge)//闪烁子程序
{
???????????????????
???????????????????
???????????????????
}

void main()
{
init();
while(1)
{
if(time==20)
{
time=0;
temp--;
if(temp==0)
temp=20;
shi=temp/10;
ge=temp%10;
}
if(temp>10)
display(shi,ge);
if(temp<11)
display_shanshuo(shi,ge);
}
}

void timer() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
time++;
}

请教各位高手,程序当中的闪烁子程序怎么编写呢?才能实现数码管正常递减并且是相隔1秒的时间在闪烁!

void display_shanshuo(uchar shi, uchar ge)//闪烁子程序
{
wei = 1; P0 = 0xff; wei = 0;//关闭显示
}

void main()
{
init();
while(1) {
if(time == 20) {
time = 0;
temp--;
if(temp == 0) temp = 20;
shi = temp / 10;
ge = temp % 10;
}
if(temp > 10) display(shi, ge); //正常显示.
else { //否则闪烁.
if (time / 10) display(shi, ge); //后半秒正常显示.
else display_shanshuo(shi, ge); //前半秒关闭显示.
}
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-06-28
你可以搞一个全局变量写在中断函数里面嘛,就像你那个time一样,计数小于等于20次就将数码管的位选送1,计数大于20小于等于40就将位选送0,满四十后马山清零,就像你的那个time一样。这样就是相隔一秒闪烁呀
第2个回答  2011-06-29
你可以搞一个全局变量写在中断函数里面嘛,就像你那个time一样,计数小于等于20次就将数码管的位选送1,计数大于20小于等于40就将位选送0,满四十后马山清零,就像你的那个time一样。这样就是相隔一秒闪烁呀
回答者: subo19920716 | 五级 | 2011-6-28 22:57
void display_shanshuo(uchar shi, uchar ge)//闪烁子程序
{
wei = 1; P0 = 0xff; wei = 0;//关闭显示
}

void main()
{
init();
while(1) {
if(time == 20) {
time = 0;
temp--;
if(temp == 0) temp = 20;
shi = temp / 10;
ge = temp % 10;
}
if(temp > 10) display(shi, ge); //正常显示.
else { //否则闪烁.
if (time / 10) display(shi, ge); //后半秒正常显示.
else display_shanshuo(shi, ge); //前半秒关闭显示.
}
}
}