用天翔老师的板子写了一个定时计数程序,使用导线接触T0引脚计数,每隔一秒钟刷新一次从0开始,程序如下:
#include
#define uchar unsigned char
#define uint unsigned int
***it dula=P2^6;
***it wela=P2^7;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar num1,flag1s;
uint val;
void delay(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void init()
{
TMOD=0x15;
TH0=0;
TL0=0;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TR0=1;
EA=1;
ET1=1;
TR1=1;
}
void display(uchar bai,uchar shi,uchar ge)
{
dula=1;
P0=table[bai];
dula=0;
wela=1;
P0=0xfe;
wela=0;
delay(5);
dula=1;
P0=table[shi];
dula=0;
wela=1;
P0=0xfd;
wela=0;
delay(5);
dula=1;
P0=table[ge];
dula=0;
wela=1;
P0=0xfb;
wela=0;
delay(5);
}
uint read()
{
uchar t1,th1,th2;
uint val;
while(1)
{
th1=TH0;
t1=TL0;
th2=TH0;
if(th1==th2)
break;
}
val=th1*256+t1;
return val;
}
void main()
{
uchar a,b,c;
uint num;
init();
while(1)
{
num=read();
if(flag1s==1)
{
TH0=0;
TL0=0;
flag1s=0;
num=0;
}
a=num/100;
b=num%100/10;
c=num%10;
display(a,b,c);
}
}
void
time() interrupt 1
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
num1++;
if(num1==20)
{
num1=0;
flag1s=1;
}
}
其中主函数中的大循环:
while(1)
{
num=read();
if(flag1s==1)
{
TH0=0;
TL0=0;
flag1s=0;
num=0;
}
a=num/100;
b=num%100/10;
c=num%10;
display(a,b,c);
}
请问为什么当我在此大循环中加入
num2=num;
这句时,每秒刷新一次从零开始就失效了呢?(num2已声明)