alpha91
Full Member level 3
Hi all, I am trying to write a code for PIC so that it can carry out different function depends on setting mode.
Default mode: both LED blinking
Mode 1 : LED 1 is blinking
Mode 2 : LED 2 is blinking
But my code doesnt work as what i thought. I am using IF statement
my code is as below:
Can anyone tell me what did i do wrong?
Default mode: both LED blinking
Mode 1 : LED 1 is blinking
Mode 2 : LED 2 is blinking
But my code doesnt work as what i thought. I am using IF statement
my code is as below:
void main () {
unsigned char MODE1;
CMCON = 0x07;
TRISA = 0x11;
TRISB = 0x00;
MODE1 = 0x00;
while (1){
if (PORTA.F0 == 1) // if button 1 is press
{
delay_ms (50);
if ( PORTA.F0 == 1) // if button 1 is press
{
if (MODE1 == 0x02) // if current mode is 02
{
MODE1 = 0x00; // reset mode to 00
}
else {
MODE1 ++; // else mode is switch to next mode
}
}
}
if (MODE1 == 0x01) // if mode is 01
{
PORTB = 0x01; // LED 2 is blinking
delay_ms (500);
PORTB = 0x00;
delay_ms (500);
}
if (MODE1 == 0x02) // if mode is 02
{
PORTB = 0x02; //LED 1 is blinking
delay_ms (500);
PORTB = 0x00;
delay_ms (500);
}
else //else mode
{
PORTB = 0x03; // both LED is blinking
delay_ms (500);
PORTB = 0x00;
delay_ms (500);
}
}
}
Can anyone tell me what did i do wrong?