📄 main.asm
字号:
stm8/
#include "mapping.inc"
#include "STM8S105C_S.inc"
;/******************** stm8单片机实验 ********************
;文件名 : 修改时钟源
;描述 : 修改stm8的时钟源为外部时钟 ,观察LD1灯的变化情况
;*********************************************************
;***************************接线**************************
;硬件:1、STM8s-discovery LED1
.FORM 72
lab equ 2
lab1 equ 3
segment word 'rom'
main.l
; initialize SP
ld a,#{lab mult lab1}
%OUT hello!
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
;系统复位后,时钟为内部RC振荡器,16Mhz,8分频,实为2Mhz.
;LD1闪烁10次
ld a,#10 ;10次
bset PD_DDR,#0
bset PD_CR1,#0
bres PD_CR2,#0
next1
bres PD_ODR,#0
call delay
bset PD_ODR,#0
call delay
dec a
jrne next1
;修改时钟为外部16Mhz时钟.
;LD1闪烁10次
mov CLK_ECKR,#01h ; 允许外部高速振荡器工作
wait_hse_ready
ld a,CLK_ECKR
and a,#02h
jreq wait_hse_ready ; 等待外部高速振荡器准备好
bset CLK_CSSR,#0 ;CSEEN<-1,时钟安全系统使能
mov CLK_SWCR,#02h ; SWEN <- 1
mov CLK_SWR,#0b4h ; 选择芯片外部的高速振荡器为主时钟
wait_clk_switch
ld a,CLK_SWCR
and a,#08h
jreq wait_clk_switch ; 等待切换成功
next2
bres PD_ODR,#0
call delay
bset PD_ODR,#0
call delay
dec a
jrne next2
jra $ ;
delay
push cc
ldw y,#10
loop1 ldw x,#0ffffh
loop decw x
jrne loop
decw y
jrne loop1
pop cc
ret
interrupt NonHandledInterrupt
NonHandledInterrupt.l
iret
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 + -