t03: added debug code.
This commit is contained in:
@@ -245,3 +245,97 @@ debugWriteString_done:
|
|||||||
debugString: .db "Hello", 13, 10, 0
|
debugString: .db "Hello", 13, 10, 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
debugPrintLoop:
|
||||||
|
sbi LED_PORT, LED_PINNUM ; off
|
||||||
|
; enable transceiver
|
||||||
|
lds r17, UCSR1B
|
||||||
|
; cbr r17, (1<<UDRIE1) ; disable DRE interrupt
|
||||||
|
ori r17, (1<<RXEN1) | (1<<TXEN1) ; enable transmit and receive
|
||||||
|
sts UCSR1B, r17
|
||||||
|
|
||||||
|
debugPrintLoop1:
|
||||||
|
push r16
|
||||||
|
rcall debugPrintHexByte
|
||||||
|
ldi r16, 13
|
||||||
|
rcall debugPrintOneChar ; (r17)
|
||||||
|
ldi r16, 10
|
||||||
|
rcall debugPrintOneChar ; (r17)
|
||||||
|
ldi r16, 10
|
||||||
|
rcall flashWaitForMulti100ms
|
||||||
|
pop r16
|
||||||
|
rjmp debugPrintLoop1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine debugPrintHexByte
|
||||||
|
;
|
||||||
|
; Convert a give byte into HEX and write it to USART1.
|
||||||
|
;
|
||||||
|
; @return CFLAG set if okay, cleared on error
|
||||||
|
; @param R16 byte to convert to print
|
||||||
|
; @clobbers r16, r20 (r17)
|
||||||
|
|
||||||
|
debugPrintHexByte:
|
||||||
|
mov r20, r16
|
||||||
|
swap r16
|
||||||
|
rcall debugNibbleToAscii ; write high nibble (r17)
|
||||||
|
rcall debugPrintOneChar ; (r17)
|
||||||
|
brcc debugPrintHexByte_error
|
||||||
|
mov r16, r20
|
||||||
|
rcall debugNibbleToAscii ; write low nibble (r17)
|
||||||
|
rcall debugPrintOneChar ; (r17)
|
||||||
|
brcc debugPrintHexByte_error
|
||||||
|
sec
|
||||||
|
ret
|
||||||
|
debugPrintHexByte_error:
|
||||||
|
clc
|
||||||
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine debugNibbleToAscii
|
||||||
|
;
|
||||||
|
; Convert a nibble to an ASCII char.
|
||||||
|
; @return R16 ASCII representation of that nibble (e.g. '0' for 0)
|
||||||
|
; @param R16 byte (in bits 0-3)
|
||||||
|
; @clobbers r17
|
||||||
|
|
||||||
|
debugNibbleToAscii:
|
||||||
|
andi r16, 0xf
|
||||||
|
cpi r16, 10
|
||||||
|
brcs debugNibbleToAscii_l1
|
||||||
|
ldi r17, 7
|
||||||
|
add r16, r17
|
||||||
|
debugNibbleToAscii_l1:
|
||||||
|
ldi r17, '0'
|
||||||
|
add r16, r17
|
||||||
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine debugPrintOneChar
|
||||||
|
;
|
||||||
|
; Write one byte to UART1.
|
||||||
|
; @param R16 byte to send
|
||||||
|
; @clobbers r17
|
||||||
|
|
||||||
|
debugPrintOneChar:
|
||||||
|
lds r17, UCSR1A
|
||||||
|
sbrs r17, UDRE1
|
||||||
|
rjmp debugPrintOneChar
|
||||||
|
sbr r17, (1<<TXC1)
|
||||||
|
sts UCSR1A, r17
|
||||||
|
sts UDR1, r16
|
||||||
|
sec
|
||||||
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user