定时器中断函数小trick
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar temp, aa, num;
sbit duan = P2^6;
sbit wei = P2^7;
uchar code digit[]={
0x3f, 0x06, 0x5b, 0x4f,
0x66, 0x6d, 0x7d, 0x07,
0x7f, 0x6f, 0x77, 0x7c,
0x39, 0x5e, 0x79, 0x71};
void delay(uint z);
void main()
{
num = aa = 0;
TMOD = 0x01;
TH0 = (65536 - 50000) / 256;
TL0 = (65536 - 50000) % 256;
EA = ET0 = TR0 = 1;
temp = 0xfe;
P1 = temp;
duan = 1;
P0 = digit[0];
duan = 0;
wei = 1;
P0 = 0xc0;
wei = 0;
while(1)
{
delay(1000);
temp = _crol_(temp, 1);
P1 = temp;
/* if(aa==40) Trick : 必须放在中断函数中,不然只在此点监测aa,线程不同步
{
aa=0;
num++;
if(num==16)
num=0;
dula=1;
P0=table[num];
dula=0;
} */
}
}
void delay(uint z)
{
uint x, y;
for(x = z; x; --x)
for(y = 110; y; --y);
}
void timer0() interrupt 1
{
TH0 = (65536 - 50000) / 256;
TL0 = (65536 - 50000) % 256;
if(++aa == 40)
{
aa = 0;
if(++num == 16) num = 0;
dula = 1;
P0 = table[num];
dula = 0;
}
}
补充:综合编程 , 其他综合 ,