$crystal = 8000000
$regfile "m16def.dat"
'*********************zmienne************************************
Dim Objetosc As Single
Dim Zapis As Byte
Dim Odczyt As Byte
Dim Adres As Word
Dim Adresa As Byte At Adres Overlay
Dim Adresb As Byte At Adres + 1 Overlay
Dim Flagamenu As Bit
Flagamenu = 0
Dim Flagalcd As Bit
Flagalcd = 1
Dim Menuselect As Byte
Menuselect = 1
Dim Lcdl As Byte
Dim Wt As Bit
Wt = 1
Dim Clsflag As Bit
Clsflag = 0
Dim Direct_flag As Bit
Dim Glowna As Word
Glowna = 0
Dim Pomolcd As Byte
Pomolcd = 0
Dim Objetosc_lcd As String * 3
'****************************************************************
'************zmienna objętości gazu**************************
Dim Gas As Long
Dim Gasa As Byte At Gas Overlay
Dim Gasb As Byte At Gas + 1 Overlay
Dim Gasc As Byte At Gas + 2 Overlay
Dim Gasd As Byte At Gas + 3 Overlay
'************************************************************
'***************procedury************************************
Declare Sub Menu
'***************koniec procedur******************************
'***********************timer1****************************
Config Timer1 = Timer , Prescale = 64 , Compare A = Toggle , Clear Timer = 1
Config Pind.5 = Output
Set Pind.5
Enable Interrupts
Enable Timer1
Ocr1ah = High(310)
Ocr1al = Low(310)
Tccr1a.com1a1 = 0
Tccr1a.com1a0 = 1
Tccr1a.com1b1 = 0
Tccr1a.com1b0 = 1
' ustawiamy Timer1 w tryb CTC - porównywanie z OCR1A
Tccr1a.wgm11 = 0
Tccr1a.wgm10 = 0
'*********************koniec timer1**************************
'*****************przerwanie INT0****************************
Config Pind.2 = Input
Set Pind.2
Config Int0 = Rising 'przerwanie nastąpi podczas trwania opadającego zbocza impulsu z enkodera
On Int0 Dodaj
'gdy processor otrzyma przerwanie wykona procedurę zwiększenia wartości ilości gazu.
Enable Int0
'**********************************************************
'*************************LCD******************************
Config Lcd = 20 * 4
Config Lcdpin = Pin , Db4 = Portb.2 , Db5 = Portb.3 , Db6 = Portb.4 , Db7 = Porta.0 , E = Portb.1 , Rs = Portb.0
Display On
Cursor Off
'**********************************************************
'*************************konfiguracja SPI***********************************
Config Pina.1 = Output
Set Porta.1
Cs Alias Porta.1
Config Spi = Hard , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Noss = 1
Zapis = 2
Odczyt = 3
Spiinit
'*************************************************************
'*********Definicje przycisków********************************
Config Pinc.2 = Input
Set Portc.2
Pup Alias Pinc.2
Config Pinc.3 = Input
Set Portc.3
Pdown Alias Pinc.3
Config Pind.7 = Input
Set Portd.7
Pok Alias Pind.7
Config Pind.3 = Input
Set Portd.3
Pright Alias Pind.3
Config Pind.4 = Input
Set Portd.4
Pleft Alias Pind.4
Config Pind.6 = Output
Set Portd.6
Direct Alias Portd.6
Config Pinc.4 = Input
Set Portc.4
Kmax Alias Pinc.4
Config Pinc.5 = Input
Set Portc.5
Kmin Alias Pinc.5
'*************************************************************
'**********************konfiguracja I2C*************************
Config Scl = Portc.0
Config Sda = Portc.1
'***************************************************************
'*************************odczyt z SPI************************
Waitms 20
Cls
'--------pierwszy bajt------
Adres = 0
Cs = 1
Cs = 0
Spiout Odczyt , 1
Spiout Adresa , 1
Spiout Adresb , 1
Spiin Gasa , 1
Cs = 1
'---------------------------
'--------drugi bajt------
Adres = 1
Cs = 1
Cs = 0
Spiout Odczyt , 1
Spiout Adresa , 1
Spiout Adresb , 1
Spiin Gasb , 1
Cs = 1
'---------------------------
'--------trzeci bajt------
Adres = 2
Cs = 1
Cs = 0
Spiout Odczyt , 1
Spiout Adresa , 1
Spiout Adresb , 1
Spiin Gasc , 1
Cs = 1
'---------------------------
'--------czwarty bajt------
Adres = 3
Cs = 1
Cs = 0
Spiout Odczyt , 1
Spiout Adresa , 1
Spiout Adresb , 1
Spiin Gasd , 1
Cs = 1
'---------------------------
'**************************************************************
Do
Incr Glowna
If Glowna = 255 Then
Glowna = 0
'--------------------poruszanie strzykawką-----------------------------
If Kmax = 0 Then
Direct_flag = 0
End If
If Kmin = 0 Then
Direct_flag = 1
End If
If Direct_flag = 0 Then
Direct = 1
End If
If Direct_flag = 1 Then
Direct = 0
End If
'--------------------koniec poruszania---------------------------------
'-----------------wysyłka przez RS-232---------------------------------
'------------------koniec wysyłki---------------------------------------
'------------wysyłka I2C--------------------------------------------------
'I2csend &H40 , Dana
'Waitms 500
'------------------koniec wysyłki--------------------------------------
'****************Wywołąnie Menu*******************************************
If Pok = 0 Then
Flagamenu = 1
Flagalcd = 0
End If
If Flagamenu = 1 Then
Call Menu
End If
'********************koniec wywołania*************************************
'***************Zapis SPI**************************************
'--------------pierwszy bajt------------
Adres = 0
Cs = 1
Cs = 0
Spiout Zapis , 1
Spiout Adresa , 1
Spiout Adresb , 1
Spiout Gasa , 1
Cs = 1
'---------------------------------------
'--------------drugi bajt------------
Adres = 1
Cs = 1
Cs = 0
Spiout Zapis , 1
Spiout Adresa , 1
Spiout Adresb , 1
Spiout Gasb , 1
Cs = 1
'---------------------------------------
'--------------trzeci bajt------------
Adres = 2
Cs = 1
Cs = 0
Spiout Zapis , 1
Spiout Adresa , 1
Spiout Adresb , 1
Spiout Gasc , 1
Cs = 1
'---------------------------------------
'--------------czwarty bajt------------
Adres = 3
Cs = 1
Cs = 0
Spiout Zapis , 1
Spiout Adresa , 1
Spiout Adresb , 1
Spiout Gasd , 1
Cs = 1
'---------------------------------------
'**************************************************************
Incr Pomolcd
If Flagalcd = 1 And Pomolcd = 255 Then
Pomolcd = 0
Objetosc = Gas * 0.0087
'Objetosc_lcd = Fusing(objetosc , "#.&&&")
Locate 1 , 4
Lcd "meter work"
Locate 3 , 1
Lcd "Obj. = " ; Objetosc
End If
End If
Loop
End
'*********************Menu***************************
Menu:
Locate 1 , 3
Lcd "***** Menu *****"
If Pup = 0 Then
Incr Menuselect
Cls
End If
If Pdown = 0 Then
Decr Menuselect
Cls
End If
Select Case Menuselect
Case 1:
Locate 4 , 1
Lcd "press -> or <- "
Locate 2 , 1
Lcd "1. LCD light: " ; Lcdl ; " "
Locate 3 , 1
Lcd " "
If Pright = 0 Then
Incr Lcdl
Cls
End If
If Pleft = 0 Then
Decr Lcdl
Cls
End If
If Lcdl = 11 Then
Lcdl = 0
End If
If Lcdl = 255 Then
Lcdl = 10
End If
'*********
Case 2:
Locate 4 , 1
Lcd "press -> or <- "
Locate 2 , 1
Lcd "2. Work type:"
If Pright = 0 Then
Wt = 0
Cls
End If
If Pleft = 0 Then
Wt = 1
Cls
End If
If Wt = 1 Then
Locate 3 , 1
Lcd " - Gas pump"
End If
If Wt = 0 Then
Locate 3 , 4
Lcd " - Gas meter"
End If
Case 3:
Locate 2 , 1
Lcd "3. EXIT MENU"
Locate 3 , 1
Lcd "If Yes press: OK"
If Pok = 0 Then
Waitms 50
If Pok = 0 Then
Flagamenu = 0
Flagalcd = 1
Menuselect = 1
Waitms 60
Cls
End If
End If
Case 4:
Locate 2 , 1
Lcd "4. Clear gas measure"
Locate 3 , 1
Lcd "If Yes press OK"
If Pok = 0 Then
Gas = 0
Locate 4 , 1
Lcd "Saved: Gas = 0"
End If
End Select
Return
'**************** Zwiększanie wartości policzonej gazu ****************************
Dodaj:
If Direct_flag = 1 Then
Gas = Gas + 1
End If
Return
'********************************************