各位此程序仅供产考 有什么不对的地方请高手指教:sht10-spi.
; P1.3 = CS, OUTPUT
; P1.4 = SCK, INPUT
; P1.5 = DAT, INPUT
; P1.6 = Reset, OUTPUT
;
; after call read_mth01, register "flag.0=1 means read data sucessful, =0 means read data error"
;
; cnt_2hz is counter for 0.5s, increment 1 every half sec in interruption subroutine.
;
; fskram is the buffer for data shifted in
read_mth01
and flag,#0feh ; reset ok bit
ld r1,cnt_2hz
ld r0,#32 ; prepare to shift in 4 bytes
and P1,#0f7h ; cs low
rmth00 cp r1,cnt_2hz
jr nz,rmth10
tm P1,#10h ; waite until sclk goes high
jr z,rmth00
scf
tm p1,#20h
jr nz,rmth01
rcf
rmth01 rlc fskram+3 ; read sdat value
rlc fskram+2
rlc fskram+1
rlc fskram
rmth02 cp r1,cnt_2hz
jr nz,rmth10
tm p1,#10h
jr nz,rmth02 ; waite until the clock is low
dec r0
jr nz,rmth00
or flag,#01h ; set ok bit after sucessful received
rmth03 or P1,#08h ; cs high
ret
;
rmth10 and P1,#0bfh ; reset low
ld r1,#30
.extern DelayNN
call DelayNN ; delay 20ms
or P1,#40h
jr rmth03
;
出
;
.end