📄 main.asm
字号:
stm8/
#include "mapping.inc"
#include "STM8S105C_S.inc"
segment 'ram0'
couter ds.b 1
vol1 ds.b 1
vol2 ds.b 1
vol3 ds.b 1
voltage ds.b 1
r00 ds.b 1
r01 ds.b 1
r02 ds.b 1
r03 ds.b 1
r04 ds.b 1
r05 ds.b 1
segment 'rom'
main.l
; initialize SP
ldw X,#stack_end
ldw SP,X
#ifdef RAM0
; clear RAM0
ram0_start.b EQU $ram0_segment_start
ram0_end.b EQU $ram0_segment_end
ldw X,#ram0_start
clear_ram0.l
clr (X)
incw X
cpw X,#ram0_end
jrule clear_ram0
#endif
#ifdef RAM1
; clear RAM1
ram1_start.w EQU $ram1_segment_start
ram1_end.w EQU $ram1_segment_end
ldw X,#ram1_start
clear_ram1.l
clr (X)
incw X
cpw X,#ram1_end
jrule clear_ram1
#endif
; clear stack
stack_start.w EQU $stack_segment_start
stack_end.w EQU $stack_segment_end
ldw X,#stack_start
clear_stack.l
clr (X)
incw X
cpw X,#stack_end
jrule clear_stack
intel
mov UART2_CR1,#0
mov UART2_CR2,#0
mov UART2_CR3,#0
mov UART2_BRR2,#0
mov UART2_BRR1,#0dh
mov UART2_CR2,#0ch
mov ADC_CR2,#0 ; A/D结果数据左对齐
mov ADC_CR1,0 ; ADC时钟=主时钟/2=1MHZ
; ADC转换模式=单次
; 禁止ADC转换
mov ADC_CSR,#8 ; 选择通道8
mov ADC_TDRH,#1
bset ADC_CR1,#0
ld a,#100
WAIT_ADC_ON.L
dec a
jrne WAIT_ADC_ON ; 延时一段时间,至少7uS,保证ADC模块的上电完成
main_loop:
bset ADC_CR1,#0
WAIT_ADC_EOC.L
ld a,ADC_CSR
and a,#80h
jreq WAIT_ADC_EOC ; 等待ADC结束
ld a,ADC_DRH ; 读出ADC结果的高8位
ld voltage,a
clrw x
mov r01 ,#00h
mov r02 ,#7dh
ld r00,a
ld a,r02
ld xl,a
ld a,r00
mul x,a
ldw r04 ,x
ld a,r01
ld xl,a
ld a,r00
mul x,a
addw x,r03
ldw r03,x
ldw x,r04
mov couter,#6
adc_div:
srlw x
dec couter
jrne adc_div
ld a,#10
div x,a
ld vol1,a
ld a,#10
div x,a
ld vol2,a
ld a,#10
div x,a
ld vol3,a
ld a,vol3
add a,#30h
call send_char
call delay
ld a,vol2
add a,#30h
call send_char
call delay
ld a,vol1
add a,#30h
call send_char
call delay
ld a,#20h
call send_char
ld a,voltage
call send_char
ld a,#20h
call send_char
jp main_loop
send_char:
here
btjf UART2_SR,#7,here
ld UART2_DR,a
ret
receive_char:
here1
btjf UART2_SR,#5,here1
ld a,UART2_DR
ret
LED_TAB: ;八段共阳数码管字模
; 0 1 2 3 4 5 6 7 8 9
dc.b 0c0h,0f9h,0a4h,0b0h,99h,92h,83h,0f8h,80h,98h
interrupt NonHandledInterrupt
NonHandledInterrupt.l
iret
delay:
ldw y,#02fh
loop2:
ldw x,#0fffh
loop1:
decw x
jrne loop1
decw y
jrne loop2
ret
motorola
segment 'vectit'
dc.l {$82000000+main} ; reset
dc.l {$82000000+NonHandledInterrupt} ; trap
dc.l {$82000000+NonHandledInterrupt} ; irq0
dc.l {$82000000+NonHandledInterrupt} ; irq1
dc.l {$82000000+NonHandledInterrupt} ; irq2
dc.l {$82000000+NonHandledInterrupt} ; irq3
dc.l {$82000000+NonHandledInterrupt} ; irq4
dc.l {$82000000+NonHandledInterrupt} ; irq5
dc.l {$82000000+NonHandledInterrupt} ; irq6
dc.l {$82000000+NonHandledInterrupt} ; irq7
dc.l {$82000000+NonHandledInterrupt} ; irq8
dc.l {$82000000+NonHandledInterrupt} ; irq9
dc.l {$82000000+NonHandledInterrupt} ; irq10
dc.l {$82000000+NonHandledInterrupt} ; irq11
dc.l {$82000000+NonHandledInterrupt} ; irq12
dc.l {$82000000+NonHandledInterrupt} ; irq13
dc.l {$82000000+NonHandledInterrupt} ; irq14
dc.l {$82000000+NonHandledInterrupt} ; irq15
dc.l {$82000000+NonHandledInterrupt} ; irq16
dc.l {$82000000+NonHandledInterrupt} ; irq17
dc.l {$82000000+NonHandledInterrupt} ; irq18
dc.l {$82000000+NonHandledInterrupt} ; irq19
dc.l {$82000000+NonHandledInterrupt} ; irq20
dc.l {$82000000+NonHandledInterrupt} ; irq21
dc.l {$82000000+NonHandledInterrupt} ; irq22
dc.l {$82000000+NonHandledInterrupt} ; irq23
dc.l {$82000000+NonHandledInterrupt} ; irq24
dc.l {$82000000+NonHandledInterrupt} ; irq25
dc.l {$82000000+NonHandledInterrupt} ; irq26
dc.l {$82000000+NonHandledInterrupt} ; irq27
dc.l {$82000000+NonHandledInterrupt} ; irq28
dc.l {$82000000+NonHandledInterrupt} ; irq29
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -