void main(void)
{
TMR0IF=0;//清除TMR0中断标志位
TMR0=255;//设置中断初始值255
unsigned int k = 1;
unsigned int TIMER0 = 0,TIMER1 = 0,TIMER2 = 0;
unsigned char Flag_1 = 1;
unsigned char Flag_2 = 1;
unsigned char Flag_3 = 1;
Pin_Init();
Answ_Out = 0;
Light1 = 0;
Light2 = 0;
Light3 = 0;
Light4 = 0;
while(1)
{
if( (TMR0IF == 1) && (Flag_1 ==1) ) //开启定时器溢出中断
{
TIMER0 ++; //计数器+1
TMR0IF = 0; //定时器溢出标志位清零
TMR0 = 255;
}
if( TIMER0 == k ) //如果计数器的值等于设定的值
{
Light4 = 1; //灯灭
}
if( TIMER0 == 100 ) //计数器加到90
{
Light4 = 0; //灯亮
TIMER0 = 0;
k++; //设定值初始化
}
if( k == 99 )
{
Light4 = 0;
k =1;
Flag_3 = 1;
Flag_1 = 0;
}
if( (TMR0IF == 1) && (Flag_2 ==1) ) //开启定时器溢出中断
{
TIMER1 ++; //计数器+1
TMR0IF = 0; //定时器溢出标志位清零
TMR0 = 255;
}
if( TIMER1 == 40040)
{
Light4 = 1;
TIMER1 = 0;
Flag_1 = 1;
Flag_2 = 0;
}
if( (TMR0IF == 1) && (Flag_3 ==1) ) //开启定时器溢出中断
{
TIMER2 ++; //计数器+1
TMR0IF = 0; //定时器溢出标志位清零
TMR0 = 255;
}
if( TIMER2 == k ) //如果计数器的值等于设定的值
{
Light4 = 0; //灯亮
}
if( TIMER2 == 100 ) //计数器加到90
{
Light4 = 1; //灯灭
TIMER2 = 0;
k++; //设定值初始化
}
if( k == 99 )
{
Light4 = 0;
k =1;
Flag_2 = 1;
Flag_3 = 0;
}
}
}