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
Bookmarks