DS18B20和PIC单片机通讯源程序
ORG PIC54GOTO MAIN
ORG 0
;----------------------
;----------------------------
DELAY22
MOVLW D'200' ; DELAY 2*250=500mS
MOVWF COUNT1
DE32 MOVLW D'250' ; 8*250=2mS
MOVWF COUNT2
DE42 NOP ; 1+2+1=5uS
DECFSZ COUNT2,1
GOTO DE42
DECFSZ COUNT1,1
GOTO DE32
RETLW 0
;--------------------------------
; 子程序!!!
;********************************
MAIN
MOVLW0FFH
TRIS RA
LOOP
CALL CONVERT
CALL DELAY22
CALL DELAY22
CALL GET_TEMP
GOTO LOOP
;------------------------
GET_TEMP
CALL INI
MOVLW0CCH
MOVWFCOMD
CALL WR1820
MOVLW0BEH
MOVWFCOMD
CALL WR1820
CALL RE1820
MOVF TEM_DATE,W
MOVWFTEM_DATEL
CALL RE1820
MOVF TEM_DATE,W
MOVWFTEM_DATEH
RETLW0
;------------------------
CONVERT
CALL INI
MOVLW0CCH
MOVWFCOMD
CALL WR1820
MOVLW44H
MOVWFCOMD
CALL WR1820
RETLW0
;---------DS1820---------
INI
;MOVLWB'00100000'
MOVLW0
TRIS RA
BSF RA,3
NOP
BCF RA,3
MOVLWD'200'
MOVWFCOUNT1
L0
DECFSZ COUNT1,1
GOTO L0
;MOVLWB'01100000'
MOVLW0FH
TRIS RA
MOVLWD'30'
MOVWFCOUNT1
L1
DECFSZ COUNT1,1
GOTO L1
BTFSCRA,3
GOTO INI
L2
MOVLWD'80'
MOVWFCOUNT1
L3
DECFSZ COUNT1,1
GOTO L3
BTFSSRA,3
GOTO L0
RETLW0
;-------------------------
WR1820
MOVLW 8
MOVWF COUNT2
WR0
;MOVLW B'00100000'
MOVLW 0
TRIS RA
BCF RA,3
NOP
NOP
MOVLW 2
MOVWF COUNT1
WR1
DECFSZCOUNT1,1
GOTO WR1
;MOVLW B'01111111'
MOVLW 0FH
BTFSC COMD,0
BSF RA,3
BTFSC COMD,0
TRIS RA
BCF STATUS,C
RRF COMD,1
MOVLW D'20'
MOVWF COUNT1
WR2
DECFSZCOUNT1,1
GOTO WR2
BSF RA,3
;MOVLW B'01100000'
MOVLW 0FH
TRIS RA
DECFSZCOUNT2,1
GOTO WR0
RETLW 0
;--------------------------
RE1820
MOVLW 8
MOVWF COUNT2
RE0
;MOVLW B'00100000'
MOVLW 0
TRIS RA
BCF RA,3
MOVLW 2
MOVWF COUNT1
RE1
DECFSZCOUNT1,1
GOTO RE1
;MOVLW B'01100000'
MOVLW 0FH
TRIS RA
NOP
BTFSS RA,3
BCF STATUS,C
BTFSC RA,3
BSF STATUS,C
RRF TEM_DATE,1
MOVLW D'20'
MOVWF COUNT1
RE2
DECFSZCOUNT1,1
GOTO RE2
DECFSZCOUNT2,1
GOTO RE0
BSF RA,3
RETLW 0
;-------------------------
;****************************
;**************************
END
页:
[1]