I have a PIC32 starter kit and I am making a program such that when I apply input 1, MCU will send this data to my PC using UART and INPUT 1 ON will be displayed on terminal, same goes for input 2 & 3. These inputs are coming from opto couplers and these are basically 3.1v. So whenever I apply these inputs, MCU pin become high, data is send to PC using UART and INPUT 1 ON or INPUT 2 ON is displayed.
But the problem is let say, I have applied input 1 and terminal is displaying INPUT 1 ON and at the same time if I apply input 2, INPUT 1 ON goes off and INPUT 2 ON started displaying. I want that both INPUT 1 ON INPUT 2 ON should be displayed and if I apply input 3 at the same time INPUT 3 ON should also be displayed along with INPUT 1 ON INPUT 2 ON. I dont know how to make logic for this. Can anyone just help me with this. Thanks
CODE:
if(PORTAbits.RA6 == 0)
{
putsUART2(">>Input: 1 ONrn");
}
if(PORTAbits.RA6 == 1)
{
putsUART2(">>Input: 1 OFFrn");
}
if(PORTAbits.RA7 == 0)
{
putsUART2(">>Input: 2 ONrn");
}
if(PORTAbits.RA7 == 1)
{
putsUART2(">>Input: 2 OFFrn");
}
if(PORTGbits.RG13 == 0)
{
putsUART2(">>Input: 3 ONrn");
}
if(PORTGbits.RG13 == 1)
{
putsUART2(">>Input: 3 OFFrn");
}
EDIT
Right now what I am trying to do is if(PORTAbits.RA6 == 0) the it should display Input: 1 ON and if if(PORTAbits.RA6 == 1) then it should display Input: 1 OFF and same for other inputs. But what’s happening is when there is no input Input: 1 OFF Input: 2 OFF Input: 3 OFF is displayed but when if(PORTAbits.RA6 == 0) comes it shows Input: 1 ON for just one time and then continuously displays Input: 1 OFF Input: 2 OFF Input: 3 OFF. I dont know why its behaving like this.