View Full Version : Any Misc Programmers Bored and wanna help a bro out? small reps

10-25-2010, 07:00 PM
looking for a simple state machine in C...all it needs to do is start in STATE0 with two inputs to a microcontroller when the inputs are 0,0...then transition to STATE1 when the inputs are 1,0...if you want to know the location of the inputs are on PTP_PTPB7 and PTP_PTPB6...we are using the CodeWarrior program to complie, program and run everything and are having trouble getting the compiler to work...have tried our own, tried copy and paste from google searches...always get errors...not lookin for our whole program just a small example and wanting to see if yall can come up with something i could tweak and plug in to work...small reps :/

10-25-2010, 07:47 PM
Don't really have a lot of of info to go off of but here's something quick:

int setState0()
//Do whatever state0 is supposed to do

int setState1()
//Do whatever state1 is supposed to do

int main()
//Initialize input values
int input1 = 0;
int input2 = 0;

//Initialize vars to store previous input1/input2 values
int prevInput1 = 0;
int prevInput2 = 0;

//Loop indefinitely
//Retrieve latest input values
input1 = (whatever call you need to access the PTP_PTPB6 register);
input2 = (whatever call you need to access the PTP_PTPB7 register);

//Check if the inputs have changed
if( input1 != prevInput1 || input2 != prevInput2 )
if( input1 == 0 && input2 == 0 )
int returnVal = setState0();
else if ( input1 == 1 && input2 == 0 )
int returnVal = setState1();
//then more 'else if' statements depending on if there are more states

//Update previous input values
prevInput1 = input1;
prevInput2 = input2;

return 0;

Obviously not complete but I think that should work, you just need to figure out what calls you need to read the register values. Might be some documentation with the microcontroller for that though.