I have been programming PIC18F8720’s for the last few days. And things have been going OK. But I have been working with some TIMER code, and I did some calculations, and what I found was that the timer was being called a heap more than it should have been. In the example code it was being called 240 times more often. 240 times.

TIMER_INIT:
PR4 = 195
IPR3.3 = 1
PIR3.3 = 0
T4CON = %01111111
return

And then in my main loop I compared PIR3.3 and called the timer handler if it was HIGH. This code was fairly simple

LOOP:
if PIR3.3 = 1 then GOSUB TIMER_LOOP ' Timer has elapsed. Therefore Do It
gosub check_serial
goto LOOP

But the code was running a heap more than it should have. I worked out I needed to INIT the timer every time through the TIMER_LOOP. The code below shows the GOSUB. It now works.

TIMER_LOOP:
Gosub TIMER_INIT
TimerCount = TimerCount + 1
if timercount > 10 then
LED = 1 - LED
timercount = 0
LCDOUT $FE, $C0, "Now :", DEC LED
endif
return

Music: Tina Cousins