12F508 and Dallas 1820 not working


Results 1 to 14 of 14

Threaded View

  1. #11
    Join Date
    Feb 2012
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: 12F508 and Dallas 1820 not working

    Oh sh*t!!!

    I had forgotten to connect a pull-up resistor to data pin, and that was the reason for non workin code. I am sorry, that I have caused trouble. The following works. Data pin is now back to GP1 (GPIO.1)



    Code:
    '****************************************************************
    '*  Name    : 12F508thermostat.BAS                                          *
    '*  Author  : AN OLD FINNISHMAN                    *
    '*  Notice  :                                    *
    '*            :                                 *
    '*  Date    : 02/12/2012                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                    *
    '*          :                                                   *
    '****************************************************************
    
    ' CHIP: PIC 12F508
    ' A simple program to read DS1820 (18S20) and depending on the temperature
    ' to drive a led (and/or a solit state relay to drive an 
    ' electric heater).
    ' ID for the sensor and a CRC value is here:
    ' $10,$B2,$AD,$D8,$00,$08,$00,$26
    ' replace it with yours
    ' USE INTERNAL OSCILLATOR (INTRC) 
    
    ' connect a led via 470 ohm resistor to GP0
    ' connect a 4k7 pull-up resistor to data pin GP1
    
    
    Define osc 4
    
    led var GPIO.0
    
    
    Tempa Var Word            ' Temperature storage
    Stat var bit
    
    DQ    Var    GPIO.1            ' One-wire data pin
    
    TRISIO =000010
    GPIO =000000
    
    'led on for a second to see if code runnig
    
            High led 
            PAUSE 1000
            low led
    
    pauseus 100
    
    Temp_1:
        
        OWOUT DQ, 1, [$55,$10,$B2,$AD,$D8,$00,$08,$00,$26,$44]
    W1:
        OWIN DQ, 4, [Stat]' Check for still busy converting
        IF Stat = 0 THEN W1' Still busy?, then loop
        OWOUT DQ, 1,[$55,$10,$B2,$AD,$D8,$00,$08,$00,$26,$BE]
        OWIN DQ, 2, [Tempa.LOWbyte,Tempa.HIGHBYTE]' Read two bytes, then end communications
        
    ' replace upper and lower limits with your own
    ' variable Tempa is 2 times the temperature in degrees C
        
    If Tempa >= 41 then low led ' if temp >= 20,5 (upper limit)
    If Tempa <= 40 then High led ' if temp <= 20 (lower limit)
    
    PAUSE 1000
    
    Goto Temp_1
    Last edited by Picprogman; - 10th February 2012 at 17:18.

Members who have read this thread : 0

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