我用的是STM8S105C6,但是一直复位不了,接收到的一直是FF,希望大家指点一下,小弟感激不尽啊
stm8/
#include "STM8S105C6.INC"
#include "user_register.inc"
#include "mapping.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
MOV R04,#64
CLR R03
CLR R02
;初始化SPI模,配置STM8S的MOSI
BSET PC_DDR,#6
BSET PC_CR1,#6
BSET PC_CR2,#6
BSET PC_ODR,#6
;__________________MISO
BRES PC_DDR,#7
BRES PC_CR1,#7
BRES PC_CR2,#7
;__________________SCK
BSET PC_DDR,#5
BSET PC_CR1,#5
BSET PC_CR2,#5
;_________________主机片选端
BRES PE_DDR,#5
BSET PE_CR1,#5
BRES PE_CR2,#5
BSET PE_ODR,#5
;_________________SD卡的CS端
BSET PD_DDR,#6
BSET PD_CR1,#6
BSET PD_ODR,#6
;初始化SPI_CR1
MOV SPI_CR1,#$16 ;使用默认的2MHSI,波特率用150縆HZ
BSET SPI_CR1,#6 ;使能SPI
RESET.L
INC R03
RESET_NEXT0.L
MOV SPI_DR,#$FF
INC R02
RESET_NEXT1.L
BTJT SPI_SR,#7,RESET_NEXT1
LD A,R02
CP A,#100
JRNE RESET_NEXT0
CLR R02
CMD0.L
BRES PD_ODR,#6 ;拉低SD卡的CS
NOP
NOP
NOP
NOP
MOV SPI_DR,#$40
CMD0_NEXT1.L
BTJT SPI_SR,#7,CMD0_NEXT1
MOV SPI_DR,#$00
CMD0_NEXT2.L
BTJT SPI_SR,#7,CMD0_NEXT2
MOV SPI_DR,#$00
CMD0_NEXT3.L
BTJT SPI_SR,#7,CMD0_NEXT3
MOV SPI_DR,#$00
CMD0_NEXT4.L
BTJT SPI_SR,#7,CMD0_NEXT4
MOV SPI_DR,#$00
CMD0_NEXT5.L
BTJT SPI_SR,#7,CMD0_NEXT5
MOV SPI_DR,#$95
CMD0_NEXT6.L
BTJT SPI_SR,#7,CMD0_NEXT6
CMD0_NEXT7.L
DEC R04
JRNE CMD0_NEXT7
MOV R04,#64
YANZHENG.L
MOV R06,SPI_DR
INC R05
LD A,R06
CP A,#$01
JREQ YANZHENG1
LD A,R05
CP A,#25
JRNE YANZHENG
CLR R05
BSET PD_ODR,#6
JPF RESET
YANZHENG1.L
BSET PD_ODR,#6
MOV SPI_DR,#$FF
LOOP.L
JPF LOOP
interrupt NonHandledInterrupt
NonHandledInterrupt.l
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+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+SPI} ; 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
|
|