'pompa
$regfile = "m16def.dat"
$crystal = 8000000
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db7 = Pa.2 , Db6 = Pa.3 , Db5 = Pa.4 , Db4 = Pa.5 , E = Pa.6 , Rs = Pa.7
Config Sda = Portb.3
Config Scl = Portb.2
Config Portc = Output
Portc = &B00000000
Config Pinb.1 = Output
Set Portb.1
Ok Alias Pinb.7
Esc Alias Pinb.6
Up Alias Pinb.5
Down Alias Pinb.4
Buzer Alias Portb.1
Dim Sekundy As Byte
Dim Minuty As Byte
Dim Godziny As Byte
Dim Menuu As Byte
Dim Menuk As Byte
Dim Pompa As Byte
Dim Kal As Word
Dim Pompa1 As Byte
Dim K As Long
Dim V As Byte
Dim V1 As Byte
Dim Kaleeprom As Word
Dim A As Byte
Dim B As Long
Dim C As Single
Dim D As Single
Dim E As Long
Dim F As Byte
Dim Kaleepromadr As Byte
Dim Dawkaeepromadr As Byte
Dim Hw As Byte
Dim Mw As Byte
Dim A1 As Byte
Dim B1 As Byte
Dim C1 As Single
Dim D1 As Single
Dim Dawkaeeprom As Byte
Dim H1 As Byte
Dim H2 As Byte
Dim H3 As Byte
Dim H4 As Byte
Dim H5 As Byte
Dim H6 As Byte
Dim H7 As Byte
Dim H8 As Byte
Dim M1 As Byte
Dim M2 As Byte
Dim M3 As Byte
Dim M4 As Byte
Dim M5 As Byte
Dim M6 As Byte
Dim M7 As Byte
Dim M8 As Byte
Dim S1 As Byte
Dim S2 As Byte
Dim S3 As Byte
Dim S4 As Byte
Dim S5 As Byte
Dim S6 As Byte
Dim S7 As Byte
Dim S8 As Byte
Dim Czaseepromadr As Byte
'############# Deklaracja strzalek #############
Deflcdchar 0 , 32 , 14 , 14 , 14 , 31 , 31 , 14 , 4
Deflcdchar 1 , 32 , 4 , 14 , 31 , 31 , 14 , 14 , 14
'############# Ekran powitalny #############
Cls
Cursor Off
Lcd "pompa"
Locate 2 , 5
Lcd "ver 1.13"
Reset Buzer
Waitms 50
Set Buzer
Waitms 100
Reset Buzer
Waitms 50
Set Buzer
Waitms 100
Reset Buzer
Waitms 50
Set Buzer
Wait 2
Cls
Locate 1 , 8
Lcd "by"
Locate 2 , 1
Lcd "helbarad"
Wait 2
Cls
'############# Petla glowna #############
Do
Gosub Odczyt_czasu
Gosub Wyswietl_czas
Gosub Sprawdz_harmonogram
If Ok = 0 Then
Waitms 50
If Ok = 0 Then
Reset Buzer
Waitms 50
Set Buzer
Gosub Menu
End If
End If
Loop
'############# Odczyt_czasu #############
Odczyt_czasu:
I2cstart
I2cwbyte 160
I2cwbyte 2
I2cstart
I2cwbyte 161
I2crbyte Sekundy , Ack
I2crbyte Minuty , Ack
I2crbyte Godziny , Nack
I2cstop
Godziny = Makedec(godziny)
Minuty = Makedec(minuty)
Sekundy = Makedec(sekundy)
Return
'############# Wyswietl_czas #############
Wyswietl_czas:
If Godziny < 10 Then
Locate 1 , 5
Lcd "0" ; Godziny ; ":"
Else
Locate 1 , 5
Lcd Godziny ; ":"
End If
If Minuty < 10 Then
Locate 1 , 8
Lcd "0" ; Minuty ; ":"
Else
Locate 1 , 8
Lcd Minuty ; ":"
End If
If Sekundy < 10 Then
Locate 1 , 11
Lcd "0" ; Sekundy
Else
Locate 1 , 11
Lcd Sekundy
End If
Return
'############# Menu #############
Menu:
Cls
Menuu = 1
Do
Locate 2 , 1
Lcd Chr(1)
Locate 2 , 16
Lcd Chr(0)
Locate 1 , 1
Select Case Menuu
Case Is = 1
Lcd "Harmonogram "
If Ok = 0 Then
Waitms 50
If Ok = 0 Then
Reset Portb.1
Waitms 50
Set Portb.1
Gosub Harmonogram
End If
End If
Case Is = 2
Lcd "Dawka reczna "
If Ok = 0 Then
Waitms 50
If Ok = 0 Then
Reset Portb.1
Waitms 50
Set Portb.1
Gosub Dawka_reczna
End If
End If
Case Is = 3
Lcd "Kalibracja "
If Ok = 0 Then
Waitms 50
If Ok = 0 Then
Reset Portb.1
Waitms 50
Set Portb.1
Gosub Kalibracja
End If
End If
Case Is = 4
Lcd "Zegar "
If Ok = 0 Then
Waitms 50
If Ok = 0 Then
Reset Portb.1
Waitms 50
Set Portb.1
Gosub Ustaw_czas
End If
End If
Case Is = 5
Lcd "Pokaz nastawy"
If Ok = 0 Then
Waitms 50
If Ok = 0 Then
Reset Portb.1
Waitms 50
Set Portb.1
Gosub Pokaz_nastawy
End If
End If
Case Is = 6
Lcd "Reset eeprom "
If Ok = 0 Then
Waitms 50
If Ok = 0 Then
Reset Portb.1
Waitms 50
Set Portb.1
Gosub Reset_eeprom
End If
End If
End Select
If Up = 0 And Menuu < 6 Then
Incr Menuu
Waitms 300
Reset Buzer
Waitms 50
Set Buzer
End If
If Up = 0 And Menuu = 6 Then
Menuu = 1
Waitms 300
Reset Buzer
Waitms 50
Set Buzer
End If
If Down = 0 And Menuu > 1 Then
Decr Menuu
Waitms 300
Reset Buzer
Waitms 50
Set Buzer
End If
If Down = 0 And Menuu = 1 Then
Menuu = 6
Waitms 300
Reset Buzer
Waitms 50
Set Buzer
End If
Loop Until Esc = 0
Reset Buzer
Waitms 50
Set Buzer
Waitms 100
Cls
Return
'############# Ustaw_czas #############
Ustaw_czas:
Cls
Locate 1 , 1
Lcd "Ustaw czas"
Do
Locate 2 , 5
If Godziny < 10 And Minuty < 10 Then
Lcd ">" ; "0" ; Godziny ; "<" ; ":" ; "0" ; Minuty
End If
If Godziny < 10 And Minuty >= 10 Then
Lcd ">" ; "0" ; Godziny ; "<" ; ":" ; Minuty
End If
If Godziny >= 10 And Minuty >= 10 Then
Lcd ">" ; Godziny ; "<" ; ":" ; Minuty
End If
If Godziny >= 10 And Minuty < 10 Then
Lcd ">" ; Godziny ; "<" ; ":" ; "0" ; Minuty
End If
If Up = 0 And Godziny < 23 Then
Reset Buzer
Waitms 50
Set Buzer
Incr Godziny
Waitms 300
End If
If Up = 0 And Godziny = 23 Then
Reset Buzer
Waitms 50
Set Buzer
Godziny = 0
Waitms 300
End If
If Down = 0 And Godziny > 0 Then
Reset Buzer
Waitms 50
Set Buzer
Decr Godziny
Waitms 300
End If
If Down = 0 And Godziny = 0 Then
Reset Buzer
Waitms 50
Set Buzer
Godziny = 23
Waitms 300
End If
If Esc = 0 Then
Reset Buzer
Waitms 50
Set Buzer
Waitms 100
Cls
Return
End If
Loop Until Ok = 0
Reset Buzer
Waitms 50
Set Buzer
Waitms 100
Cls
Locate 1 , 1
Lcd "Ustaw czas"
Do
Locate 2 , 6
If Godziny < 10 And Minuty < 10 Then
Lcd "0" ; Godziny ; ":" ; ">" ; "0" ; Minuty ; "<"
End If
If Godziny >= 10 And Minuty >= 10 Then
Lcd Godziny ; ":" ; ">" ; Minuty ; "<"
End If
If Godziny >= 10 And Minuty < 10 Then
Lcd Godziny ; ":" ; ">" ; "0" ; Minuty ; "<"
End If
If Godziny < 10 And Minuty >= 10 Then
Lcd "0" ; Godziny ; ":" ; ">" ; Minuty ; "<"
End If
If Up = 0 And Minuty < 59 Then
Reset Buzer
Waitms 50
Set Buzer
Incr Minuty
Waitms 300
End If
If Up = 0 And Minuty = 59 Then
Reset Buzer
Waitms 50
Set Buzer
Minuty = 0
Waitms 300
End If
If Down = 0 And Minuty > 0 Then
Reset Buzer
Waitms 50
Set Buzer
Decr Minuty
Waitms 300
End If
If Down = 0 And Minuty = 0 Then
Reset Buzer
Waitms 50
Set Buzer
Minuty = 59
Waitms 300
End If
If Esc = 0 Then
Reset Buzer
Waitms 50
Set Buzer
Waitms 100
Cls
Return
End If
Loop Until Ok = 0
Reset Buzer
Waitms 50
Set Buzer
Sekundy = 0
Gosub Zapis_czasu
Waitms 100
Cls
Return
'############# Zapis_czasu #############
Zapis_czasu:
Godziny = Makebcd(godziny)
Minuty = Makebcd(minuty)
Sekundy = Makebcd(sekundy)
I2cstart
I2cwbyte 160
I2cwbyte 0
I2cwbyte 8
I2cstop
I2cstart
I2cwbyte 160
I2cwbyte 2
I2cwbyte Sekundy
I2cwbyte Minuty
I2cwbyte Godziny
I2cstop
Return
'############# Reset_eeprom #############
Reset_eeprom:
If Up = 0 And Down = 0 Then
Waitms 500
If Up = 0 And Down = 0 Then
F = 0
Reset Buzer
Waitms 50
Set Buzer
Cls
Lcd "Reset eeprom"
For A = 1 To 56
Writeeeprom F , A
Next
Wait 1
Cls
End If
End If
Return
'############# Pokaz_nastawy #############
Pokaz_nastawy:
Return
'############# Kalibracja #############
Kalibracja:
Return
'############# Harmonogram #############
Harmonogram:
Return
'############# Dawka_reczna #############
Dawka_reczna:
Return
'############# Sprawdz_harmonogram #############
Sprawdz_harmonogram:
Return
'############# Odmierz_dawke_czas #############