LCD: moved address definition to main file.

This commit is contained in:
Martin Preuss
2023-01-30 01:02:04 +01:00
parent df3f1595da
commit 84c63f5651

View File

@@ -24,8 +24,6 @@
; *************************************************************************** ; ***************************************************************************
; defines ; defines
.equ LCD_TWI_ADDRESS = 0x3c
.equ LCD_WIDTH = 128 .equ LCD_WIDTH = 128
.equ LCD_HEIGHT = 64 .equ LCD_HEIGHT = 64
@@ -86,6 +84,12 @@ LCD_Init:
ldi zh, HIGH(lcdHelloMsg) ldi zh, HIGH(lcdHelloMsg)
rcall LCD_PrintFromFlash rcall LCD_PrintFromFlash
; set cursor to next line here, sometimes this doesn't work correctly
; when called later. TODO: find out what goes wrong here...
ldi r18, 0
ldi r19, 2
rcall LCD_SetCursor
sec sec
ret ret
@@ -117,7 +121,7 @@ LCD_Fini:
; - R19: Y ; - R19: Y
; OUT: ; OUT:
; - CFLAG: set if okay, cleared otherwise ; - CFLAG: set if okay, cleared otherwise
; REGS: r1, r2, r16 (R16, R17, R18, R22) ; REGS: r1, r2, r15, r16 (R16, R17, R18, R22)
LCD_SetCursor: LCD_SetCursor:
in r15, SREG in r15, SREG
@@ -173,42 +177,45 @@ LCD_SetCursor_error:
LCD_Fill: LCD_Fill:
in r15, SREG in r15, SREG
cli push r15
mov r20, r16 cli
mov r20, r16
ldi r21, 0 ; Y ldi r21, 0 ; Y
LCD_Fill_loopY: LCD_Fill_loopY:
clr r18 clr r18
mov r19, r21 mov r19, r21
rcall LCD_SetCursor rcall LCD_SetCursor
brcc LCD_Fill_error
rcall twiStart
ldi r16, (LCD_TWI_ADDRESS*2)
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
brcc LCD_Fill_error
ldi r16, LCD_DATA_MODE
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
brcc LCD_Fill_error
ldi r19, 0
LCD_Fill_loopX:
mov r16, r20
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
rcall twiSendByte
brcc LCD_Fill_error brcc LCD_Fill_error
inc r19
cpi r19, LCD_WIDTH rcall twiStart
brcs LCD_Fill_loopX ldi r16, (LCD_TWI_ADDRESS*2)
rcall twiStop rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
inc r21 brcc LCD_Fill_error
cpi r21, LCD_PAGE_COUNT ldi r16, LCD_DATA_MODE
brcs LCD_Fill_loopY rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
brcc LCD_Fill_error
ldi r19, 0
LCD_Fill_loopX:
mov r16, r20
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
rcall twiSendByte
brcc LCD_Fill_error
inc r19
cpi r19, LCD_WIDTH
brcs LCD_Fill_loopX
rcall twiStop
inc r21
cpi r21, LCD_PAGE_COUNT
brcs LCD_Fill_loopY
pop r15
out SREG, r15 out SREG, r15
sec sec
ret ret
LCD_Fill_error: LCD_Fill_error:
rcall twiStop rcall twiStop
pop r15
out SREG, r15 out SREG, r15
clc clc
ret ret
@@ -228,36 +235,39 @@ LCD_Fill_error:
LCD_PrintFromFlash: LCD_PrintFromFlash:
in r15, SREG in r15, SREG
cli push r15
lsl zl cli
rol zh lsl zl
rcall twiStart rol zh
ldi r16, (LCD_TWI_ADDRESS*2) rcall twiStart
rcall twiSendByteExpectAck ; (R16, R17, R18, R22) ldi r16, (LCD_TWI_ADDRESS*2)
brcc LCD_PrintFromFlash_error rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
ldi r16, LCD_DATA_MODE brcc LCD_PrintFromFlash_error
rcall twiSendByteExpectAck ; (R16, R17, R18, R22) ldi r16, LCD_DATA_MODE
brcc LCD_PrintFromFlash_error rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
brcc LCD_PrintFromFlash_error
LCD_PrintFromFlash_loop: LCD_PrintFromFlash_loop:
lpm r16, z+ lpm r16, z+
tst r16 tst r16
breq LCD_PrintFromFlash_end breq LCD_PrintFromFlash_end
push zh push zh
push zl push zl
rcall lcdPrintOneChar rcall lcdPrintOneChar
pop zl pop zl
pop zh pop zh
brcc LCD_PrintFromFlash_error brcc LCD_PrintFromFlash_error
rjmp LCD_PrintFromFlash_loop rjmp LCD_PrintFromFlash_loop
LCD_PrintFromFlash_end: LCD_PrintFromFlash_end:
rcall twiStop rcall twiStop
pop r15
out SREG, r15 out SREG, r15
sec sec
ret ret
LCD_PrintFromFlash_error: LCD_PrintFromFlash_error:
rcall twiStop rcall twiStop
pop r15
out SREG, r15 out SREG, r15
clc clc
ret ret
@@ -302,7 +312,7 @@ LCD_PrintChar_error:
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; LCD_PrintHexByte ; LCD_PrintHexByte
; ;
; Convert a give byte into HEX and write it to the current position. ; Convert a given byte into HEX and write it to the current position.
; ;
; IN: ; IN:
; - R16: byte to convert to hex ; - R16: byte to convert to hex
@@ -311,24 +321,27 @@ LCD_PrintChar_error:
LCD_PrintHexByte: LCD_PrintHexByte:
in r15, SREG in r15, SREG
cli push r15
mov r20, r16 cli
rcall twiStart mov r20, r16
ldi r16, (LCD_TWI_ADDRESS*2) rcall twiStart
rcall twiSendByteExpectAck ; (R16, R17, R18, R22) ldi r16, (LCD_TWI_ADDRESS*2)
brcc LCD_PrintHexByte_error rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
ldi r16, LCD_DATA_MODE brcc LCD_PrintHexByte_error
rcall twiSendByteExpectAck ; (R16, R17, R18, R22) ldi r16, LCD_DATA_MODE
brcc LCD_PrintHexByte_error rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
mov r16, r20 brcc LCD_PrintHexByte_error
rcall lcdPrintHexByte mov r16, r20
brcc LCD_PrintHexByte_error rcall lcdPrintHexByte
rcall twiStop brcc LCD_PrintHexByte_error
rcall twiStop
pop r15
out SREG, r15 out SREG, r15
sec sec
ret ret
LCD_PrintHexByte_error: LCD_PrintHexByte_error:
rcall twiStop rcall twiStop
pop r15
out SREG, r15 out SREG, r15
clc clc
ret ret
@@ -349,29 +362,33 @@ LCD_PrintHexByte_error:
LCD_PrintHexWord: LCD_PrintHexWord:
in r15, SREG in r15, SREG
cli push r15
push r18 cli
push r19 push r18
rcall twiStart push r19
ldi r16, (LCD_TWI_ADDRESS*2) rcall twiStart
rcall twiSendByteExpectAck ; (R16, R17, R18, R22) ldi r16, (LCD_TWI_ADDRESS*2)
brcc LCD_PrintHexWord_error rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
ldi r16, LCD_DATA_MODE brcc LCD_PrintHexWord_errorPop
rcall twiSendByteExpectAck ; (R16, R17, R18, R22) ldi r16, LCD_DATA_MODE
brcc LCD_PrintHexWord_error rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
pop r19 brcc LCD_PrintHexWord_errorPop
pop r18 pop r19
pop r18
rcall lcdPrintHexWord rcall lcdPrintHexWord
brcc LCD_PrintHexWord_error brcc LCD_PrintHexWord_errorNoPop
rcall twiStop rcall twiStop
pop r15
out SREG, r15 out SREG, r15
sec sec
ret ret
LCD_PrintHexWord_error: LCD_PrintHexWord_errorPop:
rcall twiStop rcall twiStop
pop r19 pop r19
pop r18 pop r18
LCD_PrintHexWord_errorNoPop:
pop r15
out SREG, r15 out SREG, r15
clc clc
ret ret