Cytat:
$crystal = 8000000
$lib "mcsbyte.lbx"
$lib "i2c_twi.lbx"
$regfile = "m8def.dat"
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portb.1 , Db5 = Portb.0 , Db6 = Portd.7 , Db7 = Portd.6 , E = Portb.2 , Rs = Portb.3
$baud = 9600
Config Serialin = Buffered , Size = 15
$eeprom
Data 0 , 22 , 22 , 22 , 0
$data
'$prog &HFC , &HE2 , &HD9 , &HF8
'***********************************************************
' DEKLARACJE
'***********************************************************
Dim Alarm1 As Byte
Dim Alarm2 As Byte
Dim Alarm3 As Byte
Dim Temp1 As Byte
Dim Temp2 As Byte
Dim Flaga As Byte
Dim Tekst As String * 16
Dim Tekst2 As String * 8
Dim Temptekst As String * 3
Dim Lcd_linia1 As String * 16
Dim Lcd_linia2 As String * 16
Dim Spacje As String * 4
Dim Znak As Byte
Dim Kod As Byte
Dim A As String * 10
Dim C As String * 10
'ZMIENNE RTC
Dim S As Byte
Dim M As Byte
Dim H As Byte
Dim Hdec As Byte
Dim Mdec As Byte
Dim Hdec2 As Byte
Dim Godzina As Byte
Dim Czas_zapisywany As Byte
Dim X As Byte
Dim Y As Byte
Dim Z As Byte
Dim Menu As Byte
Dim Kursor As Byte
Dim Zalaczony As Byte
Dim Manual As Byte
Dim Light As Byte
Dim Znak_lcd As Byte
Dim Bufor As String * 2
Dim Bufor_znak As Byte
Dim Bufor_flaga As Byte
Dim Linia As Byte
Dim Odbior As String * 10
Dim Bufor_lcd As Byte
Dim Pp As Byte
Dim Pomocnicza As Byte
Dim Pozycjaeproma As Byte
Dim Pozycja As Byte
Dim Rs485 As Byte
Dim Q As Byte
Dim P As Bit
Dim Liczniksekundy As Byte
Dim 100ms As Byte
Dim Parametr As Byte
Dim Minimalnie As Byte
Dim Maxymalnie As Byte
Dim Tempozmian As Byte
Dim 5sek As Byte
S1 Alias Pinc.0
S2 Alias Pinc.3
S3 Alias Pind.3
Piszczyk Alias Portd.4
Podswietlenie Alias Portd.5
Kierunek Alias Portd.2
'PINd.2 sterowanie do Max485
'***********************************************************
' KONFIGURACJA
'***********************************************************
Config Portb = &B11111111 : Portb = &B10000000
Config Portc = &B00000000 : Portc = &B11111111
Config Portd = &B11110111 : Portd = &B00001000
Config Timer2 = Timer , Prescale = 256
Tempozmian = 200
Q = 100
Rs485 = 1
Declare Sub Przyciskplus
Declare Sub Przyciskminus
Declare Sub Submenu1
Declare Sub Submenu2
Declare Sub Odczyt_rtc
Declare Sub Zapis_rtc
Declare Sub Ekran_zegar
Declare Sub Odbior
Deflcdchar 1 , 12 , 4 , 5 , 6 , 4 , 4 , 14 , 32 'ł
Deflcdchar 2 , 7 , 5 , 7 , 32 , 32 , 32 , 32 , 32 ' stopień
Deflcdchar 3 , 2 , 4 , 14 , 16 , 14 , 1 , 14 , 32 'ś
Deflcdchar 4 , 4 , 14 , 16 , 14 , 1 , 1 , 14 , 32 'Ś
Deflcdchar 6 , 32 , 32 , 14 , 1 , 15 , 17 , 15 , 2 'ą
Deflcdchar 7 , 32 , 6 , 8 , 8 , 8 , 6 , 32 , 32 'ć
'***********************************************************
' WYKONYWANE PO STARCIE
'
'***********************************************************
Cls
Cursor Off
If S2 = 0 Then
If S3 = 0 Then
Piszczyk = 1
Wait 1
Piszczyk = 0
For X = 1 To 25
Y = Lookup(x , Tabelaprzywracania)
Writeeeprom Y , X
Next X
Lcd " Dane fabryczne "
Lowerline
Lcd " przywrocone "
Wait 2
End If
End If
Readeeprom Alarm1 , 1
Readeeprom Alarm2 , 2
Readeeprom Alarm3 , 3
Readeeprom Light , 4
'***********************************************************
' POCZĄTEK PĘTLI GŁÓWNEJ
'
'***********************************************************
Cls
Cursor Off
Lcd " Panel RS485 "
Lowerline
Lcd " Witam! "
Waitms 500
Enable Interrupts
'Config Watchdog = 256
'Start Watchdog
Enable Timer2
Start Timer2
On Timer2 Co5ms
For X = 1 To 15
Shiftlcd Right
Waitms 250
Next X
Cls
X = 0
'***********************************************************
Do
'***********************************************************
Y = 0
Z = 0
If Alarm1 = 1 Then Goto Koniec
If Alarm2 = 1 Then Goto Koniec
Call Odczyt_rtc
If Bufor_lcd = 1 Then
Lcd_linia1 = "T>1:" + C + Chr(2) + " "
Else
Lcd_linia1 = "T>1:" + "XX" + Chr(2) + " "
End If
Lcd_linia2 = "T>2:" + Str(temp3) + Chr(2) + " " + Bcd(h) + ":" + Bcd(m)
Upperline
Lcd Lcd_linia1
Lowerline
Lcd Lcd_linia2
If S1 = 0 Then
Piszczyk = 1
Waitms 50
Piszczyk = 0
Cls
Menu = 1
Do
Incr Z
If S2 = 0 Then
Gosub Obs2
Z = 0
Incr Menu
If Menu > 6 Then Menu = 1
End If
If S3 = 0 Then
Gosub Obs3
Z = 0
Decr Menu
If Menu < 1 Then Menu = 6
End If
Select Case Menu
Case 1:
Tekst = " Ustaw Alarm 1 "
Tekst2 = "ßC "
Parametr = Alarm1
Maxymalnie = 80
Minimalnie = 10
X = 2
Pozycjaeproma = 1
Call Submenu1
Alarm1 = Parametr
Case 2:
Tekst = " Ustaw Alarm 2 "
Tekst2 = "ßC "
Parametr = Alarm2
Maxymalnie = 80
Minimalnie = 10
X = 3
Pozycjaeproma = 2
Call Submenu1
Alarm2 = Parametr
Case 3:
Tekst = " Ustaw Alarm 3 "
Tekst2 = "ßC "
Parametr = Alarm3
Maxymalnie = 80
Minimalnie = 10
X = 4
Pozycjaeproma = 3
Call Submenu1
Alarm3 = Parametr
Case 4:
Upperline
Lcd " Podswietlenie "
Lowerline
Lcd " w" ; Chr(1) ; Chr(6) ; "cz/wy" ; Chr(1) ; Chr(6) ; "cz "
If S1 = 0 Then
Gosub Obs1
Do
Incr Z
If S2 = 0 Then
Gosub Obs2
Z = 0
Podswietlenie = 0
End If
If S3 = 0 Then
Gosub Obs3
Z = 0
Podswietlenie = 1
End If
'If Podswietlenie = 0 Then
Lowerline
Lcd " Off On "
If S1 = 0 Then
Gosub Obs1
Writeeeprom Light , 4
Exit Do
End If
Waitms 50
Loop Until Z = 255
Lowerline
Lcd " "
Z = 0
Menu = 5
End If
Case 5:
Upperline
Lcd "Ustawianie czasu"
Lowerline
Lcd " "
If S1 = 0 Then
Gosub Obs1
Cursor Off Blink
X = 4
Do
Incr Z
Call Odczyt_rtc
Hdec = Makedec(h)
Mdec = Makedec(m)
If S1 = 0 Then
Gosub Obs1
Decr X
End If
If X = 4 Then
Parametr = Hdec
Maxymalnie = 23
Minimalnie = 0
Kursor = 6
Call Submenu2
Hdec = Parametr
Czas_zapisywany = Makebcd(hdec)
Call Ekran_zegar
Call Zapis_rtc
End If
If X = 3 Then
Parametr = Mdec
Maxymalnie = 59
Minimalnie = 0
Kursor = 9
Call Submenu2
Mdec = Parametr
Czas_zapisywany = Makebcd(mdec)
Call Ekran_zegar
Call Zapis_rtc
End If
If X = 2 Then
Kursor = 12
Call Ekran_zegar
Waitms 100
If S2 = 0 Then
Czas_zapisywany = 0
Gosub Obs2
Call Zapis_rtc
End If
End If
If X = 1 Then
Cursor Off Noblink
Upperline
Lcd " Czas ustawiony !"
Wait 1
Exit Do
End If
Waitms 20
Piszczyk = 0
Loop Until Z = 255
Cls
X = 0
Z = 0
Menu = 6
End If
Case 6:
Upperline
Lcd " -WYJ" ; Chr(4) ; "CIE!- "
If S1 = 0 Then
Gosub Obs1
Goto Koniecmenu3
End If
End Select
Waitms 100
Loop Until Z = 255
Z = 0
Koniecmenu3:
End If
Bufor_flaga = Ischarwaiting()
If Bufor_flaga = 1 Then
C = ""
Do
A = Inkey()
If A <> "" Then
If A = Chr(13) Then Exit Do
C = C + A
End If
Loop
End If
Koniec:
Waitms 100
Loop
End
'***********************************************************
' PRZERWANIA
'***********************************************************
Co5ms:
Timer2 = 50
'***********************************************************
' Pętla wykonywana co 1 s
'***********************************************************
Incr Liczniksekundy '
If Liczniksekundy = 200 Then
Liczniksekundy = 0
If S2 = 0 Then
If S3 = 0 Then
Piszczyk = 1
Wait 1
Piszczyk = 0
For X = 1 To 25
Y = Lookup(x , Tabelaprzywracania)
Writeeeprom Y , X
Next X
Lcd " Dane fabryczne "
Lowerline
Lcd " przywrocone "
Wait 2
End If
End If
Readeeprom Alarm1 , 1
Readeeprom Alarm2 , 2
Readeeprom Alarm3 , 3
Readeeprom Light , 4
Koniec2:
End If
Return