Skip to content

Instantly share code, notes, and snippets.

@mbamac

mbamac/lcd.s Secret

Last active May 4, 2017 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbamac/ec087be8ed23e54d4d88b799b71cbc95 to your computer and use it in GitHub Desktop.
Save mbamac/ec087be8ed23e54d4d88b799b71cbc95 to your computer and use it in GitHub Desktop.
; library for LCD with HD44780 chip
; by M. Bartosiak
; adresses of LCD registers
lcd_i = $DF00
lcd_d = $DF01
;_lcd_str_ptr must be defined elsewhere!!!!
; init and clear lcd display
; accumulator preserved
lcd_init
pha
jsr lcd_busy
lda #%00111000 ; $38: function set: 8 bit, 2 lines, 5x7
sta lcd_i
jsr lcd_busy
lda #%00000110 ; $06: entry mode set: increment, no shift
sta lcd_i
jsr lcd_busy
lda #%00001100 ; $0e: display on, cursor off, blink off
sta lcd_i
jsr lcd_busy
jsr lcd_clear
lda #$0
jsr lcd_goto
pla
rts
; print null-terminated string (up to 255 chars)
lcd_print
pha ;save a, y to stack
phy
ldy #$00
- lda (param_addr_ptr),y
beq +
jsr lcd_putchar
iny
bne -
+ ply ;restore a, y
pla
rts
; clear lcd and return cursor to home
; accumulator not preserved
lcd_clear
lda #%00000001 ; clear display
sta lcd_i
jmp lcd_busy
; to return from subroutine
; we will use "rts" from lcd_busy
; goto specific postion on lcd
; accumulator not preserved
lcd_goto
ora #%10000000
sta lcd_i
jmp lcd_busy
; to return from subroutine
; we will use "rts" from lcd_busy
; print byte as hex
; (accumulator not preserved)
lcd_hex
pha
lsr
lsr
lsr
lsr
jsr _lcd_hex
pla
and #$F
; here we are going to _lcd_hex
; without jump... :)
_lcd_hex
cmp #$A ; if a > 0xA
bcc + ; then
adc #$6 ; a += 0x6
+
adc #$30 ; a += '0'
; next we are going to lcd_putchar
; without jump... :)
; print single character from accumulator
; (accumulator not preserved)
lcd_putchar
sta lcd_d ; output the character
; next we are going to lcd_busy
; without jump... :)
; wait until lcd busy bit is clear
; (accumulator not preserved)
lcd_busy
- nop ; slow down a little
lda lcd_i ; read register instruction from lcd
bmi - ; check bit 7 (busy)
; after return in accumulator
; we should have current lcd memory location
rts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment