⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.asm

📁 STM8S实验 ASM源程序
💻 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
	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
;初始化PB,推挽输出,用于数码管段驱动;
  mov PB_DDR,#0ffh
	mov PB_CR1,#0ffh
	mov PB_CR2,#0
;初始化PA,推挽输出,用于数码管位驱动;	
  mov PA_DDR,#0ffh
	mov PA_CR1,#0ffh
	mov PA_CR2,#0
	mov PA_ODR,#0ffh	


  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             ; 选择通道0

  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位
  ldw     x,#500
	mul     x,a

  mov couter,#8 
adc_div:
  sraw    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
 
  ldw x,#0

  ldw x,vol1
	ld a,(LED_TAB,x)
	call send_char
	ld PB_ODR,a 
	call send_char
  mov PA_ODR,#11110111b
	call delay
  mov PA_ODR,#0ffh	
	
  ldw x,#vol2
	ld a,(LED_TAB,x)
	ld  PB_ODR,a
	call send_char
  mov PA_ODR,#11101111b
	call delay 
  mov PA_ODR,#0ffh	
	
  ldw x,#vol3
	ld a,(LED_TAB,x)
	ld  PB_ODR,a
  call send_char	
  mov PA_ODR,#11011111b
 	call delay 
  mov PA_ODR,#0ffh	


	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,#00ffh
loop1:
  decw y
	jrne loop1
  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 + -