angel.angel
Member level 1
- Joined
- Jan 23, 2013
- Messages
- 36
- Helped
- 2
- Reputation
- 4
- Reaction score
- 2
- Trophy points
- 1,288
- Location
- India
- Activity points
- 1,533
hi
My all dear friends.
I m dealing with programing of MCU atmega8l-8pu in c/c++ language first time. So Ii m facing a problem in the programing related to the breaking the continous while loop. I cannot. Here i m using four different sensor input to MCU as shown in the program below:
Regarding this program written above. when one input value of while loop is true, it is giving the desired output. But during the working of the MCU at one while statement, if there is any change the input i.e. input of 2nd while statement the continous while loop is not breaking till the power suply is not off. If we off the Power suply, then it jumps the new statement.
to solve this problem I used the break statement. and the new programe written below:
Now at this situation I m confused. I donnot know what to do right now.
So any one can help me one this topic that How to break the infinite loop of while statement to jump into another while loop with the change in input of the sensor.
Thanks in advance/.
My all dear friends.
I m dealing with programing of MCU atmega8l-8pu in c/c++ language first time. So Ii m facing a problem in the programing related to the breaking the continous while loop. I cannot. Here i m using four different sensor input to MCU as shown in the program below:
Code:
#define F_CPU 1000000UL // 1 MHz
#include <inttypes.h>
#include <avr/io.h>
int main() // The main function
{
DDRD = 0b00000000;// Set all the pin of portD as input
DDRB = 0b11111111; // Set all the pin of portB as output
while(PIND==0b00001111)
{
PORTB = 0b00000101; // both motor rotate Clock Wise
}
while (PIND==0b00001101)
{
PORTB = 0b00000100; // left motor stop and right motor rotate CW
}
while(PIND==0b00001100)
{
PORTB = 0b00000110; // left motor CW and right motor counter clock wise (CCW)
}
while (PIND==0b00001011)
{
PORTB = 0b00000001; // left motor CW and right motor stop
}
while (PIND==0b00000011)
{
PORTB = 0b00001001; // left motor CW and right motor CCW
}
}
to solve this problem I used the break statement. and the new programe written below:
Code:
#define F_CPU 1000000UL // 1 MHz
#include <inttypes.h>
#include <avr/io.h>
int main() // The main function
{
DDRD = 0b00000000;// Set all the pin of portD as input
DDRB = 0b11111111; // Set all the pin of portB as output
while(PIND==0b00001111)
{
PORTB = 0b00000101; // both motor rotate Clock Wise
if(PIND != 0b00001111)
break;
PORTB = 0b00000101;
}
while (PIND==0b00001101)
{
PORTB = 0b00000100; // left motor stop and right motor rotate CW
if(PIND != 0b00001101)
break;
PORTB = 0b00000100;
}
while(PIND==0b00001100)
{
PORTB = 0b00000110; // left motor CW and right motor counter clock wise (CCW)
if(PIND != 0b00001100)
break;
PORTB = 0b00000110;
}
while (PIND==0b00001011)
{
PORTB = 0b00000001; // left motor CW and right motor stop
if(PIND != 0b00001011)
break;
PORTB = 0b00000001;
}
while (PIND==0b00000011)
{
PORTB = 0b00001001; // left motor CW and right motor CCW
if(PIND != 0b00000011)
break;
PORTB = 0b00001001;
}
}
So any one can help me one this topic that How to break the infinite loop of while statement to jump into another while loop with the change in input of the sensor.
Thanks in advance/.
Last edited by a moderator: