At the very least...
TMR0H is not the actual high byte of Timer0 in 16-bit mode. It is actually a buffered version of the real high
byte of Timer0 which is not directly readable nor writable (refer to Figure 11-2). TMR0H is updated with
the contents of the high byte of Timer0 during a read of TMR0L. This provides the ability to read all 16 bits of
Timer0 without having to verify that the read of the high and low byte were valid, due to a rollover between
successive reads of the high and low byte.
Similarly, a write to the high byte of Timer0 must also take place through the TMR0H Buffer register. The high
byte is updated with the contents of TMR0H when a write occurs to TMR0L. This allows all 16 bits of Timer0
to be updated at once.
So, to set TH & TL you MUST write the values in the correct order
TMR0H = Timer_High; // must set TH before writing to TL
TMR0L = Timer_Low; // writing to TL updates TL and TH
@DavidDLC,
Your code may appear to work but in reality the first interrupt will be slow to appear, after that the value you set in TH will be the previous value written to the TH
buffer, not necessarily the value currently in Timer_High.
@Bibiricat,
You have the same problem in your initialisation code
TMR0L = 0x82; //(255-130)*4/Fosc *prescaler=0.05ms
TMR0H = 0x85;
So, TL = 0x82, the TH
buffer = 0x85 but the actual TH register = ?? ie whatever happened to be in the TH
buffer at the time TL was written, after a reset it could well be zero.
In this case you are running a 1/255 prescaler. At 8MHz: 8000000 / 4 / 256 = 7812.5Hz timer frequency, assuming 0 in TH your count to interrupt will be around 0xff00 (65280), 65280 * 1 / 7812.5 = 8.35584 seconds
You appear to be running at 2MHz (? from the TMR0L comment above), so the time to your first interrupt will be around 40 seconds, after which you will run at your 0xEEEE timings.
Your code looks feasible, are you perhaps declaring the code bad before the 40 seconds are up? I've certainly done this at least once... or twice
