Implement a timer without using an interrupt
I've read the posts on using timers, but I have not been able to get one to work in my situation. I would like to use a timer to turn off a LCD backlight after approximately 5 seconds without pausing program execution. I am using PORTD.6 of a 16F877A to turn the LCD backlight on. Here is what I tried:
T2CON = %01111010 ' Pre- and Post-scaler 1:16, stop timer
Counter VAR BYTE
MAIN:
if PORTB <> 255 then GOSUB UPDATE_LCD
if PIR1.1 = 1 then
Counter = Counter + 1
PIR1.1 = 0
endif
if Counter = 350 then
PORTD.6 = 0
T2CON.2 = 0
endif
GOTO MAIN
UPDATE_LCD:
PORTD.6 = 1 ' Turn on backlight
T2CON.2 = 1 ' Turn on timer
' Code to update LCD information
RETURN