+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    slash819's Avatar
    slash819 Guest

    Default PIC 12F683 and DS18B20 problem

    Hi everyone,

    I'm trying to obtain the temperature using four DS18B20s and transfer the result to my PC using serial port. My code is below, but I couldn't obtain the result I wanted, when I simulated using Proteus. I used SEROUT command instead of HSEROUT, because this PIC model doesn't have built in USART. Maybe I did a mistake using this command. I'd be glad, if you can help. (BTW i'm using MicroCode studio and MPASM).

    Code :

    '************************************************* ***************
    '* Name : UNTITLED.BAS *
    '* Author : [select VIEW...EDITOR OPTIONS] *
    '* Notice : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 27.02.2012 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    @ __CONFIG _WDT_OFF & _MCLRE_ON & _CP_OFF & _PWRTE_ON & _CPD_OFF & _BOD_OFF & _FCMEN_ON & _IESO_OFF & _INTRC_OSC_NOCLKOUT


    OSCCON = %01100001
    DEFINE XTAL = 4


    PortA=0




    Busy VAR BIT
    HAM VAR WORD
    HEAT VAR WORD
    FLOAT VAR WORD
    SIGN_BIT VAR HAM.Bit11
    NEG_HEAT CON 1
    DEGREE CON 223
    SIGN VAR BYTE
    TEMP VAR BYTE
    COMM_PIN VAR PORTA.0
    COMM_PIN1 VAR PORTA.1
    COMM_PIN2 VAR PORTA.2
    COMM_PIN3 VAR PORTA.3
    CLEAR


    START:
    GOSUB READSENSOR
    GOSUB READSENSOR1
    GOSUB READSENSOR2
    GOSUB READSENSOR3
    GOTO START


    READSENSOR:
    OWOUT Comm_Pin,1,[$CC,$44]


    WAT :
    OWIN COMM_PIN,4,[Busy]
    IF Busy=0 THEN WAT
    OWOUT COMM_PIN,1,[$CC,$BE]
    OWIN COMM_PIN,2,[HAM.Lowbyte,ham.highbyte]
    GOSUB CALC
    RETURN


    CALC:
    SIGN = "+"
    IF SIGN_BIT = NEG_HEAT THEN
    SIGN = "-"
    TEMP = ($FFFF - HAM + 1)*625
    HEAT = DIV32 10
    GOTO SUB
    ENDIF
    TEMP = 625*HAM
    HEAT = DIV32 10


    SUB:
    FLOAT = (HEAT//1000)/100
    HEAT = (HEAT/1000)


    SEROUT PORTA.0,2,[HEAT,10]
    RETURN


    Hi, we are pleased to see that you are using our forum.

    We'd like you to become a member of our community. Membership is FREE, please REGISTER and view our forums without these annoying reminders!

    Once registered you may post on the forums, download from the file areas and use the WIKI without interruption.







    READSENSOR1:
    OWOUT Comm_Pin1,1,[$CC,$44]


    WAT1 :
    OWIN COMM_PIN1,4,[Busy]
    IF Busy=0 THEN WAT1
    OWOUT COMM_PIN1,1,[$CC,$BE]
    OWIN COMM_PIN1,2,[HAM.Lowbyte,ham.highbyte]
    GOSUB CALC1
    RETURN


    CALC1:
    SIGN = "+"
    IF SIGN_BIT = NEG_HEAT THEN
    SIGN = "-"
    TEMP = ($FFFF - HAM + 1)*625
    HEAT = DIV32 10
    GOTO SUB1
    ENDIF
    TEMP = 625*HAM
    HEAT = DIV32 10


    SUB1:
    FLOAT = (HEAT//1000)/100
    HEAT = (HEAT/1000)


    SEROUT PORTA.1,2,[hEAT,10]
    RETURN


    READSENSOR2:
    OWOUT Comm_Pin2,1,[$CC,$44]


    WAT2 :
    OWIN COMM_PIN2,4,[Busy]
    IF Busy=0 THEN WAT2
    OWOUT COMM_PIN2,1,[$CC,$BE]
    OWIN COMM_PIN2,2,[HAM.Lowbyte,ham.highbyte]
    GOSUB CALC2
    RETURN


    CALC2:
    SIGN = "+"
    IF SIGN_BIT = NEG_HEAT THEN
    SIGN = "-"
    TEMP = ($FFFF - HAM + 1)*625
    HEAT = DIV32 10
    GOTO SUB2
    ENDIF
    TEMP = 625*HAM
    HEAT = DIV32 10


    SUB2:
    FLOAT = (HEAT//1000)/100
    HEAT = (HEAT/1000)


    SEROUT PORTA.2,2,[HEAT,10]
    RETURN


    READSENSOR3:
    OWOUT Comm_Pin3,1,[$CC,$44]


    WAT3 :
    OWIN COMM_PIN3,4,[Busy]
    IF Busy=0 THEN WAT3
    OWOUT COMM_PIN3,1,[$CC,$BE]
    OWIN COMM_PIN3,2,[HAM.Lowbyte,ham.highbyte]
    GOSUB CALC3
    RETURN


    CALC3:
    SIGN = "+"
    IF SIGN_BIT = NEG_HEAT THEN
    SIGN = "-"
    TEMP = ($FFFF - HAM + 1)*625
    HEAT = DIV32 10
    GOTO SUB3
    ENDIF
    TEMP = 625*HAM
    HEAT = DIV32 10


    SUB3:
    FLOAT = (HEAT//1000)/100
    HEAT = (HEAT/1000)


    SEROUT PORTA.3,2,[HEAT,10]
    RETURN
    END

  2. #2
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    289

    Default Re: PIC 12F683 and DS18B20 problem

    This might help you... there is an article in the "wiki" section under "projects" "temperature" that shows how to read multiple ds18B20's...

    http://www.picbasic.co.uk/forum/cont...r-nine-of-them
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts