traxex
Newbie level 4
- Joined
- Jul 8, 2011
- Messages
- 7
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,326
Hi. I have an issue about a program for my project. I am taking two inputs from RD0 and RD1. When RD0 is 1, the output at PORTB should be 1. When RD0 goes to 0, controller should check for RD1. When RD1 is 0 while RD0 is also 0, the output at PORTB should be 0. When RD1 goes to 1 while RD0 is 0, the output at PORTB should be 1. The program executes nicely at the first, but i cannot go out of the second while loop. When RD0 is 0 and RD1 is 1, the output is 1, and RD0 goes to 1 always when, so the program should look at the first loop, but it doesn't. I want to code it so that it always looks RD0 and looks at RD1 only when RD0 is 0, i.e. I want to enable RD1 only when RD0 is 0, like the priorities of them are different(RD0 is higher, RD1 is lower). How should i code it?
Code:
while(1)
{
while(RD0==1)
{
PORTB = 0XFF;
}
while(RD0==0)
{
if(RD1==1)
{
PORTB = 0XFF;
}
if(RD1==0)
{
PORTB = 0X00;
}
}
}