mehmetcfb
Üye
- Katılım
- 24 Tem 2009
- Mesajlar
- 9
- Puanları
- 1
- Yaş
- 44
Arkadaşlar merhaba,
Ds18B20 den aldığım sıcaklığı pic16f84 ile set ettğim sıcaklık ile karşılaştırıp portb.0 üzerinden role çektirerek fanları çalıştırıyorum .Altta bütün kodları vereceğim sorum şu programdaki karşılaştırma etiketi bu :
karsilastirma
temp=temp/8
if temp >= set then
portb.0 = 1
else
portb.0 = 0
Burda " if temp >= set then " koşulu sağlandığında portb.0 ' ın 2 dakika yada 1 dakika gibi bir süre portb.0=1 olarak kalmasını ve sonra döngüye devam etmesini istiyorum. yada yine " if temp >= set then " koşulu sağlandığında ortam sıcaklığı set ettiğim sıcaklığın 2 derece altına düşene kadar portb.0 = 1 olarak kalmasını isiyorum.
Bütün program :
' Picbasic Pro program to read DS1820 1-wire temperature sensor
' and display temperature on LCD
' Allocate variables
command var byte ' Storage for command
i2 var byte ' Storage for loop counter
temp var word ' Storage for temperature
ayar var word ' Storage for temperature
set var word ' Storage for temperature
DQ var PORTB.4 ' Alias DS1820 data pin
DQ_DIR var TRISB.4 ' Alias DS1820 data direction pin
output portb.0
'output portb.1
'output portb.2
Pause 500 ' Wait for LCD to start
LCDOUT $fe,1,"MEHMET OZLAV"
LCDOUT $FE, $C0, "DIJITAL TERMO"
Pause 1000 ' Wait for LCD to start
LCDOUT $fe,1,"ORTAM SICAKLIGI"
LCDOUT $FE, $C0,"OKUNUYOR"
PAUSE 1000
c var byte
c = 0
while c =< 22
Lcdout $fe, $80 + c , "."
Lcdout $fe, $7f + c , "."
Lcdout $fe, $7e + c , "."
Lcdout $fe, $7d + c , "."
Lcdout $fe, $7c + c , "."
Lcdout $fe, $7b + c , "."
Lcdout $fe, $7a + c , "."
Lcdout $fe, $79 + c , "."
Pause 50
Lcdout $fe,1
c = c + 1
wend
mainloop:
read 10,ayar
set=ayar
if portb.7=0 and portb.6=0 then
gosub ayarlama
else
gosub okuma
endif
ayarlama:
if portb.7 = 0 then 'DERECE ARTTIR
ayar = ayar + 1
pause 100
endif
if portb.6 = 0 then 'DERECE AZALT
ayar = ayar - 1
pause 100
endif
' Display the decimal temperature
Lcdout $fe, 1, "Set:",dec (set >> 1 ), ".", dec (set.0 * 5),223,"C"
lcdout $fe,$c0,"Ayar:",dec (ayar >> 1 ), ".", dec (ayar.0 * 5),223,"C"
pause 100
if portb.5 = 0 then 'DERECE SET
set = ayar
WRITE 10,set
Lcdout $fe, 1, "Set: ",dec (set >> 1 ), ".", dec (set.0 * 5),223,"C"
lcdout $fe,$c0,"Ayarlandi..."
pause 1000
else
gosub ayarlama
endif
'------------------------------------------------------------------------------
okuma:
read 10,set
Gosub init1820 ' Init the DS1820
command = $cc ' Issue Skip ROM command
Gosub write1820
command = $44 ' Start temperature conversion
Gosub write1820
'LCDOUT $FE, $C0, "Termometre"
Pause 1500 ' Wait 2 seconds for conversion to complete
Gosub init1820 ' Do another init
command = $cc ' Issue Skip ROM command
Gosub write1820
command = $be ' Read the temperature
Gosub write1820
Gosub read1820
' karsilastirma
temp=temp/8
if temp >= set then
portb.0 = 1
else
portb.0 = 0
endif
' Display the decimal temperature
Lcdout $fe, 1,"Ortam:", dec (temp >> 1 ), ".", dec (temp.0 * 5),223,"C"
Lcdout $fe, $C0, "Set: ",dec (set >> 1 ), ".", dec (set.0 * 5),223,"C"
Goto mainloop ' Do it forever
' 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, 1, "HAZIR DEGIL"
'LCDOUT $FE, $C0, "Mehmet OZLAV"
Pause 500
Goto mainloop ' Try again
Endif
Pauseus 400 ' Wait for end of presence pulse
Return
' Write "command" byte to the DS1820
write1820:
For i2 = 1 to 8 ' 8 bits to a byte
If command.0 = 0 Then
Gosub write0 ' Write a 0 bit
Else
Gosub write1 ' Write a 1 bit
Endif
command = command >> 1 ' Shift to next bit
Next i2
Return
' Write a 0 bit to the DS1820
write0:
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
write1:
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 temperature from the DS1820
read1820:
For i2 = 1 to 16 ' 16 bits to a word
temp = temp >> 1 ' Shift down bits
Gosub readbit ' Get the bit to the top of temp
Next i2
Return
' Read a bit from the DS1820
readbit:
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
Yardımlarınızı bekliyorum . şimdiden sağolun.
Arkadaşlar cevaplarınızı bekliyorum![Gülümse :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Ds18B20 den aldığım sıcaklığı pic16f84 ile set ettğim sıcaklık ile karşılaştırıp portb.0 üzerinden role çektirerek fanları çalıştırıyorum .Altta bütün kodları vereceğim sorum şu programdaki karşılaştırma etiketi bu :
karsilastirma
temp=temp/8
if temp >= set then
portb.0 = 1
else
portb.0 = 0
Burda " if temp >= set then " koşulu sağlandığında portb.0 ' ın 2 dakika yada 1 dakika gibi bir süre portb.0=1 olarak kalmasını ve sonra döngüye devam etmesini istiyorum. yada yine " if temp >= set then " koşulu sağlandığında ortam sıcaklığı set ettiğim sıcaklığın 2 derece altına düşene kadar portb.0 = 1 olarak kalmasını isiyorum.
Bütün program :
' Picbasic Pro program to read DS1820 1-wire temperature sensor
' and display temperature on LCD
' Allocate variables
command var byte ' Storage for command
i2 var byte ' Storage for loop counter
temp var word ' Storage for temperature
ayar var word ' Storage for temperature
set var word ' Storage for temperature
DQ var PORTB.4 ' Alias DS1820 data pin
DQ_DIR var TRISB.4 ' Alias DS1820 data direction pin
output portb.0
'output portb.1
'output portb.2
Pause 500 ' Wait for LCD to start
LCDOUT $fe,1,"MEHMET OZLAV"
LCDOUT $FE, $C0, "DIJITAL TERMO"
Pause 1000 ' Wait for LCD to start
LCDOUT $fe,1,"ORTAM SICAKLIGI"
LCDOUT $FE, $C0,"OKUNUYOR"
PAUSE 1000
c var byte
c = 0
while c =< 22
Lcdout $fe, $80 + c , "."
Lcdout $fe, $7f + c , "."
Lcdout $fe, $7e + c , "."
Lcdout $fe, $7d + c , "."
Lcdout $fe, $7c + c , "."
Lcdout $fe, $7b + c , "."
Lcdout $fe, $7a + c , "."
Lcdout $fe, $79 + c , "."
Pause 50
Lcdout $fe,1
c = c + 1
wend
mainloop:
read 10,ayar
set=ayar
if portb.7=0 and portb.6=0 then
gosub ayarlama
else
gosub okuma
endif
ayarlama:
if portb.7 = 0 then 'DERECE ARTTIR
ayar = ayar + 1
pause 100
endif
if portb.6 = 0 then 'DERECE AZALT
ayar = ayar - 1
pause 100
endif
' Display the decimal temperature
Lcdout $fe, 1, "Set:",dec (set >> 1 ), ".", dec (set.0 * 5),223,"C"
lcdout $fe,$c0,"Ayar:",dec (ayar >> 1 ), ".", dec (ayar.0 * 5),223,"C"
pause 100
if portb.5 = 0 then 'DERECE SET
set = ayar
WRITE 10,set
Lcdout $fe, 1, "Set: ",dec (set >> 1 ), ".", dec (set.0 * 5),223,"C"
lcdout $fe,$c0,"Ayarlandi..."
pause 1000
else
gosub ayarlama
endif
'------------------------------------------------------------------------------
okuma:
read 10,set
Gosub init1820 ' Init the DS1820
command = $cc ' Issue Skip ROM command
Gosub write1820
command = $44 ' Start temperature conversion
Gosub write1820
'LCDOUT $FE, $C0, "Termometre"
Pause 1500 ' Wait 2 seconds for conversion to complete
Gosub init1820 ' Do another init
command = $cc ' Issue Skip ROM command
Gosub write1820
command = $be ' Read the temperature
Gosub write1820
Gosub read1820
' karsilastirma
temp=temp/8
if temp >= set then
portb.0 = 1
else
portb.0 = 0
endif
' Display the decimal temperature
Lcdout $fe, 1,"Ortam:", dec (temp >> 1 ), ".", dec (temp.0 * 5),223,"C"
Lcdout $fe, $C0, "Set: ",dec (set >> 1 ), ".", dec (set.0 * 5),223,"C"
Goto mainloop ' Do it forever
' 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, 1, "HAZIR DEGIL"
'LCDOUT $FE, $C0, "Mehmet OZLAV"
Pause 500
Goto mainloop ' Try again
Endif
Pauseus 400 ' Wait for end of presence pulse
Return
' Write "command" byte to the DS1820
write1820:
For i2 = 1 to 8 ' 8 bits to a byte
If command.0 = 0 Then
Gosub write0 ' Write a 0 bit
Else
Gosub write1 ' Write a 1 bit
Endif
command = command >> 1 ' Shift to next bit
Next i2
Return
' Write a 0 bit to the DS1820
write0:
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
write1:
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 temperature from the DS1820
read1820:
For i2 = 1 to 16 ' 16 bits to a word
temp = temp >> 1 ' Shift down bits
Gosub readbit ' Get the bit to the top of temp
Next i2
Return
' Read a bit from the DS1820
readbit:
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
Yardımlarınızı bekliyorum . şimdiden sağolun.
Arkadaşlar cevaplarınızı bekliyorum
Moderatör tarafında düzenlendi: