stm8汇编实现“门铃”,按一下按钮C2,蜂鸣器响一秒

stm8/

	#include "mapping.inc"
  #include "stm8s105k.inc"
	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
  
	;output port_d
	mov PD_DDR, #$ff
  mov PD_CR1, #$ff
  mov PD_ODR, #$00
	
	;input PORT_C
	;input floating with interrupt
  mov PC_DDR,#$00
	mov PC_CR1,#$00
	mov PC_CR2,#$ff
	
	;interrupt sensitivity
	mov EXTI_CR1,#$20 ;falling edge
	
	;configure timer2 --PWM
  MOV TIM2_CR1,#%00000000 ;counter enable OFF
	MOV TIM2_IER,#$00       ;no interrupts
	MOV TIM2_CCMR1,#%01100000  ;PWM mode1+CC1  as output
	MOV TIM2_CCER1,#$00000001  
	;enable CC1 output directly connected to PD4
	;the frequency 1kHz 
	ldw x, #$07D0
	ld a ,xh
	ld TIM2_ARRH,a
	ld a ,xl
	ld TIM2_ARRL,a
	;the dutycycle 50%
	ldw x, #$03E8
	ld a,xh
	ld TIM2_CCR1H,a
	ld a,xl
	ld TIM2_CCR1L,a
	
	;config tim3 for 1 second
	mov TIM3_CR1,#%00000000  ;tim3 off
	mov TIM3_PSCR,#$07   ;prescaler x128
	bset TIM3_EGR,#0   ;force uev to update prescaler
	mov TIM3_IER, #$01   ;TIM3 interrupt on update enabled
	
	;config TIM3
	MOV TIM3_ARRH,#%00111101 ;15625HZ 1s
	MOV TIM3_ARRL, #%00001001
	
	RIM
infinite_loop.l
  ld a,#$01  ;empty operation
	jra infinite_loop

	interrupt NonHandledInterrupt
NonHandledInterrupt.l
	iret

  interrupt sound
sound
	MOV TIM2_CR1,#%00000001 ;enable tim2
	MOV TIM3_CR1,#%00000001 ;enable tim3
  iret
	
	interrupt timer
timer
  MOV TIM2_CR1,#%00000000  ;disable tim2
	MOV TIM3_CR1,#%00000000   ;disable tim3
	BRES TIM3_SR1,#0 ;clear flag
	iret
	
	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+sound}	; 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+timer}	; 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

微暗之火大火!!!!!!!!!!!!

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值