here is something to start playing with
for buttom press i used
Bitwait Pinb.1 , Set 'only 1 step pr push
Waitms 200 ' or use waitms 200 then it steps every 200 ms
[code:1:1488fc956e]'http://qabulbee.blogspot.dk/2011/11/sensor-suhu-lm35-dg-micro-atmega8535.html
'$sim
$regfile = "M8535.dat"
$crystal = 11059200
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.2 , Rs = Portc.1
Config Lcd = 16 * 2
Buzzer Alias Portd.0
Relay2 Alias Portd.7
Relay1 Alias Portd.6
Ddrb = &B11111100
Button_up Alias Pinb.0 'Button Connectet To Pinb.0 - -button-- - Gnd
Button_down Alias Pinb.1 'Button Connectet To Pinb.1 - -button - Gnd
Set Portb.0 'pullup
Set Portb.1 'pullup
Dim Set_temp As Single 'set temp var
Dim Old_temp As Single 'old temp var for update lcd
Declare Sub Read_lm35() 'sub for read LM35
Declare Sub Read_keys() 'sub for read buttons
Declare Sub Set_relays() 'sub for read set relays
Declare Sub Setup()
Config Adc = Single , Prescaler = Auto , Reference = Internal
Dim Dataadc As Word , Datasuhu As Single
Const Vreff = 5.00
Start Adc
Cls
Cursor Off
'READ SET TEMP VALUE FROM EEPROM
Readeeprom Set_temp , 3 'read stored SET temp from eeprom
If Set_temp > 100 Or Set_temp < 1 Then Set_temp = 39.5 'set som defalut values for SET temp min max else set defalt value 39.5 deg
Call Setup() 'setup default lcd
'MAIN
Do
Call Read_keys() 'read buttons
Call Read_lm35() 'read LM35
Call Set_relays() 'set relays
Waitms 100
Loop
End
'SUBS
Sub Read_keys() ' connect button to port pin and GND
If Button_up = 0 Then
Set_temp = Set_temp + 0.5 'incrase temp by 0.5 deg
Locate 1 , 7
If Set_temp < 10 Then Lcd " "
If Set_temp => 100 Then Locate 1 , 7
If Set_temp => 10 And Set_temp < 100 Then Lcd " "
Lcd Fusing(set_temp , "#.##") ; " "
Writeeeprom Set_temp , 3
'Bitwait Pinb.0 , Set ' only 1 step pr push
Waitms 200 'or use
End If
If Button_down = 0 Then
Set_temp = Set_temp - 0.5 'decrese temp by 0.5 deg
Locate 1 , 7
If Set_temp < 10 Then Lcd " "
If Set_temp => 100 Then Locate 1 , 7
If Set_temp => 10 And Set_temp < 100 Then Lcd " "
Lcd Fusing(set_temp , "#.##") ; " "
Writeeeprom Set_temp , 3
' Bitwait Pinb.1 , Set ' only 1 step pr push
Waitms 200 'or use
End If
End Sub
Sub Read_lm35()
Dataadc = Getadc(5)
Datasuhu = Dataadc / 1024
Datasuhu = Datasuhu * Vreff
Datasuhu = Datasuhu * 100
If Datasuhu <> Old_temp Then 'update lcd if temp is new
Locate 2 , 7
If Datasuhu < 10 Then Lcd " "
If Datasuhu => 100 Then Locate 2 , 7
If Datasuhu => 10 And Datasuhu < 100 Then Lcd " "
Lcd Fusing(datasuhu , "#.##") ; " "
Old_temp = Datasuhu
End If
End Sub
Sub Set_relays()
If Datasuhu => Set_temp Then
Relay2 = 0
Relay1 = 1
Buzzer = 1
Elseif Datasuhu < Set_temp Then
Relay2 = 1
Relay1 = 0
Buzzer = 0
End If
End Sub
Sub Setup()
'logo
Locate 1 , 2
Lcd "*TAT TWAM ASI*"
Wait 2 'show for 2 sec
Cls 'clear lcd
'setup default text to lcd
Locate 1 , 1
Lcd "SET ="
Locate 1 , 8
Lcd Fusing(set_temp , "#.##") ; " "
Locate 1 , 14
Lcd Chr(223) ; "C"
Locate 2 , 14
Lcd Chr(223) ; "C"
Locate 2 , 1
Lcd "TEMP ="
End Sub[/code:1:1488fc956e]
↧