一个良好的架构很重要,受益终身……
#include<reg52.h>
//定义Timer0重载值常数:
#define Timer0Reload_H (ms_to_timer(10)>>8) //定时器溢出周期设为10ms
#define Timer0Reload_L ms_to_timer(10)
volatile unsigned char cnt_10ms=0;//定时器中断里累加,主程序里读取
unsigned char i ;
unsigned char led;
unsigned char temp;
#include<intrins.h>
void main(void)
{
temp=0xfe;
P1=temp;
TH0=Timer0Reload_H;//(65535-50000)/256;
TL0=Timer0Reload_L;//(65535-50000)%256;
ET0=1;
EA=1;
TR0=1;
while(1)
{
if(cnt_10ms>=50)//500ms
{
cnt_10ms = 0;
temp=_crol_(temp,1);
P1=temp;//刷新到输出
}
}
}
void insteat() interrupt 1
{
// i++;
TH0=Timer0Reload_H;//(65535-50000)/256;
TL0=Timer0Reload_L;//(65535-50000)%256;
// if(i==10)
// {
// i=0;
// temp=_crol_(temp,1);
// }
cnt_10ms++;//定时器中断里只做最简单、最短的事
}