codes here with english descriptions
'****************************************************************
'* Name : DS1820'li oda termometresi.BAS *
'* Author : ERHAN YILMAZ *
'* Notice : *
'* : All Rights Reserved *
'* Date : 13.05.2009 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
' Picbasic Pro program to read DS1820 1-wire temperature sensor
' and display temperature on LCD
@ DEVICE PIC16F84A
@ DEVICE PIC16F84A,XT_OSC
@ DEVICE PIC16F84A, WDT_OFF
@ DEVICE PIC16F84A, PWRT_ON
@ DEVICE PIC16F84A, PROTECT_OFF
define OSC 4
Define LCD_DREG PORTB
Define LCD_DBIT 4
Define LCD_RSREG PORTB
Define LCD_RSBIT 0
Define LCD_EREG PORTB
Define LCD_EBIT 1
LCDOUT $FE,$40,12,18,18,12,0,0,0,0 'degree sign
LCDOUT $FE,$48,4,14,4,4,4,4,14,0 'İ character
' Allocate variables
komut var byte ' Storage for command
i var byte ' Storage for loop counter
temp var word '' Storage for temperature
DQ var PORTB.2' Alias DS1820 data pin
DQ_DIR var TRISB.2' Alias DS1820 data direction pin
;Lcdout $fe, 1, "ROOM THERMOMETER"' english
Lcdout $fe, 1, "ODA TERMOMETRES",1' Turkish
'Mainloop to read the temperature and display on LCD
basla:
Gosub init1820 ' init the DS1820
komut = $cc ' Issue Skip ROM command
Gosub DS1820_yaz
komut = $44 ' Start temperature conversion
Gosub DS1820_yaz
Gosub init1820 ' Do another init
komut = $cc ' Issue Skip ROM command
Gosub DS1820_yaz
komut = $be ' Read the temperature
Gosub DS1820_yaz
Gosub DS1820_oku
' Display the decimal temperature
Lcdout $FE,$C0,"SICAKLIK=",dec(temp >> 1),".",dec(temp.0 * 5),0," "
Goto basla
' Initialize DS1820 and check for presence
init1820:
Low DQ ' Set the data pin low to init
Pauseus 500 ' Wait > 480us
DQ_DIR = 1 ' Release data pin (set to input for high)
Pauseus 100 ' Wait > 60us
If DQ = 1 Then
'Lcdout $FE,$C0, "DS1820 not present"'english
Lcdout $FE,$C0, " DS1820 YOK "'Turkish
Pause 500
Goto basla ' Try again
Endif
Pauseus 400 ' Wait for end of presence pulse
Return
' Write "command" byte to the DS1820
DS1820_yaz:
For i = 1 to 8 ' 8 bits to a byte
If komut.0 = 0 Then
Gosub sifir_yaz ' Write a 0 bit
Else
Gosub bir_yaz ' Write a 1 bit
Endif
komut = komut >> 1 ' Shift to next bit
Next i
Return
'Write a 0 bit to the DS1820
sifir_yaz:
Low DQ
Pauseus 60 ' Low for > 60us for 0
DQ_DIR = 1 ' Release data pin (set to input for high)
Return
'Write a 1 bit to the DS1820
bir_yaz:
Low DQ ' Low for < 15us for 1
@ nop ' Delay 1us at 4MHz
DQ_DIR = 1 ' Release data pin (set to input for high)
Pauseus 60 ' Use up rest of time slot
Return
'Read a bit from the DS1820
DS1820_oku:
For i = 1 to 16 ' 16 bits to a word
temp = temp >> 1 ' Shift down bits
Gosub bit_oku ' Get the bit to the top of temp
Next i
Return
'DS1820'den 1 bit okur
bit_oku:
temp.15 = 1 ' Preset read bit to 1
Low DQ ' Start the time slot
@ nop ' Delay 1us at 4MHz
DQ_DIR = 1 ' Release data pin (set to input for high)
If DQ = 0 Then
temp.15 = 0 ' Set bit to 0
Endif
Pauseus 60 ' Wait out rest of time slot
Return
End