$regfile = "m8def.dat" 'najpierw określamy typ proca
$crystal = 8000000 'definiujemy z jakim taktowaniem będzie pracował
Deflcdchar 1 , 4 , 4 , 4 , 4 , 4 , 17 , 10 , 4 ' replace ? with number (0-7)
Deflcdchar 2 , 1 , 2 , 6 , 10 , 17 , 17 , 31 , 6 ' replace ? with number (0-7)
Config Portc.4 = Output
Config Portb.0 = Input
Portb.0 = 1
Config Portd.7 = Input
Portd.7 = 1
Config Portd.6 = Input
Portd.6 = 1 'wejscia'
Config Portd.5 = Input
Portd.5 = 1
Config Portb.7 = Input
Portb.7 = 1
Config Portb.1 = Output
Portb.1 = 0
Config 1wire = Portc.5
Config Portb.2 = Output 'wyjscia'
Speaker Alias Portb.2
Config Timer1 = Timer , Prescale = 256
On Timer1 1sekunda:
Enable Interrupts
Enable Timer1
Dim Odczyt(2) As Byte
Dim A As Byte
Dim Licznik As Byte
Dim T As Integer
Dim T1 As Single
Dim Napis As String * 5
Dim Zt As Bit
Dim W As Bit
Dim X As Bit
Dim S As Byte
Dim M As Byte
Dim G As Byte
Dim Y As Bit
Dim U As Bit
Dim Wybor As Byte
Dim Wart_bcd As Byte
Dim Blokada As Bit
Dim Stopzegar As Bit
Dim Budz As Bit
Dim Gb As Byte
Dim Mb As Byte
Dim Zal As Bit
Dim Muza As Bit
Dim Kal As Bit
Dim Dni As Byte
Dim Dnimax As Byte
Dim Mies As Byte
Dim Miesiac As String * 7
Dim Uskal As Bit
Dim Rok As Byte
Dim Blokada2 As Bit
Dim Address As Byte
Dim Command As Byte
Declare Sub Termometr
Declare Sub Zegar
Declare Sub Petla
Declare Sub Zatwierdz
Declare Sub Przycisk
Declare Sub Menu
Declare Sub Ustawzegar
Declare Sub Budzik
Declare Sub Melodia
Declare Sub Budzikmelodia
Declare Sub Budzikstop
Declare Sub Kalendarz
Declare Sub Ustawkalendarz
Declare Sub Wybormiesiecy
S1 Alias Pinb.0
S2 Alias Pind.7
S3 Alias Pind.6 'zmiana nazw przycinkow'
S4 Alias Pinb.7
S5 Alias Pind.5
Config Rc5 = Pind.3
Enable Interrupts
Cursor Off Noblink
Cls
Lcd "zegar"
Lowerline
Lcd "by frog"
Wait 1
W = 1
Gosub Menu
Do
Getrc5(address , Command)
Command = Command And &B01111111
If Address = 20 And Command = 12 Then
Toggle Portc.4
End If
Blokada2 = 0
If X = 1 And W = 1 Then Zegar
If Wybor = 2 Then Zatwierdz
If Wybor = 3 Then Zatwierdz
If Wybor = 4 Then Zatwierdz
If Wybor = 5 Then Zatwierdz
If Wybor = 6 Then Zatwierdz
If Wybor = 7 Then Zatwierdz
If X = 1 And Y = 1 Then Termometr
If U = 1 Then Ustawzegar
If Budz = 1 Then Budzik
If Kal = 1 Then Kalendarz
If Uskal = 1 Then Ustawkalendarz
If Blokada = 0 Then
If S3 = 0 Then
Waitms 150
If S3 = 0 Then
Incr Wybor
Gosub Menu
End If
End If
If S2 = 0 Then
Waitms 150
If S2 = 0 Then
Decr Wybor
Gosub Menu
End If
End If
End If
If Blokada2 = 0 Then
If S5 = 0 Then 'jesli piaty klawisz nacisniety'
Waitms 100 'opoznienie'
If S5 = 0 Then 'skocz do podprogramu wyswietlajacego wartosci budzika' 'aktywuj klawisze potrzebne do nastawienie budzika'
Toggle Portb.1 'zmien stan wyprowadzenia z dioda sygnalizujaca czy budzik jest zalaczony czy wylaczony'
Toggle Zal 'zmien stan budzika czyli zalaczony/wylaczony'
End If 'koniec petli warunkowej'
End If
If Zal = 0 Then 'jesli budzik zalaczony'
If Mb = M And Gb = G Then 'jesli minuty ustawien budzika sa takie same jak minuty zehara a godziny ustawien budzika jak godziny zegara '
Budzikmelodia 'to skocz do podprogramu generujacego dzwiek budzenia'
End If 'koniec petli warunkowej'
End If
If S5 = 0 And Zal = 0 Then
Waitms 100
If S5 = 0 And Zal = 0 Then
Cls
Lcd "budzik zalaczony"
Locate 2 , 4
If Gb < 10 Then Lcd "0"
Lcd Gb ; ":"
If Mb < 10 Then Lcd "0"
Lcd Mb
Wait 1
Cls
End If
End If
If S5 = 0 And Zal = 1 Then
Waitms 100
If S5 = 0 And Zal = 1 Then
Cls
Lcd "budzik wylaczony"
Wait 1
Cls
End If
End If
End If
Loop
End
Sub Menu
If Wybor = 0 Then
Wybor = 6
End If
If Wybor = 8 Then
Wybor = 1
End If
Select Case Wybor
Case 1
Y = 0
W = 0
U = 0
Cls
Lcd "1. daria"
Case 2
W = 0
Cls
Lcd "2. termometr"
Case 3
Y = 0
U = 0
Cls
Lcd "3. zegar"
Case 4
Y = 0
W = 0
Cls
Lcd "4. Ustaw zegar"
Case 5
Cls
Lcd "5. Budzik "
Case 6
Cls
Lcd "6. kalendarz "
Case 7
Cls
Lcd "7. Ustaw kalendarz "
End Select
End Sub
Sub Zatwierdz:
If S1 = 0 Then
Waitms 100
If S1 = 0 Then
If Wybor = 2 Then Y = 1
If Wybor = 3 Then W = 1
If Wybor = 4 Then U = 1
If Wybor = 5 Then
Cls
Budz = 1
End If
If Wybor = 6 Then
Cls
Kal = 1
End If
If Wybor = 7 Then Uskal = 1
End If
End If
End Sub
Sub Kalendarz
Blokada = 1
If S1 = 0 Then
Waitms 110
If S1 = 0 Then
If Blokada = 1 Then
Kal = 0
Blokada = 0
Cls
Locate 1 , 1
Lcd "nacisnij przycisk "
Locate 2 , 4
Lcd "S2 lub S3"
Stopzegar = 0
Return
End If
End If
End If
W = 0
Locate 1 , 1
Wart_bcd = Makebcd(rok)
Lcd Dni ; " " ; Miesiac ; " " ; "20" ; Bcd(wart_bcd)
Locate 2 , 1
Lcd Dnimax
End Sub
Sub Budzikmelodia:
W = 0
Budzikstop
Sound Speaker , 124 , 675 'H2(1/16)
Budzikstop
Sound Speaker , 110 , 758 'A2(1/16)
Budzikstop
Cls
Budzikstop
Lcd "ALARM"
Budzikstop
End Sub
Sub Budzikstop:
If Pind.5 = 0 Then
Waitms 100
If Pinb.5 = 0 Then
Toggle Portb.1
Toggle Zal
If W = 0 Then W = 1
End If
End If
End Sub
Sub Termometr:
X = 0
1wreset 'reset
1wwrite &HCC 'jedna kostka, więc wykorzystujemy rozkaz SKIP ROM
1wwrite &H44 'dokonaj konwersji
Waitms 750 'przeczekaj czas konwersji
1wreset 'reset
1wwrite &HCC 'rozkaz adresowy SKIP ROM
1wwrite &HBE 'rozkaz funkcyjny - polecenie odczytu DS18x20
Odczyt(1) = 1wread(2) 'odczytaj dwa pierwsze bajty
T = Odczyt(2) 'przepisz starszy bajt do zmiennej typu Integer
Shift T , Left , 8 'przesuń ten bajt w lewo na wyższe pozycje
T = T + Odczyt(1) 'przepisz - dodaj młodszy bajt
T1 = T * 0.0625 'wyra? w stopniach Celsjusza, wynik wpisz do zmiennej Single
Napis = Fusing(t1 , "#.#")
Cls : Cursor Off : Lcd "* Temperatura *"
Lowerline
Lcd "Wynik: " ; Napis ; " " ; "C" 'rozkaz funkcyjny - polecenie odczytu DS18x20
End Sub
Sub Budzik:
If S4 = 0 Then
Waitms 100
If S4 = 0 Then
Toggle Zal
End If
End If
If S1 = 0 Then
Waitms 110
If S1 = 0 Then
If Blokada = 1 Then
Budz = 0
Blokada = 0
Cls
Locate 1 , 1
Lcd "nacisnij przycisk "
Locate 2 , 4
Lcd "S2 lub S3"
Stopzegar = 0
Return
End If
End If
End If
Blokada = 1
If S2 = 0 Then
Waitms 100
If S2 = 0 Then
Incr Gb
Budz = 1
End If
End If
If S3 = 0 Then
Waitms 100
If S3 = 0 Then
Incr Mb
Budz = 1
End If
End If
Locate 1 , 4
Lcd "Budzik"
Locate 2 , 2
Wart_bcd = Makebcd(gb)
Lcd Bcd(wart_bcd) ; ":"
Wart_bcd = Makebcd(mb)
Lcd Bcd(wart_bcd) ; Chr(0)
Waitms 10
Toggle Budz
Waitms 100
Toggle Budz
End Sub
Sub Ustawkalendarz
Kal = 0
If S1 = 0 Then
Waitms 100
If S1 = 0 Then
If Blokada = 1 Then
Uskal = 0
Blokada = 0
Cls
Locate 1 , 1
Lcd "nacisnij przycisk "
Locate 2 , 4
Lcd "S2 lub S3"
Stopzegar = 0
Return
End If
End If
End If
Blokada2 = 1
If S5 = 0 Then
Waitms 100
If S5 = 0 Then
Incr Rok
If Rok = 50 Then Rok = 0
End If
End If
If S4 = 0 Then
Waitms 100
If S4 = 0 Then
Decr Rok
If Rok = 0 Then Rok = 50
End If
End If
Blokada = 1
If S2 = 0 Then
Waitms 100
If S2 = 0 Then
Incr Dni
If Dni > Dnimax Then
Dni = 0
End If
End If
End If
If S3 = 0 Then
Waitms 100
If S3 = 0 Then
Incr Mies
Wybormiesiecy
If Mies = 13 Then
Mies = 1
End If
End If
End If
Locate 2 , 2
Wart_bcd = Makebcd(rok)
Lcd Dni ; " " ; Miesiac ; " 20" ; Bcd(wart_bcd) ; " "
Waitms 10
Toggle Uskal
Waitms 100
Toggle Uskal
End Sub
Sub Ustawzegar:
Stopzegar = 1
S = 0
If S1 = 0 Then
Waitms 100
If S1 = 0 Then
If Blokada = 1 Then
U = 0
Blokada = 0
Cls
Locate 1 , 1
Lcd "nacisnij przycisk "
Locate 2 , 4
Lcd "S2 lub S3"
Stopzegar = 0
Return
End If
End If
End If
Blokada = 1
If S2 = 0 Then
Waitms 100
If S2 = 0 Then
Incr M
Cls
Locate 1 , 6
Lcd Chr(1) ; "minuta"
If M = 60 Then M = 0
End If
End If
If S3 = 0 Then
Waitms 100
If S3 = 0 Then
Incr G
Cls
Locate 1 , 4
Lcd Chr(1) ; "godzina"
If G = 24 Then G = 0
End If
End If
Locate 2 , 2
Wart_bcd = Makebcd(g)
Lcd "<<" ; Bcd(wart_bcd) ; ":"
Wart_bcd = Makebcd(m)
Lcd Bcd(wart_bcd) ; ":"
Wart_bcd = Makebcd(s)
Lcd Bcd(wart_bcd) ; ">>" ; " "
Waitms 10
Toggle U
Waitms 100
Toggle U
End Sub
Sub Zegar:
X = 0
Cls
Locate 1 , 4
Lcd "Zegar"
Locate 2 , 4
Wart_bcd = Makebcd(g)
Lcd Bcd(wart_bcd) ; ":"
Wart_bcd = Makebcd(m)
Lcd Bcd(wart_bcd) ; ":"
Wart_bcd = Makebcd(s)
Lcd Bcd(wart_bcd)
If Zal = 0 Then
Locate 1 , 16
Lcd Chr(2)
End If
End Sub
Sub Wybormiesiecy
Select Case Mies
Case 1:
Dnimax = 3
Miesiac = "sty "
Case 2:
Dnimax = 4
Miesiac = "lut "
Case 3:
Dnimax = 3
Miesiac = "mar "
Case 4:
Dnimax = 4
Miesiac = "kwi "
Case 5:
Dnimax = 3
Miesiac = "maj "
Case 6:
Dnimax = 30
Miesiac = "cze "
Case 7:
Dnimax = 3
Miesiac = "lip "
Case 8:
Dnimax = 4
Miesiac = "sie "
Case 9:
Dnimax = 3
Miesiac = "wrz "
Case 10:
Dnimax = 4
Miesiac = "paz "
Case 11:
Dnimax = 3
Miesiac = "lis "
Case 12:
Dnimax = 4
Miesiac = "gru "
End Select
End Sub
1sekunda:
Timer1 = Timer1 + 34286
If Stopzegar = 0 Then
Incr S
X = 1
If S = 60 Then
S = 0
Incr M
If M = 60 Then
M = 0
Incr G
If G = 24 Then
G = 0
Incr Dni
If Dni > Dnimax Then
Incr Mies
Dni = 1
If Mies = 13 Then Mies = 0
Wybormiesiecy
End If
End If
End If
End If
End If
Return