Files
aqhomecontrol/avr/lcd.asm
2023-01-28 15:29:58 +01:00

150 lines
2.6 KiB
NASM

; ***************************************************************************
; defines
.equ LCD_CONTROLBYTE_DC_MASK = 0x40
.equ LCD_CONTROLBYTE_CO_MASK = 0x80
.equ LCD_TWI_ADDRESS = 0x3c
.equ LCD_WIDTH = 128
.equ LCD_HEIGHT = 64
; ***************************************************************************
; data
.dseg
lcdDataBegin:
lcdDataEnd:
; ***************************************************************************
; code
.cseg
LCD_Init:
sbi DDRA, PORTA2 ; debug
sbi PORTA, PORTA2 ; debug (off)
ldi zl, LOW(lcdInitCommandsBegin)
ldi zh, HIGH(lcdInitCommandsBegin)
ldi r16, (lcdInitCommandsEnd-lcdInitCommandsBegin)*2
rcall lcdWriteCommandsFromFlash
ldi r16, 0
rcall LCD_Fill
sec
ret
; - R16: number of bytes to send
; - Z=pointer to data
lcdWriteCommandsFromFlash:
rcall twiStart
lsl zl
rol zh
mov r20, r16 ; number of bytes
ldi r16, (LCD_TWI_ADDRESS*2)
rcall twiSendByte
brcc lcdWriteCommandsFromFlash_error
tst r16
brne lcdWriteCommandsFromFlash_error
lcdWriteCommandsFromFlash_loop:
lpm r16, z+
rcall twiSendByte
brcc lcdWriteCommandsFromFlash_error
tst r16
brne lcdWriteCommandsFromFlash_error
dec r20
brne lcdWriteCommandsFromFlash_loop
rcall twiStop
sbi DDRA, PORTA2 ; debug
cbi PORTA, PORTA2 ; debug (on)
sec
ret
lcdWriteCommandsFromFlash_error:
rcall twiStop
clc
ret
; - R16: data to write
LCD_Fill:
mov r20, r16
rcall twiStart
ldi r16, (LCD_TWI_ADDRESS*2)
rcall twiSendByte
brcc LCD_Fill_error
tst r16
brne LCD_Fill_error
ldi r21, 0 ; Y
LCD_Fill_loopY:
ldi r16, 0xb0 ; set page address (data byte and next control byte follow, data byte is a command)
add r16, r21
rcall twiSendByte
brcc LCD_Fill_error
tst r16
brne LCD_Fill_error
ldi r16, 0x01 ; set lower column address
rcall twiSendByte
brcc LCD_Fill_error
tst r16
brne LCD_Fill_error
ldi r16, 0x10 ; set higher column bits
rcall twiSendByte
brcc LCD_Fill_error
tst r16
brne LCD_Fill_error
ldi r19, 0
LCD_Fill_loopX:
mov r16, r20
rcall twiSendByte
brcc LCD_Fill_error
tst r16
brne LCD_Fill_error
inc r19
cpi r19, LCD_WIDTH
brcs LCD_Fill_loopX
inc r21
cpi r21, 8
brcs LCD_Fill_loopY
rcall twiStop
sec
ret
LCD_Fill_error:
rcall twiStop
clc
ret
lcdInitCommandsBegin: ; 28 bytes
.db 0xae, 0x00, 0x10, 0x40, 0x81, 0xcf, 0xa1, 0xc8
.db 0xa6, 0xa8, 0x3f, 0xd3, 0x00, 0xd5, 0x80, 0xd9
.db 0xf1, 0xda, 0x12, 0xdb, 0x40, 0x20, 0x02, 0x8d
.db 0x14, 0xa4, 0xa6, 0xaf
lcdInitCommandsEnd: