ds18b20 pic54單片機(jī)通訊源程序
ds18b20 pIC54單片機(jī)通訊源程序
ORG PIC54
GOTO MAIN
ORG 0
;----------------------
;----------------------------
DELAY22
MOV LW D'200' ; DELAY 2*250=500mS
MOV WF COUNT1
DE32 MOV LW D'250' ; 8*250=2mS
MOV WF COUNT2
DE42 NOP ; 1+2+1=5uS
DECFSZ COUNT2,1
GOTO DE42
DECFSZ COUNT1,1
GOTO DE32
RETLW 0
;--------------------------------
; 子程序!!!
;********************************
MAIN
MOV LW 0FFH
TRIS RA
LOOP
CALL CONVERT
CALL DELAY22
CALL DELAY22
CALL GET_TEMP
GOTO LOOP
;------------------------
GET_TEMP
CALL INI
MOV LW 0CCH
MOV WF COMD
CALL WR1820
MOV LW 0BEH
MOV WF COMD
CALL WR1820
CALL RE1820
MOV F TEM_DATE,W
MOV WF TEM_DATEL
CALL RE1820
MOV F TEM_DATE,W
MOV WF TEM_DATEH
RETLW 0
;------------------------
CONVERT
CALL INI
MOV LW 0CCH
MOV WF COMD
CALL WR1820
MOV LW 44H
MOV WF COMD
CALL WR1820
RETLW 0
;---------DS1820---------
INI
; MOV LW B'00100000'
MOV LW 0
TRIS RA
BSF RA,3
NOP
BCF RA,3
MOV LW D'200'
MOV WF COUNT1
L0
DECFSZ COUNT1,1
GOTO L0
; MOV LW B'01100000'
MOV LW 0FH
TRIS RA
MOV LW D'30'
MOV WF COUNT1
L1
DECFSZ COUNT1,1
GOTO L1
BTFSC RA,3
GOTO INI
L2
MOV LW D'80'
MOV WF COUNT1
L3
DECFSZ COUNT1,1
GOTO L3
BTFSS RA,3
GOTO L0
RETLW 0
;-------------------------
WR1820
MOV LW 8
MOV WF COUNT2
WR0
; MOV LW B'00100000'
MOV LW 0
TRIS RA
BCF RA,3
NOP
NOP
MOV LW 2
MOV WF COUNT1
WR1
DECFSZ COUNT1,1
GOTO WR1
; MOV LW B'01111111'
MOV LW 0FH
BTFSC COMD,0
BSF RA,3
BTFSC COMD,0
TRIS RA
BCF STATUS,C
RRF COMD,1
MOV LW D'20'
MOV WF COUNT1
WR2
DECFSZ COUNT1,1
GOTO WR2
BSF RA,3
; MOV LW B'01100000'
MOV LW 0FH
TRIS RA
DECFSZ COUNT2,1
GOTO WR0
RETLW 0
;--------------------------
RE1820
MOV LW 8
MOV WF COUNT2
RE0
; MOV LW B'00100000'
MOV LW 0
TRIS RA
BCF RA,3
MOV LW 2
MOV WF COUNT1
RE1
DECFSZ COUNT1,1
GOTO RE1
; MOV LW B'01100000'
MOV LW 0FH
TRIS RA
NOP
BTFSS RA,3
BCF STATUS,C
BTFSC RA,3
BSF STATUS,C
RRF TEM_DATE,1
MOV LW D'20'
MOV WF COUNT1
RE2
DECFSZ COUNT1,1
GOTO RE2
DECFSZ COUNT2,1
GOTO RE0
BSF RA,3
RETLW 0
;-------------------------
;****************************
;**************************
END