A slightly different method:
Updating LCDs is really time consuming, from a PIC viewpoint. I find that a .25(once every 4 seconds) update rate is about right for most people, especially if it a two-line display.
The code below lets your code run at full speed and updates the LCD once every 4 seconds. Of course the rate can be changed to suit the user. It uses an ASM interrupt for low overhead.
Of course, you could read the timer directly, but I find that I always need interrupts anyway.
Code:
DEFINE OSC 4
MasterClock VAR WORD BANKA SYSTEM
;----------------Timer Setup-----------------------------------
T0CON = 000010 ; /1:8 prescaler, tmr0 ON
;
;-------------------------------------------------------------
INCLUDE "DT_INTS-18.bas" '
;---------------------------------------------------------------
asm
INT_LIST macro
INT_Handler TMR0_INT, MainTimer, ASM, yes
endm
INT_CREATE
endasm
''----------------- Initialization Done! -----------------------------
Goto OverInt
;----------------------- Timer INt ------------------------------------
ASM
MainTimer
movlw 0xCF ; 100 mSec @ 4MHz
movwf TMR0H
movlw 0x2C
movwf TMR0L
btfsc MasterClock + 1,7 ; Don't let MasterClock roll over
bra DontCount
infsnz MasterClock
incf MasterClock + 1
DontCount
bcf INTCON,2
INT_ENABLE TMR0_INT
INT_RETURN
ENDASM
;---------------------------------------------------------------------
OverInt:
INTCON.7 = 1 ; Main Ints
INTCON.6 = 1 ; Peripheral ints
MasterClock = 0
@ bcf INTCON,2
@ INT_ENABLE TMR0_INT
TopOfLoop:
If MasterClock >= 20 then ; 20 X .1 sec = 2 seconds
MasterClock = 0
; Do LCD routines here
endif
; Your main program here
goto TopOfLoop
Bookmarks