Hello, I want to use the Timer 0 on the C167 in a program. The initialization is:
void initTimer(INT16U reloadVal) { T0REL = reloadVal; T0 = reloadVal; T01CON= 0x0042; /* Prescalar = 32, Timer Mode, Timer enabled */ T0IC = 0x007C; /* T0IE = 1 ILVL=15 GLVL=0 */ }
One thing that has made my programs work on the simulator and not the real device is over-writing variables by doing something like writing more characters to a buffer than it can hold. The simulator does not always catch this. I rather strongly doubt the correctness of that analysis. The simulator and real hardware are equally unlikely to catch simple buffer overflows. Hardware doesn't ever catch plain buffer overflows. The simulator may, but only if they overflow not just the buffer, but the entire configured memory space. What hardware does in such a case depends on the hardware. If it trips on something the simulator didn't detect, that's a sign of mis-configuration of the simulator, e.g. by claiming you have more memory than you actually do. If a program works better in the simulator than on the metal, that's almost certainly for other reasons. Most prominently these two: 1) real memory comes up with random content after power-up, the simulator tends to boot with all RAM filled with zeroes. If this makes a difference to your program, that's a bug in the code (uninitialized variables). 2) crashing or misbehaving peripherals that aren't simulated at all.
"2) crashing or misbehaving peripherals that aren't simulated at all." Or even real peripherals that are behaving perfectly correctly, but the simulation was flawed...