blueroomelectronics
Well-Known Member
Here's working code that was designed for the Unicorn in LCD mode (it also works with Oshonsofts 18F & LCD simulator) It will be part of the Unicorn assembly manual.
PS anyone have any decent asm formatters for posting?
**broken link removed**
PS anyone have any decent asm formatters for posting?
**broken link removed**
Code:
list p=18F4550
include <p18F4550.inc>
CONFIG FOSC = INTOSC_HS, WDT = OFF, LVP = OFF, PBADEN = OFF
#define LCD_E LATE,2
#define LCD_RS LATE,0
#define LCD_RW LATE,1
#define LCD_BL LATB,3
delay equ 0
temp equ 1
org 0x000
movlw HIGH LCD_CC ; high byte
movwf TBLPTRH ; pointer to table high order byte
setf ADCON1 ; all I/O digital
bcf TRISB, 3 ; LCD backlight control
clrf TRISD ; LCD data output
clrf PORTE ; LCD control
clrf TRISE
clrf LATE ; zero output on E
movlw 0x02 ; use internal osc
movwf OSCCON ; 31.25KHz internal clock
; LCD soft reset (ignores/enables busy flag polling)
movlw .3 ; repeat sending 0x38 to reset LCD
movwf temp ; loop counter
_init3 movlw .131 ; 50ms delay
movwf delay ; enter with delay in ms via W
decfsz delay
bra $-2
bsf LCD_E ; LCD enable bit high
movlw 0x38 ; send 0x38 four times
movwf LATD ; LCD = 0x38 (8 bit mode x 2 line)
bcf LCD_E ; latches on High to Low transition
decfsz temp
bra _init3 ; repeat 3 times
bsf LCD_BL ; turn on backlight
; load special charaters into LCD RAM using LCD busy flag
movlw b'01000000' ; set LCD CG address to 00
rcall LCD_Ins ; relative call
clrf temp
movlw LOW 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
; clear & enable LCD DRAM, no visible cursor
movlw 0x0C ; display on, cursor off
rcall LCD_Ins
; display top 16 characters
movlw 0x01 ; clear display, home cursor
rcall LCD_Ins
movlw .16
movwf temp
movlw LOW Text_ ; low byte pointer
movwf TBLPTRL ; point to first line of text
_top tblrd*+ ; get in-line string character
movf TABLAT,W ; last character
rcall LCD_Chr
decfsz temp
bra _top
; display bottom 16 characters
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
bra $ ; endless loop done
; 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 LATD ; put data on LCD port
bcf LCD_E ; latch byte to LCD
bcf LCD_RS
setf 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
return
; text to display
org 0x0800
Text_ 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
END
Last edited: