|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
我编了一个SPI总线的程序,两块硬件都是ADUC812
但主机始终无法将数据传送给从机,但从机的数据却可以传送给主机
硬件连接良好,估计是程序问题,我实在找不出错误,请大虾帮我看看,程序很短的
或者能否提供确实能用的程序让我参考一下,谢谢
主机:
$MOD812 ; Use 8052 & ADuC812 predefined symbols
SS EQU P3.5 ; P3.5 drives slave device's SS pin
ORG 0000h
LJMP MAIN ; jump to main program
ORG 003Bh ; (.................... SPI ISR)
SETB SS ; pull slave's SS pin high
MOV A,SPIDAT
CLR C
RETI
;====================================================================
; MAIN PROGRAM
ORG 004Bh
MAIN:
SETB EA
MOV IE2,#01H
MOV SPICON,#30H
MASTER:
JB P3.4,$
CLR SS
NOP
NOP
NOP
NOP
SETB C
MOV SPIDAT,#0AAH
JC $
LJMP MASTER
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DELAY: ; delays approximately 100ms
PUSH ACC
PUSH B
MOV A,#200 ; 200 * 500us = 100ms
DLY1: MOV B,#229 ; 229 * 2.17us = 500us
DJNZ B,$ ; sit here for 500us
DJNZ ACC,DLY1 ; repeat 200 times (100ms delay)
POP B
POP ACC
RET
END
从机:
$MOD812 ; Use 8052 & ADuC812 predefined symbols
SS EQU P3.5 ; P3.5 drives slave device's SS pin
ORG 0000H
LJMP MAIN ; jump to main program
ORG 0013H
CLR SPE
SETB SPE
MOV SPIDAT,#0BBH
SETB P3.2
RETI
ORG 003BH
MOV A,SPIDAT
SETB P3.5
CLR C
RETI
;====================================================================
; MAIN PROGRAM
ORG 004Bh
MAIN:
SETB P3.5
SETB EA
MOV IE2,#01H
SETB EX0
MOV SPICON,#20H
CLR P1.5
SLAVE:
CLR P3.5
JB P1.5,$
CLR P3.2
SETB C
JC $
LJMP SLAVE
; - - - - - - - - - - - - - - -POST http://eetop.cn/cgi-bin/post.cgi HTTP/1.0
P ; delays approximately 100ms
PUSH ACC
PUSH B
MOV A,#200 ; 200 * 500us = 100ms
DLY1: MOV B,#229 ; 229 * 2.17us = 500us
DJNZ B,$ ; sit here for 500us
DJNZ ACC,DLY1 ; repeat 200 times (100ms delay)
POP B
POP ACC
RET
END
|
|