DS18B20 and PIC microcontroller communication source program

Publisher:冰心独语uLatest update time:2011-02-24 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
ORG     PIC54
GOTO    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
MOVLW  0FFH
TRIS   RA
LOOP
CALL   CONVERT
CALL   DELAY22
CALL   DELAY22
CALL   GET_TEMP

GOTO   LOOP
;------------------------
GET_TEMP
CALL   INI
MOVLW  0CCH
MOVWF  COMD
CALL   WR1820
MOVLW  0BEH
MOVWF  COMD
CALL   WR1820
CALL   RE1820
MOVF   TEM_DATE,W
MOVWF  TEM_DATEL
CALL   RE1820
MOVF   TEM_DATE,W
MOVWF  TEM_DATEH
RETLW  0
;------------------------
CONVERT
CALL   INI
MOVLW  0CCH
MOVWF  COMD
CALL   WR1820
MOVLW  44H
MOVWF  COMD
CALL   WR1820
RETLW  0

;---------DS1820---------
INI
;MOVLW  B'00100000'
MOVLW  0
TRIS   RA
BSF    RA,3
NOP
BCF    RA,3
MOVLW  D'200'
MOVWF  COUNT1
L0
DECFSZ COUNT1,1
GOTO   L0
;MOVLW  B'01100000'
MOVLW  0FH
TRIS   RA
MOVLW  D'30'
MOVWF  COUNT1
L1
DECFSZ COUNT1,1
GOTO   L1
BTFSC  RA,3
GOTO   INI
L2
MOVLW  D'80'
MOVWF  COUNT1
L3
DECFSZ COUNT1,1
GOTO   L3
BTFSS  RA,3
GOTO   L0
RETLW  0
;-------------------------
WR1820
MOVLW   8
MOVWF   COUNT2
WR0
;MOVLW   B'00100000'
MOVLW   0
TRIS    RA
BCF     RA,3
NOP
NOP
MOVLW   2
MOVWF   COUNT1
WR1
DECFSZ  COUNT1,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
DECFSZ  COUNT1,1
GOTO    WR2
BSF     RA,3
;MOVLW   B'01100000'
MOVLW   0FH
TRIS    RA
DECFSZ  COUNT2,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
DECFSZ  COUNT1,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
DECFSZ  COUNT1,1
GOTO    RE2
DECFSZ  COUNT2,1
GOTO    RE0
BSF     RA,3
RETLW   0
;-------------------------
;****************************
;**************************
END


Reference address:DS18B20 and PIC microcontroller communication source program

Previous article:PIC microcontroller floating point number and its conversion to decimal number
Next article:Set all ports high and low at the same time, and keep flashing

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号