一个定时中断产生N个软件定时器
#include <reg52.h>//三个LED灯并行处理,分别闪烁0.5、1、2S
#define BLINK_TIME1 25//定时时间0.5S,每20MS中断一次
#define BLINK_TIME2 50//1S
#define BLINK_TIME3 100//2S
sbit led1=P1^0;
sbit led2=P1^2;
sbit led3=P1^4;
volatile unsigned int count1=0,count2=0,count3=0;//volatile是一个前缀的修饰关键词,用来保护主函数和中断函数公用的全局变量
volatile unsigned char timeflag1=0,timeflag2=0,timeflag3=0;/*互斥量,保护数据的安全。因为主函数和中断函数本质上是
两个独立的进程并行运行,如果主函数在对count1变量(两个字节)进行写操作时需要2个指令,在执行了第一个指令后还没有来得及
执行第2条指令时来了一个中断对count1进行写操作,这样就带来了隐患*/
unsigned char Gu8Step1=0,Gu8Step2=0