;============LCD8.ASM===================
list P=16F876a
#include "P16F876A.inc"
__config 0x3FF9
radix hex
[COLOR=Red][B] ;=======================================
; cpu equates
status equ 0x03
porta equ 0x05
portb equ 0x06
portc equ 0x07
count1 equ 0x0c
count2 equ 0x0d
trisa equ 0x85
trisb equ 0x86
trisc equ 0x87
;=======================================
; bit equates
rp0 equ 5
;=======================================[/B][/COLOR]
org 0x000
;
start bsf status,rp0 ;switch to bank 1
movlw b'00000000' ;outputs
movwf trisa
movwf trisb
movwf trisc
bcf status,rp0 ;switch back to bank0
movlw b'00000000' ;all outputs low
movwf porta
movwf portb
movwf portc
call del_5 ;allow lcd time to initialise itself
call del_5
call initlcd ;initialise display
circle goto circle ;done
;=======================================
;=======================================
;=======================================
initlcd bcf portc,1 ;E line low
bcf portc,2 ;RS line low, setup for control
call del_125 ;delay 125 microseconds
movlw 0x38 ;8-bit, 5x7
movwf portb ;0011 1000
call pulse ;pulse and delay
movlw 0x0f
movwf portb ;0000 1111
call pulse
movlw 0x01 ;clear display
movwf portb ;increment mode, no display shift
call pulse
call del_5 ;delay 5 milliseconds after init
call del_5
return
;========================================
;==================================
del_125 movlw 0x2a ;approx 42x3 cycles (decimal)
movwf count1 ;load counter
repeat decfsz count1,f ;decrement counter
goto repeat ;not 0
return
;==================================
del_5 movlw 0x29 ;decimal 40
movwf count2 ;to timer
delay call del_125 ;delay 125 micro seconds
decfsz count2,f ;do it 40 times = 5 milliseconds
goto delay
return ;counter 0, ends delay
;==================================
pulse bsf portc,1 ;pulse E line
nop ;delay
bcf portc,1
call del_125 ;125 micrsecond delay
return
;==================================
end
;==================================