I am trying to work around a circuit and my requirement is as follows: - There are two inputs and two outputs. Each input controls an individual led. I am writing a code for this requirement using a Nuvoton MS51 based controller (Which itself is 8051 based controller). The software used for the same is Keil. Following is the code I have written-
#include "MS51.h"
void main (void)
{
P01_INPUT_MODE;
P03_INPUT_MODE;
P10_PUSHPULL_MODE;
P00_PUSHPULL_MODE;
while (1)
{
if (!(P0 & SET_BIT3))
{
while( !(P0 & SET_BIT3));
P0 ^= 0x01;
}
if (!(P0 & SET_BIT1))
{
while (!(P0 & SET_BIT1));
P1 ^= 0x01;
}
}
}
The problem I am facing is that both the switches are not working simultaneously but only in a sequence. The first switch will work, then the second (I am not able to use the first switch again). Is there anything wrong that I am doing in the code?
Solution: I have found the mistake I was doing. The mistake was of pull-up/pull-down of the switch. My switch is pulled down and the code that I had written corresponded to the case of a pull-up. Hence my code was being stuck in the while loop again and again, hence stopping the flow of code to the next line.