I am not asking for enum statement. please look at following program. here I am trying to use enum , switch and if condition. I want make working program later I will test. how to use all in one program?
C:
#include<reg51.h> //header file
sbit LED1 = P2^0; //LED 1 conncted to port P2 pin 0
sbit LED2 = P2^1; //LED 2 conncted to port P2 pin 1
sbit LED3 = P2^2; //LED 3 conncted to port P2 pin 2
// prototype function
void DoSomething0(void);
void DoSomething1(void);
void DoSomething2(void);
typedef enum
{
task1 ,
task2,
task3
} my_task_t;
my_task_ t task;
int main(void)
{
switch (task)
{
case task1:
if <task> == task1
DoSomething0();
break;
case task2:
if <task> == task2
DoSomething1();
break;
case task3:
if <task> == task3
DoSomething2();
break;
}
I wrote something. Its not complete code I just trying to complete code. I have some issues like if condition and code for three LEDs and I am working on that issue what do you think about code?
C:
#include<reg51.h> //header file
#define LED1_ON 1
#define LED1_OFF 0
#define LED2_ON 1
#define LED2_OFF 0
#define LED3_ON 1
#define LED4_OFF 0
sbit LED1 = P2^0; //LED 1 conncted to port P2 pin 0
sbit LED2 = P2^1; //LED 2 conncted to port P2 pin 1
sbit LED3 = P2^2; //LED 3 conncted to port P2 pin 2
typedef enum
{
task1,
task2,
task3
};
// prototype function
void LED1_Blink(void);
void LED2_Blink(void);
void LED3_Blink(void);
int main(void)
{
unsigned int task=0;
while(1)
{
switch (task)
{
case task1:
LED1_Blink();
break;
case task2:
LED2_Blink();
break;
case task3:
LED3_Blink();
break;
}
}
}
void LED1_Blink ()
{
unsigned int i;
for (i = 0; i < 1000; i++);
}
void LED2_Blink()
{
unsigned int j;
for (j = 0; j < 1500; j++);
}
void LED3_Blink()
{
unsigned int k;
for (k = 0; k < 1200; k++);
}