> From: James Fitzsimons [mailto:jamesfit@PARADISE.NET.NZ] > > Hi all, > I am trying to debug some code I have written and I can't > seem to understand why it is not working. The code builds > fine, and I have tested it on hardware, and in the simulator. > > I have included the code below (sorry about the size of it, > didn't want to leave out anything important!) > > The problem is if I output a character using putch(char) such > as the line directly after main() > "putch(success+1);" and I step through using the simulator > the program seems to get stuck on the "while(1)" instruction > and never seems to get to the "if (encoder_count == 50)".... > > If I comment out this first putch and change nothing else, > the program runs all the way through. I am getting consistent > results from both the simulator and hardware. > > Has anyone got any ideas? I am totally lost here as I don't > see why having that one putch line should cause the program > not to work! > [code deleted] If the Hi-Tech compiler was a superb optimizer, the whole "if (encoder_count == 50)" statement would not generate code. encoder_count needs to be declared as volatile to ensure that the compiler is aware that it can be changed outside of your tight while loop. Based on what I've seen and discussed with others, the Hi-Tech compiler will treat all variables as-if they are volatile. Assuming it isn't an issue of optimization, have the compiler generate a listing with assembly and C interleaved. Look at the code generated by the compiler and pay attention to the differences. In theory the code in the while loop should be the same. Also look at the code for putchar. Make sure that it doesn't do any bank switching that isn't also undone. I think the latest version of the compiler is good about dealing with bank switching, but earlier versions weren't so good. If you're using the MP-LAB simulator, I've noticed that it isn't the best at staying lined up with C source. It might help do watch your simulation run in the ROM window. The simulator is much better at staying lined up with assembly. -Mike -Mike -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body