I am starting to learn C and I am stuck on multiple expressions in an if and if-else statement. I want a red led to be on and green led off when neither of 2 buttons are pressed but if the failsafe button is pressed then red is off and green is on. I have coded what I thought would work but the red light remains when I press it.
Can anyone see what I am missing?
I am using MPLAB, PICKIT 2 and pic16f690
Can anyone see what I am missing?
Rich (BB code):
#include <pic16f690.h>
#include <htc.h>
//Port initialize
#define Button_Input_Init TRISBbits.TRISB7
#define Fan_Red_Light_Output_Init TRISBbits.TRISB6
#define Fan_Green_Light_Output_Init TRISBbits.TRISB5
#define Failsafe_Input_Init TRISCbits.TRISC2
// Port bit names
#define Button_State PORTBbits.RB7
#define Red_Light_State PORTBbits.RB6
#define Green_Light_State PORTBbits.RB5
#define Failsafe_State PORTCbits.RC2
void main(void)
{
// Initiate's I/O port bits
Button_Input_Init = 1;
Fan_Red_Light_Output_Init = 0;
Fan_Green_Light_Output_Init = 0;
Failsafe_Input_Init = 1;
if(Button_State == 0 && Failsafe_State == 0)
{
Red_Light_State = 1;
Green_Light_State = 0;
}
else if(Button_State == 0 && Failsafe_State == 1)
{
Red_Light_State = 0;
Green_Light_State = 1;
}
while(1);
}
Last edited: