View previous topic :: View next topic |
Author |
Message |
canal
Joined: 23 Feb 2014 Posts: 9
|
Posted: Sun Feb 23, 2014 1:01 pm Post subject: Add push button |
|
|
Hi everybody, can you help me? please
I'm a newbie..
I try to create tools (thermostat) using ATmega8535, and i don't know how to create code for push button.
I will put the button on Pinb.0 and Pinb.1, So i can set temperature increase or decrease setting and store data to the eeprom..
I'm using LM35 for sensor, on Port A5..
This is the my first code using bascom
Code: |
$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
Config Adc = Single , Prescaler = Auto , Reference = Internal
Dim Dataadc As Word , Datasuhu As Single
Const Vreff = 5.00
Start Adc
Cls
Cursor Off
Locate 1 , 2
Lcd "*TAT TWAM ASI*"
Locate 2 , 14
Lcd Chr(223) ; "C"
Locate 2 , 1
Lcd "SUHU ="
Do
Dataadc = Getadc(5)
Datasuhu = Dataadc / 1024
Datasuhu = Datasuhu * Vreff
Datasuhu = Datasuhu * 100
Locate 2 , 8
Lcd "" ; Fusing(datasuhu , "#.##")
If Datasuhu > 39 Then
Relay2 = 0
Relay1 = 1
Buzzer = 1
Elseif Datasuhu < 39 Then
Relay2 = 1
Relay1 = 0
Buzzer = 0
End If
Waitms 100
Loop
End
|
See on the Lcd "*TAT TWAM ASI*", i need this text present only 2 second and replace with "Set : °C"
Please help me..
Thank you
(BASCOM-AVR version : 2.0.7.7 ) |
|
Back to top |
|
|
amirf
Joined: 25 Aug 2009 Posts: 154
|
Posted: Sun Feb 23, 2014 1:33 pm Post subject: |
|
|
see bascom manual , you may use debounce command |
|
Back to top |
|
|
canal
Joined: 23 Feb 2014 Posts: 9
|
Posted: Sun Feb 23, 2014 9:18 pm Post subject: |
|
|
amirf wrote: | see bascom manual , you may use debounce command |
Thanks Amir.
I see, but can you write the code using debounce command?
i don't know from where i started write the code using debounce command.. |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Sun Feb 23, 2014 9:41 pm Post subject: |
|
|
here is something to start playing with
for buttom press i used waitms 200 but you can use bitwait to see help Bitwait
Bitwait Pinb.1 , Set 'only 1 step pr push
Waitms 200 ' or use waitms 200 then it steps every 200 ms
Code: | '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 |
_________________ / Kim |
|
Back to top |
|
|
canal
Joined: 23 Feb 2014 Posts: 9
|
Posted: Sun Feb 23, 2014 11:54 pm Post subject: attach schematics |
|
|
Kimmi, Thanks for give some code. i try to use this code.
So now i'll attach the schematics and purpose of this tools. please help me to give code for this schematics.
(Because this forum is not support to attach the PDF file) |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Mon Feb 24, 2014 1:17 am Post subject: |
|
|
just zip the pdf
I removed your link to g..gle
you ask for help to use pins as input for buttons and save to eeprom all that is in code above _________________ / Kim |
|
Back to top |
|
|
canal
Joined: 23 Feb 2014 Posts: 9
|
Posted: Mon Feb 24, 2014 4:53 am Post subject: |
|
|
Oh i'm sorry kim, yes this is i attach the schematics on zip.. Your code is work and no problem.. Thanks so much.. and i call your code for Tat Twam asi V1.0..
This schematics is different with the first... see, and please help to create code.. |
|
Back to top |
|
|
canal
Joined: 23 Feb 2014 Posts: 9
|
Posted: Wed Feb 26, 2014 1:36 pm Post subject: |
|
|
Thank you very much Kim, it's working properly.. next time, i need your help again, to create code for my other schematics.. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|