📄 rxhex.a51
字号:
$NOMOD51
$include (reg1210.inc)
PUBLIC rx_hex_echo, _ascii2bin, rx_hex_word_echo, rx_hex_double_echo
EXTRN code (rx_byte, rx_byte_echo)
RxHex SEGMENT CODE
RSEG RxHex
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Convert R7 from ascii to bin
;Used acc and Cy
_ascii2bin:
mov a,r7
clr c
subb a,#'A' ; -65
jbc cy,a2b_under10
add a,#0ah ; A~F
sjmp a2b_end
a2b_under10:
add a,#17 ;0~9
a2b_end:
mov r7,a
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; unsigned int rx_hex_word_echo(void)
; Receive 4 ascii (/w echo), return bin val in R7:R6
; Warning: R7:R6 convention for stack,
; but wrong for Keil C int
; Used acc, and 2 stack
rx_hex_word_echo:
call rx_hex_double_echo
push reg6
mov reg6,reg7
pop reg7
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; unsigned int rx_hex_word_echo(void)
; Receive 4 ascii (/w echo), return bin val in R6:R7
rx_hex_double_echo:
call rx_hex_echo
mov REG6,REG7
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Receive 2 ascii (/w echo), return bin val in R7
; Used acc, and a stack
rx_hex_echo:
; get hi nibble
call rx_byte_echo ;rx a byte in R7
acall _ascii2bin ;convert R7 to bin
push reg7 ;hi nib in stk
; get lo nibble
call rx_byte_echo ;rx a byte in R7
acall _ascii2bin ;convert R7 to bin
pop acc ;get hi nib from stk
swap a ;position hi nib
orl reg7,a ;combine hinib with low nib
ret
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -