📄 menuuart.asm
字号:
;==========================================================
; This is a part of: Eversmith - AVRSMS
; Copyright (2003) Martin Thomas, Kaiserslautern, Germany.
; This Software is distributed under the Aladdin Free
; Public License (AFPL) Read the file license.txt included
; in the distibution-package. See main-file for more infor-
; mation and license.
;==========================================================
;----------------------------------------------------------
; subroutines Menu and "STDIO" via UART
;----------------------------------------------------------
; Menu is handled via UART2 (2nd UART TODO)
.CSEG
;----------------------------------------------------------
; MenuUartGetByte - Reads a byte (key) from UART (console)
;----------------------------------------------------------
;
; Inputs:
; none
;
; Ouputs:
; r17 - Byte read
;
MenuUartGetByte:
push r18
ldi r18,$00 ; no timout
call Uart2ReadByteFIFO ; read byte in r17
pop r18
ret
;----------------------------------------------------------
; MenuUartSendByte - Sends a byte to UART (console)
;----------------------------------------------------------
;
; Inputs:
; r17 - Byte to send
;
; Ouputs:
; none
;
MenuUartSendByte:
push r16
mov r16,r17
call UART2SendByte ; send byte in r16
pop r16
ret
;----------------------------------------------------------
; MenuUartSendFlashSeq - Sends Null-Terminated Sequence
; from FLASH to UART
;----------------------------------------------------------
;
; Inputs:
; Z-Register: Pointer to Sequence in FLASH
;
MenuUartSendFlashSeq:
push r0
push r17
push ZL
push ZH
MenuUartSendFlashSeq_L1:
; lpm r17, Z+ ; is not supported in AVR 90S8515 so:
lpm ; defaults to lpm r0
mov r17,r0
tst r17 ; test for Null
breq MenuUartSendFlashSeq_End
rcall MenuUartSendByte
adiw ZH:ZL,$01 ; to be removed if lpm rXX,Z+ supported
rjmp MenuUartSendFlashSeq_L1
MenuUartSendFlashSeq_End:
pop ZH
pop ZL
pop r17
pop r0
ret
;----------------------------------------------------------
; MenuUart - Shows Menu from FLASH and returns
; selection (0-9)
;----------------------------------------------------------
;
; Inputs:
; Z-Register = Pointer to Menu in FLASH (Null-terminated)
;
; Ouputs:
; r17 - selection (ASCII '0'-'9')
;
MenuUart:
push ZL
push ZH
rcall MenuUartSendFlashSeq
MenuUart_L1:
rcall MenuUartGetByte
cpi r17,'0'
brlo MenuUart_L1
cpi r17,'9'+1
brsh MenuUart_L1
cpi r17,'0'
brne MenuUart_L2
ldi ZL,LOW(2*MUEXITMSG)
ldi ZH,HIGH(2*MUEXITMSG)
rcall MenuUartSendFlashSeq
MenuUart_L2:
pop ZH
pop ZL
ret
MUEXITMSG:
.db "Exiting Menue... ",$0D,$0A,$00
;----------------------------------------------------------
; MenuUartInputToRam - read a string from UART to SRAM
;----------------------------------------------------------
;
; Input:
; Y-Register = Pointer to SRAM (Size r19+1 for terminating Null)
; r19 = number of characters to read
;
; Output
; Sting in SRAM at Postion of Y-Register
;
MenuUartInputToRam:
push r17 ; char read
push r18 ; counter
push YL
push YH
clr r18
RSUTR_L1:
rcall MenuUartGetByte
cpi r17,$0D ; test for "Return"
breq RSUTR_END
cpi r17,$08 ; test for Backspace
breq RSUTR_DEL
cp r18,r19 ; test for maximum size
brsh RSUTR_L1
rcall MenuUartSendByte
st Y+,r17
inc r18
rjmp RSUTR_L1
RSUTR_DEL:
tst r18
breq RSUTR_L1
rcall MenuUartSendByte ; send the backspace
ldi r17,$20
rcall MenuUartSendByte ; send a blank
ldi r17,$08
rcall MenuUartSendByte ; send another backspace
clr r17
st -Y,r17
dec r18
rjmp RSUTR_L1
RSUTR_END:
ldi r17,0 ; store termination
st Y,r17
pop YH
pop YL
pop r18
pop r17
ret
;----------------------------------------------------------
; MenuUartInputToRamPrompt - Prompts a message from FLASH
; and reads a string from UART to SRAM
;----------------------------------------------------------
;
; Input:
; Z-Register = Pointer to prompt in FLASH (Null-terminated)
; Y-Register = Pointer to SRAM (Size r19+1 for terminating Null)
; r19 = number of chars to read
;
; Output
; Sting in SRAM at Postion of Y-Register
;
MenuUartInputToRamPrompt:
rcall MenuUartSendFlashSeq
rcall MenuUartInputToRam
ret
;----------------------------------------------------------
; MenuUartSendRamSeq - Sends Null-Terminated Sequence
; from SRAM to UART
;----------------------------------------------------------
;
; Inputs:
; Y-Register: Pointer to Sequence in FLASH
;
MenuUartSendRamSeq:
push r17
push YL
push YH
MenuUartSendRamSeq_L1:
ld r17,Y+
tst r17 ; test for Null
breq MenuUartSendRamSeq_End
rcall MenuUartSendByte
rjmp MenuUartSendRamSeq_L1
MenuUartSendRamSeq_End:
pop YH
pop YL
pop r17
ret
;----------------------------------------------------------
; MenuUartSendEepromSeq - Sends Null-Terminated Sequence
; from EEPROM to UART
;----------------------------------------------------------
; depends on EEReadPlus from eeprom.asm
;
; Inputs:
; r24 = Address in EEPROM low (Data null terminated)
; r25 = Address in EEPROM high
;
; Outputs:
; none
;
; Side-effects:
; implicit from EEReadPlus
; TODO: check side-effect - remove
MenuUartSendEepromSeq:
push r16
push r17
MenuUartSendEepromSeq_L1:
rcall EEReadPlus
cpi r16,$FF ; inital empty protection
brne MenuUartSendEepromSeq_L2
ldi r16,$00
MenuUartSendEepromSeq_L2:
tst r16
breq MenuUartSendEepromSeq_End
mov r17,r16
rcall MenuUartSendByte
rjmp MenuUartSendEepromSeq_L1
MenuUartSendEepromSeq_End:
pop r17
pop r16
ret
;----------------------------------------------------------
; MenuUartSendCRLF - Sends CR and LF to UART
;----------------------------------------------------------
MenuUartSendCRLF:
push r17
ldi r17,$0D
rcall MenuUartSendByte ; send CR
ldi r17,$0A
rcall MenuUartSendByte ; send LF
pop r17
ret
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -