I'm trying to write general non blocking code logic for three LED, Not for specific uC and compiler. #There are 3 LED, numbered 1, 2 and 3.
Description of problem
Here is my planning with pseudocode. I'm stuck with LED flashing function logic and I don't have any idea how do it
Description of problem
- Flash LED 1 once for 200 ms time period every 250 ms
- Flash LED 2 once for 400 ms time period every 500 ms
- Flash LED 3 once for 600 ms time period every 750 ms
Here is my planning with pseudocode. I'm stuck with LED flashing function logic and I don't have any idea how do it
C:
LED1
LED2
LED3
#define True 1
#define SET 1
#define RESET 0
#define OFF 0
#define CLEAR 0
void main ()
{ // main start from here
LED1 = OFF ;
LED2 = OFF ;
LED3 = OFF ;
unit8_t Time_Flag = CLEAR;
unit8_t LED1_Deadline_Time = CLEAR ;
unit8_t LED2_Deadline_Time = CLEAR ;
unit8_t LED3_Deadline_Time = CLEAR ;
while ( True )
{ // while Loop start from here
if (Time_Flag == SET)
{
if ( LED1_Deadline_Time == 200 ) // Always check deadline time for LED1 if match
{
LED1_Flashing();
LED1_Deadline_Time = RESET;
}
LED1_Deadline_Time++;
if ( LED2_Deadline_Time == 400 ) // Always check deadline time for LED2 if match
{
LED2_Flashing();
LED2_Deadline_Time = RESET;
}
LED2_Deadline_Time++;
if ( LED3_Deadline_Time == 700 ) // Always check deadline time for LED1 if match
{
LED3_Flashing();
LED3_Deadline_Time = RESET;
}
LED3_Deadline_Time++;
}
Time_Flag = CLEAR ;
} //while Loop End here
}// main End here
// interrupt every 10ms
void ISR_Timer_Interrupt ()
{
if ( T1IF = SET )
{
Time_Flag = SET;
T1IF = CLEAR;
}
}
Last edited: