But... wait a minute... The 'switch(state)' doesn't make any sense! The variable 'state' will always be zero at this point. It is local, you initialized it to zero, you didn't change it... Maybe you meant to make it 'static':

in case 0, (the initial state), there is a line that updates the variable 'state'. Same goes for case 1.

12-30-2012

comocomocomo

Quote:

Originally Posted by kim15

in case 0, (the initial state), there is a line that updates the variable 'state'. Same goes for case 1.

Yes, but this doesn't help, since 'state' is an automatic local variable, which gets initialized to 0 every time the processor enters the function. If the compiler follows the rules of the language, 'state' will always be 0 when the 'switch' is reached.

12-30-2012

kim15

oh. so should i declare it as a global?

12-31-2012

comocomocomo

You don't need it in any other function, and global variables are bad. Leave it local but make it static. It will live like a global variable (whole program execution lifespan, initialized only once), but it will remain private to its function.

01-28-2013

Click_here

You are using MPLAB from memory -> But you still haven't told us what compiler you are using!

It would also depend on whether you are using the LITE/Standard/PRO (You pay more money, your code gets optimised more)

The best way would be to actually see what is being generated -> The switch statement is usually better when programming your PIC, because it generates an optimised branching table.

Do the two different ways in your code. Click "View" -> "Disassembly listing"