list p=18F4550
include <p18F4550.inc>
CONFIG FOSC = INTOSC_HS, WDT = OFF, LVP = OFF, DEBUG = ON
CONFIG PBADEN = OFF, PLLDIV = 5
#define LCD_E LATE,2
#define LCD_RS LATE,0
#define LCD_RW LATE,1
#define LCD_BL LATB,3
#define LCD_DAT LATD
cblock 0 ; ram starts at 0x000
delay
temp
endc
org 0x000
nop
bra Init
; *** pad each entry to 16 characters db " <16> "
Text_ db .4,.5," Creatron Inc"
db .6,.7," 16x2 LCD "
db "blueroom ",.0,.1
db "electronics ",.2,.3
; *** 2x2 blueroomelectronics logo (house)
LCD_CC db .128,.128,.129,.131,.135,.143,.159,.159
db .128,.128,.128,.144,.152,.156,.158,.130
db .159,.159,.159,.145,.145,.145,.159,.128
db .130,.130,.158,.130,.130,.130,.158,.128
; *** 2x2 creatron logo (c)
db .128,.128,.135,.143,.156,.153,.154,.154
db .128,.128,.158,.159,.130,.152,.132,.128
db .154,.154,.153,.156,.143,.135,.128,.128
db .128,.132,.152,.130,.159,.158,.128,.128
Init clrf TBLPTRH ; table in first 256 bytes memory
movlw 0x0A
movwf ADCON1
movlw b'11110111'
movwf TRISB
clrf TRISD ; LCD Data output
clrf PORTE ; LCD Control
clrf TRISE
clrf LATE ; zero output on E
movlw b'00000010' ; use internal osc
movwf OSCCON ; 32KHz internal clock
;wait 15ms before using LCD
movlw .4 ; repeat sending 0x38 to reset LCD
movwf temp ; loop counter
_init3 movlw .50 ; 50ms delay
rcall dly1ms ;
bsf LCD_E ; LCD enable bit high
movlw 0x38 ; send 0x38 four times
movwf LCD_DAT ; LCD = 0x38 (8 bit mode x 2 line)
bcf LCD_E ; latches on High to Low transition
decfsz temp
bra _init3 ; repeat 3 times
; load special charaters into LCD RAM
movlw b'01000000' ; set LCD CG address to 00
rcall LCD_Ins ; relative call
clrf temp
movlw LCD_CC ; pointer to custom charater table
movwf TBLPTRL
_nextcc tblrd*+ ; get in-line string character
movf TABLAT,W ; last character
rcall LCD_Chr ; send the character into LCD RAM
incf temp
btfss temp, 6 ; 64 bytes total
bra _nextcc
Restart movlw Text_
movwf TBLPTRL ; point to first line of text
rcall Clr_LCD
movlw .9
movwf temp
_wait movlw .250
rcall dly1ms
decfsz temp
bra _wait
rcall Clr_LCD
movlw .9
movwf temp
_wait1 movlw .250
rcall dly1ms
decfsz temp
bra _wait1
bra Restart ; loop forever, if fail WDT restart
Clr_LCD movlw 0x01 ; clear display
rcall LCD_Ins
movlw 0x0C ; display on, cursor off
rcall LCD_Ins
bsf LCD_BL ; turn on backlight
movlw .16
movwf temp
_top tblrd*+ ; get in-line string character
movf TABLAT,W ; last character
rcall LCD_Chr
decfsz temp
bra _top
movlw 0xC0 ; set cursor to second line
rcall LCD_Ins
movlw .16
movwf temp
_bot tblrd*+ ; get in-line string character
movf TABLAT,W ; last character
rcall LCD_Chr
decfsz temp
bra _bot
return
; LCD entry routines watches busy flag
LCD_Chr bsf LCD_RS ; enable Charater mode
LCD_Ins bsf LCD_E
clrf TRISD ; make PORTD an output
movwf LCD_DAT ; put data on LCD port
bcf LCD_E ; latch byte to LCD
movlw 0xFF
bcf LCD_RS
movwf TRISD ; make LCD port input
bsf LCD_RW ; enter read mode
bsf LCD_E ; enable LCD
_BusyFl btfsc PORTD,7 ; wait for bit 7 to be pulled low
bra _BusyFl
bcf LCD_RW ; return to Instruction mode
clrwdt ; if no LCD program will lock up
return
dly1ms movwf delay ; enter with delay in ms via W
_loop1 bra $+2
bra $+2
clrwdt
decfsz delay
bra _loop1
return
END