我用定时器中断控制倒计时30秒。程序不报错,但是显示一直停在30..请问好友们,帮我看看问题出在哪里?
时间:10-02
整理:3721RD
点击:
意味着我的定时器中断,的变量 i 没有发生变化,为什么呢?
#include<reg52.h>
#define uchar unsigned char
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
#define uint unsigned int
int i,count,ge,shi;
void init();
void display();
void delay(uchar z)
{
uint x,y;
for(x = z;x>0;x--)
for(y = 110;y>0;y--);
}
void main()
{
init();
while(1)
{
display();
}
}
void init( ) //初始化函数
{
TMOD = 0x01;
TH0 = (65536-18432)/256;
TL0 = (65536-18432)%256;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void display(uint ge,uint shi) //数码管显示30s倒计时
{
P1 =0xfe;
P0 = table[shi];
delay(5);
P0 = 0xff;
P1 = 0xfd;
P0 = table[ge];
delay(5);
P0 = 0xff;
}
void tinm_T0 () interrupt 1 //我的思路是用定时器产生一个变了一秒自减一的变量 i
{
TH0 = (65536-18432)/256; //20ms
TL0 = (65536-18432)%256;
count++;
if(count ==50)
{
count = 0;
i--;
ge = i%10;
shi = i/10;
if(i ==0) i = 30;
}
}
#include<reg52.h>
#define uchar unsigned char
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
#define uint unsigned int
int i,count,ge,shi;
void init();
void display();
void delay(uchar z)
{
uint x,y;
for(x = z;x>0;x--)
for(y = 110;y>0;y--);
}
void main()
{
init();
while(1)
{
display();
}
}
void init( ) //初始化函数
{
TMOD = 0x01;
TH0 = (65536-18432)/256;
TL0 = (65536-18432)%256;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void display(uint ge,uint shi) //数码管显示30s倒计时
{
P1 =0xfe;
P0 = table[shi];
delay(5);
P0 = 0xff;
P1 = 0xfd;
P0 = table[ge];
delay(5);
P0 = 0xff;
}
void tinm_T0 () interrupt 1 //我的思路是用定时器产生一个变了一秒自减一的变量 i
{
TH0 = (65536-18432)/256; //20ms
TL0 = (65536-18432)%256;
count++;
if(count ==50)
{
count = 0;
i--;
ge = i%10;
shi = i/10;
if(i ==0) i = 30;
}
}
Display 没有传参
谢谢 ,是这个原因,已经改过来了。实在感谢
你好,还有个问题,就是数码管只有各位显示,9到0.十位不显示 。请问是我自减算法出问题了么?我思路错了么
全局默认初始化为0,第一次自减成负的了
好厉害啊~!~!不懂~