avr: improved lcd module.
This commit is contained in:
@@ -77,7 +77,7 @@ LCD_BEGIN:
|
|||||||
LCD_Init:
|
LCD_Init:
|
||||||
ldi zl, LOW(lcdInitCommandsBegin)
|
ldi zl, LOW(lcdInitCommandsBegin)
|
||||||
ldi zh, HIGH(lcdInitCommandsBegin)
|
ldi zh, HIGH(lcdInitCommandsBegin)
|
||||||
ldi r16, 8
|
ldi r16, 28
|
||||||
rcall lcdWriteCommandsFromFlash
|
rcall lcdWriteCommandsFromFlash
|
||||||
|
|
||||||
ldi r16, 0
|
ldi r16, 0
|
||||||
@@ -89,7 +89,7 @@ LCD_Init:
|
|||||||
ldi r16, 0
|
ldi r16, 0
|
||||||
rcall LCD_Fill
|
rcall LCD_Fill
|
||||||
|
|
||||||
ldi r18, 20
|
ldi r18, 0
|
||||||
ldi r19, 0
|
ldi r19, 0
|
||||||
rcall LCD_SetCursor
|
rcall LCD_SetCursor
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ LCD_Init:
|
|||||||
; set cursor to next line here, sometimes this doesn't work correctly
|
; set cursor to next line here, sometimes this doesn't work correctly
|
||||||
; when called later. TODO: find out what goes wrong here...
|
; when called later. TODO: find out what goes wrong here...
|
||||||
ldi r18, 0
|
ldi r18, 0
|
||||||
ldi r19, 2
|
ldi r19, 0
|
||||||
rcall LCD_SetCursor
|
rcall LCD_SetCursor
|
||||||
|
|
||||||
sec
|
sec
|
||||||
@@ -123,6 +123,127 @@ LCD_Fini:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine LCD_Sleep @global
|
||||||
|
;
|
||||||
|
; @return nothing
|
||||||
|
; @param r16 1=sleep, 0=awake
|
||||||
|
; @clobbers r15, r16, r19 (R17, R18, R22)
|
||||||
|
;
|
||||||
|
|
||||||
|
LCD_Sleep:
|
||||||
|
ldi r16, 0xae ; set sleep
|
||||||
|
tst r19
|
||||||
|
brne LCD_Sleep_send
|
||||||
|
ldi r16, 0xaf ; set wake
|
||||||
|
LCD_Sleep_send:
|
||||||
|
rjmp lcdOneByteCommand
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine lcdOneByteCommand
|
||||||
|
; Send a one byte command
|
||||||
|
;
|
||||||
|
; @return nothing
|
||||||
|
; @param r20 first byte of command
|
||||||
|
; @clobbers r15, r16, r19 (R17, R18, R22)
|
||||||
|
;
|
||||||
|
|
||||||
|
lcdOneByteCommand:
|
||||||
|
in r15, SREG
|
||||||
|
push r15
|
||||||
|
cli
|
||||||
|
|
||||||
|
rcall lcdBeginMultiCommand
|
||||||
|
brcc lcdOneByteCommand_error
|
||||||
|
|
||||||
|
mov r16, r20
|
||||||
|
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
||||||
|
brcc lcdOneByteCommand_error
|
||||||
|
|
||||||
|
rcall twiStop ; (R22)
|
||||||
|
pop r15
|
||||||
|
out SREG, r15
|
||||||
|
sec
|
||||||
|
ret
|
||||||
|
|
||||||
|
lcdOneByteCommand_error:
|
||||||
|
rjmp lcdTwiStopPopR15ClcRet ; (R22)
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine lcdTwoByteCommand
|
||||||
|
; Send a two byte command
|
||||||
|
;
|
||||||
|
; @return nothing
|
||||||
|
; @param r20 first byte of command
|
||||||
|
; @param r21 second byte of command
|
||||||
|
; @clobbers r15, r16, r19 (R17, R18, R22)
|
||||||
|
;
|
||||||
|
|
||||||
|
lcdTwoByteCommand:
|
||||||
|
in r15, SREG
|
||||||
|
push r15
|
||||||
|
cli
|
||||||
|
|
||||||
|
rcall lcdBeginMultiCommand
|
||||||
|
brcc lcdTwoByteCommand_error
|
||||||
|
|
||||||
|
mov r16, r20
|
||||||
|
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
||||||
|
brcc lcdTwoByteCommand_error
|
||||||
|
|
||||||
|
mov r16, r21
|
||||||
|
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
||||||
|
brcc lcdTwoByteCommand_error
|
||||||
|
|
||||||
|
rcall twiStop ; (R22)
|
||||||
|
pop r15
|
||||||
|
out SREG, r15
|
||||||
|
sec
|
||||||
|
ret
|
||||||
|
|
||||||
|
lcdTwoByteCommand_error:
|
||||||
|
rjmp lcdTwiStopPopR15ClcRet ; (R22)
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine lcdBeginMultiCommand
|
||||||
|
; Send a two byte command
|
||||||
|
;
|
||||||
|
; @return nothing
|
||||||
|
; @param r20 first byte of command
|
||||||
|
; @param r21 second byte of command
|
||||||
|
; @clobbers r16, (R17, R18, R22)
|
||||||
|
;
|
||||||
|
|
||||||
|
lcdBeginMultiCommand:
|
||||||
|
rcall twiStart ; (R22)
|
||||||
|
ldi r16, (LCD_TWI_ADDRESS*2)
|
||||||
|
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
||||||
|
brcc lcdTwoByteCommand_error
|
||||||
|
|
||||||
|
ldi r16, LCD_MODE_MULTICMD
|
||||||
|
rjmp twiSendByteExpectAck ; (R16, R17, R18, R22)
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
lcdTwiStopPopR15ClcRet:
|
||||||
|
rcall twiStop ; (R22)
|
||||||
|
pop r15
|
||||||
|
out SREG, r15
|
||||||
|
clc
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
; LCD_SetCursor
|
; LCD_SetCursor
|
||||||
;
|
;
|
||||||
@@ -150,33 +271,31 @@ LCD_SetCursor:
|
|||||||
ldi r16, LCD_MODE_MULTICMD
|
ldi r16, LCD_MODE_MULTICMD
|
||||||
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
||||||
brcc LCD_SetCursor_error
|
brcc LCD_SetCursor_error
|
||||||
mov r16, r2
|
mov r16, r2 ; Y
|
||||||
andi r16, 0x07
|
andi r16, 0x07
|
||||||
ori r16, 0xb0 ; Set Page Start Address for Page Addressing Mode
|
ori r16, 0xb0 ; set page start address for page addressing mode
|
||||||
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
||||||
brcc LCD_SetCursor_error
|
brcc LCD_SetCursor_error
|
||||||
mov r16, r1
|
|
||||||
andi r16, 0x0f ; Set Lower Column Start Address
|
ldi r16, 0x21 ; set column start
|
||||||
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
||||||
brcc LCD_SetCursor_error
|
brcc LCD_SetCursor_error
|
||||||
mov r16, r1
|
|
||||||
swap r16
|
mov r16, r1 ; X
|
||||||
andi r16, 0x0f
|
|
||||||
ori r16, 0x10 ; Set Higher Column Start Address
|
|
||||||
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
||||||
brcc LCD_SetCursor_error
|
brcc LCD_SetCursor_error
|
||||||
|
|
||||||
|
ldi r16, LCD_WIDTH-1
|
||||||
|
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
||||||
|
brcc LCD_SetCursor_error
|
||||||
|
|
||||||
rcall twiStop ; (R22)
|
rcall twiStop ; (R22)
|
||||||
pop r15
|
pop r15
|
||||||
out SREG, r15
|
out SREG, r15
|
||||||
sec
|
sec
|
||||||
ret
|
ret
|
||||||
LCD_SetCursor_error:
|
LCD_SetCursor_error:
|
||||||
rcall twiStop ; (R22)
|
rjmp lcdTwiStopPopR15ClcRet ; (R22)
|
||||||
pop r15
|
|
||||||
out SREG, r15
|
|
||||||
clc
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -208,19 +327,19 @@ LCD_Fill_loopY:
|
|||||||
ldi r16, (LCD_TWI_ADDRESS*2)
|
ldi r16, (LCD_TWI_ADDRESS*2)
|
||||||
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
||||||
brcc LCD_Fill_error
|
brcc LCD_Fill_error
|
||||||
|
|
||||||
ldi r16, LCD_MODE_DATA
|
ldi r16, LCD_MODE_DATA
|
||||||
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
||||||
brcc LCD_Fill_error
|
brcc LCD_Fill_error
|
||||||
|
|
||||||
ldi r19, 0
|
ldi r19, LCD_WIDTH ; count backwards to save one instruction
|
||||||
LCD_Fill_loopX:
|
LCD_Fill_loopX:
|
||||||
mov r16, r20
|
mov r16, r20
|
||||||
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
||||||
rcall twiSendByte
|
rcall twiSendByte
|
||||||
brcc LCD_Fill_error
|
brcc LCD_Fill_error
|
||||||
inc r19
|
dec r19
|
||||||
cpi r19, LCD_WIDTH
|
brne LCD_Fill_loopX
|
||||||
brcs LCD_Fill_loopX
|
|
||||||
rcall twiStop
|
rcall twiStop
|
||||||
inc r21
|
inc r21
|
||||||
cpi r21, LCD_PAGE_COUNT
|
cpi r21, LCD_PAGE_COUNT
|
||||||
@@ -230,11 +349,7 @@ LCD_Fill_loopX:
|
|||||||
sec
|
sec
|
||||||
ret
|
ret
|
||||||
LCD_Fill_error:
|
LCD_Fill_error:
|
||||||
rcall twiStop
|
rjmp lcdTwiStopPopR15ClcRet ; (R22)
|
||||||
pop r15
|
|
||||||
out SREG, r15
|
|
||||||
clc
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -282,11 +397,7 @@ LCD_PrintFromFlash_end:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
LCD_PrintFromFlash_error:
|
LCD_PrintFromFlash_error:
|
||||||
rcall twiStop
|
rjmp lcdTwiStopPopR15ClcRet ; (R22)
|
||||||
pop r15
|
|
||||||
out SREG, r15
|
|
||||||
clc
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -320,11 +431,7 @@ LCD_PrintChar:
|
|||||||
sec
|
sec
|
||||||
ret
|
ret
|
||||||
LCD_PrintChar_error:
|
LCD_PrintChar_error:
|
||||||
rcall twiStop
|
rjmp lcdTwiStopPopR15ClcRet ; (R22)
|
||||||
pop r15
|
|
||||||
out SREG, r15
|
|
||||||
clc
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -359,11 +466,7 @@ LCD_PrintHexByte:
|
|||||||
sec
|
sec
|
||||||
ret
|
ret
|
||||||
LCD_PrintHexByte_error:
|
LCD_PrintHexByte_error:
|
||||||
rcall twiStop
|
rjmp lcdTwiStopPopR15ClcRet ; (R22)
|
||||||
pop r15
|
|
||||||
out SREG, r15
|
|
||||||
clc
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -514,6 +617,10 @@ lcdWriteCommandsFromFlash:
|
|||||||
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
||||||
brcc lcdWriteCommandsFromFlash_error
|
brcc lcdWriteCommandsFromFlash_error
|
||||||
|
|
||||||
|
ldi r16,LCD_MODE_MULTICMD
|
||||||
|
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
||||||
|
brcc lcdWriteCommandsFromFlash_error
|
||||||
|
|
||||||
lcdWriteCommandsFromFlash_loop:
|
lcdWriteCommandsFromFlash_loop:
|
||||||
lpm r16, z+
|
lpm r16, z+
|
||||||
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
rcall twiSendByteExpectAck ; (R16, R17, R18, R22)
|
||||||
@@ -649,7 +756,11 @@ lcdUpcase_done:
|
|||||||
|
|
||||||
; TODO: set adressing mode??
|
; TODO: set adressing mode??
|
||||||
lcdInitCommandsBegin: ; 28 bytes
|
lcdInitCommandsBegin: ; 28 bytes
|
||||||
.db LCD_MODE_MULTICMD, 0xa8, ((LCD_PAGE_COUNT*8)-1), 0x8d, 0x14, 0xaf, 0xa1, 0xc8
|
; .db LCD_MODE_MULTICMD, 0xa8, ((LCD_PAGE_COUNT*8)-1), 0x8d, 0x14, 0xaf, 0xa1, 0xc8
|
||||||
|
.db 0xae, 0x20, 0x00, 0xb0, 0xc8, 0x00, 0x10, 0x40
|
||||||
|
.db 0x81, 0x3f, 0xa1, 0xa6, 0xa8, LCD_HEIGHT-1, 0xa4, 0xd3
|
||||||
|
.db 0x00, 0xd5, 0xf0, 0xd9, 0x22, 0xda, 0x12, 0xdb
|
||||||
|
.db 0x20, 0x8d, 0x14, 0xaf
|
||||||
lcdInitCommandsEnd:
|
lcdInitCommandsEnd:
|
||||||
|
|
||||||
lcdHelloMsg: .db "AqHOME 2024", 0
|
lcdHelloMsg: .db "AqHOME 2024", 0
|
||||||
|
|||||||
Reference in New Issue
Block a user