Witaj,kiedyś napisałem program w Bascomie do załączania żelazka które nie miało żadnego czujnika i regulatora temperatury,program jest napisany pod czujnik temperatury LM35 ponieważ ma duży zakres mierzenia,może ci to pomoże w rozwiązaniu twojego problemu:
Zaloguj się, aby zobaczyć kod
$regfile = "m8def.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 64
$framesize = 32
Config Debounce = 30
'********************* Konfiguracja wejść i wyjść
Config Portb.4 = Output
Set Portb.4
Config Portb.5 = Output
Set Portb.5
Config Portb.0 = Input
Set Portb.0
Config Portb.1 = Input
Set Portb.1
Config Portb.2 = Input
Set Portb.2
Config Portb.3 = Input
Set Portb.3
'********************* Konfiguracja wyświetlacza
Config Lcd = 16 * 4 'konfiguracja typu wyświetlacza
Config Lcdpin = Pin , Db4 = Portd.3 , Db5 = Portd.2 , Db6 = Portd.1 , Db7 = Portd.0 , E = Portd.4 , Rs = Portd.5
'********************* Konfiguracja znaku specjalnego LCD
Deflcdchar 0 , 8 , 20 , 11 , 4 , 4 , 4 , 3 , 32 'znak stopnia Celsjusza
Deflcdchar 3 , 12 , 4 , 6 , 12 , 4 , 4 , 14 , 32 ' replace ? with number (0-7)
Deflcdchar 4 , 32 , 32 , 14 , 1 , 15 , 17 , 15 , 2 ' replace ? with number (0-7)
'********************* Konfiguracja magistrali 1-Wire
Config Timer1 = Timer , Prescale = 256
Enable Timer1
On Timer1 Czas
Timer1 = 34286
'********** Włączenie przerwań
Enable Interrupts
'********************* Deklaracje zmiennych
'zmienna zawierająca przeliczoną i sformatowaną wartość wskazania układu
Dim T_min As Single
Dim T_min1 As Integer
Dim T_max As Single
Dim T_max1 As Integer
Dim T_min_lcd As String * 6
Dim T_max_lcd As String * 6
Dim Flaga_buzer As Bit
Dim Start_menu As Byte
Dim Licznik1 As Integer
Dim Flaga_menu As Bit
Dim V As Word
Dim S As Single
Dim Wart_nap1 As String * 3
Dim Volt_d As Byte
'********************* Deklaracja podprogramów
Declare Sub Menu
Declare Sub Ustaw_max
Declare Sub Ustaw_min
'********************* Przypisanie przyjaznych nazw do poszczególnych portów
Led1 Alias Portb.5
Buzer Alias Portb.4
Enter Alias Pinb.3
Gora Alias Pinb.1
Dol Alias Pinb.2
Menu_ustaw Alias Pinb.0
Config Adc = Single , Prescaler = Auto , Reference = Avcc
'********************* Deklaracja wartości początkowych
T_min = 135.0
T_max = 150.0
Cursor Off 'wyłącz kursor
Cls
Start Adc
Do
Debounce Menu_ustaw , 0 , Menu , Sub
V = Getadc(0)
S = V * 5
S = S / 10
Wart_nap1 = Fusing(s , "#.&" )
Locate 1 , 1 'wyświetl w pozycji
Lcd "T.aktual " ; Wart_nap1 ; Chr(0) ; " "
T_min1 = T_min
T_min_lcd = Str(t_min)
T_min_lcd = Format(t_min_lcd , " 0") 'wyświetl wynik formatowania + znak specjalny + C
Locate 2 , 1
Lcd "T.ust.min " ; T_min_lcd ; Chr(0) ; " "
T_max1 = T_max
T_max_lcd = Str(t_max)
T_max_lcd = Format(t_max_lcd , " 0")
Locate 3 , 1
Lcd "T.ust.max " ; T_max_lcd ; Chr(0) ; " "
'*************************** Ustawienie temperatur - włączenie i wyłączenie
If S =< T_min Then
Led1 = 0
End If
If S >= T_max Then
Led1 = 1
End If
If S >= T_min And S >= T_max Then
Locate 4 , 3
Lcd "Grzanie Wy" ; Chr(3)
End If
If Led1 = 1 And S =< T_max Then
Locate 4 , 3
Lcd "Grzanie Wy" ; Chr(3)
End If
If S =< T_min And S =< T_max Then
Locate 4 , 3
Lcd "Grzanie Za" ; Chr(3)
End If
If Led1 = 0 And S =< T_max Then
Locate 4 , 3
Lcd "Grzanie Za" ; Chr(3)
End If
'*************************** Sygnalizacja zmian temperatury przez buzer
If S >= T_max Or S =< T_min Then
If Flaga_buzer = 0 Then
Buzer = 0
Waitms 200
Buzer = 1
Flaga_buzer = 1
End If
Else
Flaga_buzer = 0
End If
Loop
End
'*********************** Podprogram ustawiania wartości temperatur
Sub Menu:
Start_menu = 0
Do
If Menu_ustaw = 0 Then
Waitms 25
If Menu_ustaw = 0 Then
Incr Start_menu
If Start_menu >= 3 Then
Start_menu = 0
End If
End If
End If
Select Case Start_menu
Case 0 :
Case 1 :
Locate 3 , 1
Lcd "Ustaw max:"
Waitms 200 : Cls : Gosub Ustaw_max
Case 2 :
Locate 2 , 1
Lcd "Ustaw min:"
Waitms 200 : Cls : Gosub Ustaw_min
End Select
If Enter = 0 Then
Exit Do
End If
Loop
End Sub
Ustaw_min:
If Gora = 0 Then
T_min = T_min + 0.5
Else
If Dol = 0 Then
T_min = T_min - 0.5
End If
End If
T_min1 = T_min
T_min_lcd = Str(t_min)
T_min_lcd = Format(t_min_lcd , " 0")
Locate 2 , 12
Lcd T_min_lcd
Return
Ustaw_max:
If Gora = 0 Then
T_max = T_max + 0.5
Else
If Dol = 0 Then
T_max = T_max - 0.5
End If
End If
T_max1 = T_max
T_max_lcd = Str(t_max)
T_max_lcd = Format(t_max_lcd , " 0")
Locate 3 , 12
Lcd T_max_lcd
Return
Czas:
Timer1 = Timer1 + 34286
Incr Licznik1
If Licznik1 = 12 Then
Flaga_menu = 1
Licznik1 = 0
End If
Return