$regfile = "m32def.dat"
$crystal = 16000000
$hwstack = 255
$swstack = 128
$framesize = 128
Config Submode = New
'--------------------------------------------------------------------
$projecttime = 2
$version 0 , 0 , 218
Dim Firmware As String * 32
Firmware = "Obrotomierz TYTAN 750"
'Debug Off
Debug On
'-------------------------------------------------------------------
'KONFIGURACJA TIMERA
Config Timer1 = Timer , Prescale = 8
On Timer1 Przertimer1
Enable Timer1
'--------------------------------------------------------------------
'KONFIGURACFJA ENKODERA
'Config Int0 = Falling
'On Int0 Enkoder
'Enable Int0
'--------------------------------------------------------------------
'Enable Interrupts
'--------------------------------------------------------------------
'KONFIGURACJA LCD
Config Lcdpin = Pin , Db4 = Porta.0 , Db5 = Porta.1 , Db6 = Porta.2 , Db7 = Porta.3 , E = Porta.4 , Rs = Porta.5 'mirley UPT M16
Config Lcd = 16 * 4
'--------------------------------------------------------------------
'KONFIGURACJA PORTÓW
Config Portd.2 = Input : Portd.2 = 1 'enkoder kanał A
Config Portd.3 = Input : Portd.3 = 1 'enkoder kanał B
Config Portd.6 = Output : Portd.6 = 1 'LED Live
Config Portb.0 = Input ': Pinb.0 = 1 'sw_menu
Config Portb.1 = Input : 'sw_zero_kąt
Portb = &B11111111
'--------------------------------------------------------------------
'ALIASY PORTÓW
Kanal_a Alias Pind.2
Kanal_b Alias Pind.3
Led_live Alias Portd.6
Sw_menu Alias Pinb.0
Sw_zero_kat Alias Pinb.1
'--------------------------------------------------------------------
'ZMIENNE ENKODERA
Dim En_impuls As Long 'zmienna przechowywujaca impulsy z enkodera
'--------------------------------------------------------------------
'ZMIENNE CZASU
Dim Timer_tikx10 As Byte 'zmienna liczaca przepełnienie timera
Dim Timertikx100 As Byte 'zmienna liczaca przepełnienie timera x10
Dim Timertikx200 As Byte 'zmienna liczaca przepełnienie timera x 20
Dim Timertikx500 As Byte 'zmienna liczaca przepełnienie timera x 50
Dim Timer_tik_flag As Byte
Flaga10ms Alias Timer_tik_flag.0
Flaga100ms Alias Timer_tik_flag.1
Flaga500ms Alias Timer_tik_flag.2
Flaga1s Alias Timer_tik_flag.3
Flaga2s Alias Timer_tik_flag.4
Flaga2_5s Alias Timer_tik_flag.5
'zostaly jeszce trzy wolne flagi
' a uzylem tylko jednego bajtu
'####################################################################
'ZMIENNE POMIARU OBROTÓW
Dim Pomiar1 As Single 'zmienna pomocnicza1
Dim Pomiar2 As Single 'zmienna pomocnicza2
Dim Pomiar3 As Single 'zmienna pomocnicza3
Dim Wynik As String * 5 'zmienna pomocnicza4
Dim Wynik1 As Long
'-----------------------------------------------------------------------
'ZMIENNE POMIARU KĄTA
Dim Kat_ As Word
Dim Kat_1 As Single
'-----------------------------------------------------------------------
'ZMIENNE MENU
Dim Poz_menu As Byte 'zmienna menu
Dim Wyswietl_ As Byte 'zmiennawyboru wyświetlania
'----------------------------------------------------------------------------
'ZMIENNE PRZYCISKU ENKODERA
Dim Sw_cnt As Word
Dim Lock As Byte
'----------------------------------------------------------------------------
$include "subs\mruganie.inc"
$include "subs\wyswietl.inc"
'$include "subs\pomiar.inc"
'-------------------------------------------------------------------
'Enable Interrupts
'----------------------------------------------------------------------------
'KONFIGURACFJA ENKODERA
Config Int0 = Falling
On Int0 Enkoder
Enable Interrupts
Enable Int0
Waitms 500
Cursor Off
Cursor Noblink
Cls
Poz_menu = 0
'----------------------------------------------------------------------------
Do
'====================================================================
If Timer_tikx10 >= 10 Then 'jeśli uplyneło 100ms to
Flaga100ms = 1 'ustaw flage upłyneło 100ms
Incr Timertikx100 'zwiększaj Timertikx100
Timer_tikx10 = 0 'zeruj liczenie
End If 'koniec warunku
If Timertikx100 >= 10 Then 'jeśli uplynela sekunda
Flaga1s = 1 'ustaw flage upłyneła sekunda
Incr Timertikx200 'zwiększaj Timertikx200
Incr Timertikx500
Timertikx100 = 0 'zeruj liczenie
End If 'koniec warunku
If Timertikx200 >= 2 Then 'jeśli upłyneły dwie sekundy
Flaga2s = 1 'ustaw flagę upłyneły dwie sekundy
Timertikx200 = 0 'zeruj liczenie
End If 'koniec warunku
If Timertikx500 >= 5 Then
Flaga500ms = 1
Timertikx500 = 0
End If
'=====================================================================
If Flaga10ms = 1 Then 'jeśli Flaga10ms jest równa 1
Flaga10ms = 0 'wyzeruj Flaga10ms 'dopisano 19.06.2018
End If 'koniec warunku
'---------------------------------------------------------------------------------------------------
If Flaga100ms = 1 Then 'jeśli Flaga100ms jest równa 1
Flaga100ms = 0 'wyzeruj Flaga100ms
End If 'koniec warunku
'--------------------------------------------------------------------------------------------------
If Flaga500ms = 1 Then 'jeśli Flaga500ms jest równa 1
Flaga500ms = 0 'wyzeruj Flaga500ms
End If 'koniec warunku
'---------------------------------------------------------------------------------------------------
If Flaga1s = 1 Then 'jeśli Flaga1s jest równa 1
Mruganie
Wyswietl
'Pomiar
Pomiar1 = En_impuls / 1000 '720
Pomiar2 = Pomiar1 * 60
Pomiar3 = Pomiar2
En_impuls = 0
Flaga1s = 0 'wyzeruj Flaga1s
End If 'koniec warunku
'---------------------------------------------------------------------------------------------------
If Flaga2s = 1 Then 'jeśli Flaga2s jest równa 1
Flaga2s = 0 'wyzeruj Flaga
End If
'koniec warunku
If Sw_menu = 0 Then
Poz_menu = Poz_menu + 1
End If
If Poz_menu = 0 Then
Wyswietl_ = 0
End If
If Poz_menu = 1 Then
Wyswietl_ = 1
End If
If Poz_menu = 2 Then
Poz_menu = 0
End If
If Sw_zero_kat = 0 Then
Kat_1 = 0
End If
If Kat_ > 720 Then
Kat_ = 0
End If
Kat_1 = Kat_ / 2
Loop
End
'-----------------------------------------------------------------------------------------------------
' podprogram przerwań Timer1
Przertimer1:
Timer1 = 45536 'wstawienie do Timer1 wartości 45536
Incr Timer_tikx10
If Timer_tikx10 = 1 Then
Set Flaga10ms
End If
Return 'powrót
'-----------------------------------------------------------------------------------------------------
Enkoder:
Disable Int0
'Waitms 1
If Kanal_a = 0 Then
If Kanal_b = 0 Then
Incr En_impuls
Incr Kat_
Else
Decr Kat_
End If
End If
Enable Int0
Return
'------------------------------