![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 7
Rep Power: 0
![]() |
Switch statement
I have writtien the code below as part of an embedded application, but having trouble with my states. I can go forward betwwen states, ie from 0 to 1, but cant seem to go from 1 to 0.
switch (state){
case 0: {
clrLCD();
LCD_write("OMIT ZONES Y/N " , 1 ); // output text to LCD line 1
do {answer = get_keypad();}
while (answer == 'X');
if (answer == 'A')
{
delay_ms(750);
state = 1;
}
else return;
}
case 1: {
clrLCD();
LCD_write("ZONE 00 " , 1 ); // output text to LCD line 1
SendCmd(0x86); /* moves cursor to 7th character line 1*/
delay_ms(1);
do {zone_num = get_keypad();}
while (zone_num == 'X');
putc_LCD(zone_num);
delay_ms(750);
do {answer = get_keypad();}
while (answer == 'X');
if (answer == 'B')
{
state = 2;
}
else state = 0;
}
case 2: {
clrLCD();
if (zone_num == '1')
{
state = 1;
}
if (zone_num == '2' )
{
zone[1] = '0';
}
if (zone_num == '3')
{
zone[2] = '0';
}
if (zone_num == '4')
{
zone[3] = '0';
}
if (zone_num == '5')
{
zone[4] == '0';
}
if (zone_num == '6')
{
zone[5] == '0';
}
if (zone_num == '7')
{
zone[6] == '0';
}
}
}
} |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Apr 2005
Posts: 6
Rep Power: 0
![]() |
Where are your break statements?
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2005
Posts: 7
Rep Power: 0
![]() |
I am trying to implement a state machine not exit the switch statement after executing the relevant case, thought i didnt need break statements for this.
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
If you do not have breaks between each case, the code will flow through as if you didn't have a switch statement.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#5 |
|
Programming Guru
![]() |
Doesn't it flow through from the first case it agree with?
|
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() ![]() |
yes it flows through... he isn't using breaks after each case.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|