$regfile = "xm128a3udef.dat"
$crystal = 32000000 '32MHz
$hwstack = 80 'this is for my other tasks so
$swstack = 100 'you can modify values to your needs
$framesize = 100
Debug On
Config Submode = New
$projecttime = 37
$version 0 , 0 , 10
Dim Firmware As String * 32
Firmware = "OBROTOMIERZ Xmega128A3U"
Const Max_usb_in_command_len = 50
Const Max_nex_command_len = 50
' ***************** SYSTEM CLOCK CONFIG **************************
' INTERNAL 32MHz NO PRESCALE
Config Osc = Disabled , 32mhzosc = Enabled , 32khzosc = Enabled
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1
' ENABLING AUTOMATIC OSCILLATOR CALIBRATION
Osc_dfllctrl.0 = 1
Dfllrc32m_ctrl.0 = 1
'*****************************************************************
'********************** CLOCK CONFIG *******************************************
' we select the internal 1 KHz clock from the 32khz Internal Oscillator
Config Clock = Soft , Rtc = 1khz_int32khz_rcosc
Config Priority = Static , Vector = Application , Lo = Enabled , Med = Enabled ' the RTC uses LO priority
'****************************************************************
'********************TIMER ODLICZAJĄCY 1ms*******************
Config Tcf0 = Normal , Prescale = 256
Tcf0_per = 125
'******************************************************************
'*******************KONFIGURACJA PAMIĘCI EEPROM************************
Config Eeprom = Mapped 'Setup memory mode for EEPROM in XMEGA
'Const Updateeprom =
'************ CONFIGURATION FOR COM1 UART_C0************************************
' ' TX-PORTC.3 RX-PORTC.2 com 2 tcp
Config Com1 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
'Open "COM1:" For Binary As #buart_channel 'no need to open any more
Config Serialin0 = Buffered , Size = 128 , Bytematch = None 'for COM1
Config Serialout0 = Buffered , Size = 128
Open "COM1:" For Binary As #1
'Config Input1 = Crlf , Echo = Cr
'Echo On
'
'*******************************************************************************
'*********** CONFIGURATION FOR COM2 UART_C1*************************************
' ' TX-PORTC.7 RX-PORTC.6 (udp com 1 )
'Config Com2 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
'Open "COM2:" For Binary As #buart_channel
'no need to open any more
'Config Serialin1 = Buffered , Size = 128 , Bytematch = None 'for COM2
'Config Serialout1 = Buffered , Size = 128
'Open "COM2:" For Binary As #1
' Config Input2 = Cr , Echo = Cr
'Echo On
'*******************************************************************************
'************ CONFIGURATION FOR COM3 UART_D0************************************
' ' TX-PORTD.3 RX-PORTD.2 wifi
'Config Com3 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
'Open "COM3:" For Binary As #buart_channel 'no need to open any more
'Config Serialin2 = Buffered , Size = 128 , Bytematch = None 'for COM1
'Config Serialout2 = Buffered , Size = 128
'Open "COM3:" For Binary As #2
'Echo On
'
'*******************************************************************************
'************ CONFIGURATION FOR COM4 UART_D1************************************
' ' TX-PORTD.3 RX-PORTD.2 wifi
'Config Com4 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
'Open "COM3:" For Binary As #buart_channel 'no need to open any more
'Config Serialin3 = Buffered , Size = 128 , Bytematch = None 'for COM1
'Config Serialout3 = Buffered , Size = 128
'Open "COM4:" For Binary As #3
'Echo On
'
'*******************************************************************************
'************ CONFIGURATION 'COM5 UART_E0 **************************************
' ' TX-PORTE.3 ' RX-PORTE.2 DEBUG USB COM5
Config Com5 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8 'Asynchroneous
Config Serialin4 = Buffered , Size = Max_usb_in_command_len '128 , Bytematch = None 'for COM4
'Config Serialout4 = Buffered , Size = Max_usb_out_command_len '128
Dim Char As Byte , Cmd_timeout1 As Byte , Got_str1 As Byte
Dim Command1 As String * Max_usb_in_command_len
Open "COM5:" For Binary As #4
Const Usb = 4
'Config Input1 = Crlf , Echo = Cr
' Echo on
'
'*******************************************************************************
'************ CONFIGURATION 'COM6 UART_E1 **************************************
' ' TX-PORTE.3 ' RX-PORTE.2 Xmega_2_SLAVE
'Config Com6 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
'Open "COM5:" For Binary As #buart_channel 'channel 4
'Config Serialin5 = Buffered , Size = 128 , Bytematch = None 'for COM4
'Config Serialout5 = Buffered , Size = 128
'Open "COM6:" For Binary As #5
'Config Input1 = Crlf , Echo = Cr
' Echo on
'
'*******************************************************************************
'************ CONFIGURATION 'COM5 UART_F0 **************************************
' ' TX-PORTE.3 ' RX-PORTE.2 NEXTION LCD COM7
Config Com7 = 9600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8 'Asynchroneous
Dim Cmd_timeout As Byte , Got_str As Byte
'unnecessary
Dim Command As String * Max_nex_command_len
Config Serialin6 = Buffered , Size = Max_nex_command_len 'RX
'Config Serialout6 = Buffered , Size = 128
Open "COM7:" For Binary As #6
Const Nex = 6
'Config Input1 = Crlf , Echo = Cr
' Echo on
'************************ZMIENNE TIMER'a TCF0*****************
Dim Timer_tikx1 As Byte
Dim Timer_tikx10 As Byte
Dim Timer_tikx50 As Byte
Dim Timer_tikx100 As Byte
Dim Timer_tikx500 As Byte
Dim Timer_tikx1000 As Byte
Dim Timer_tik_flag As Byte
'**********************************************************
Config Pina.0 = Input
Config pina.1 = Input
'-----------------------------------------------------------------------------------
Config Portb.7 = Output 'LED_LIVE TEST
Config Xpin = Portb.7 , Outpull = Totem
'------------------------------------------------------------------------------------
'ZMIENNE ENKODERA
Dim En_impuls As Long 'zmienna przechowywujaca impulsy z enkodera
Dim Pomiar1 As Single 'zmienna pomocnicza1
Dim Pomiar2 As Single 'zmienna pomocnicza2
Dim Pomiar3 As Single
Dim Wynik As String * 5 'zmienna pomocnicza4
Dim Wynik1 As Long
'**************ALIASY*********************
Flaga1ms Alias Timer_tik_flag.0
Flaga10ms Alias Timer_tik_flag.1
Flaga50ms Alias Timer_tik_flag.2
Flaga100ms Alias Timer_tik_flag.3
Flaga500ms Alias Timer_tik_flag.4
Flaga1s Alias Timer_tik_flag.5
Flaga2s Alias Timer_tik_flag.6
Led_live Alias Portb.7
'**************************************************
Porta_pin0ctrl = &B00_011_010
Porta_int0mask = &B0000_0001 'include PIN0 in INT0 Mask
On Porta_int0 Port_a_int0__isr
Enable Porta_int0 , Lo
Enable Interrupts
'****************************************************************
Print #usb , "This use COM4" 'print current Uart
Print #usb , "MCU Rev. = " ; Mcu_revid 'version of the MCU
'****************************************************************
Do
'------------------------------------------------
If Tcf0_intflags.0 = 1 Then
Flaga1ms = 1
Incr Timer_tikx1
Tcf0_intflags.0 = 1
End If
'------------------------------------------------
If Timer_tikx1 >= 10 Then
Incr Timer_tikx10
Flaga10ms = 1
Timer_tikx1 = 0
End If
'------------------------------------------------
If Timer_tikx10 >= 5 Then
Incr Timer_tikx50
Flaga50ms = 1
Timer_tikx10 = 0
End If
'------------------------------------------------
If Timer_tikx50 >= 2 Then
Incr Timer_tikx100
Flaga100ms = 1
Timer_tikx50 = 0
End If
'------------------------------------------------
If Timer_tikx100 >= 5 Then
Incr Timer_tikx500
Flaga500ms = 1
Timer_tikx100 = 0
End If
'------------------------------------------------
If Timer_tikx500 >= 2 Then
Incr Timer_tikx1000
Flaga1s = 1
Timer_tikx500 = 0
End If
'======================================
If Flaga1ms = 1 Then
End If
'------------------------------------------------
If Flaga10ms = 1 Then
Flaga10ms = 0
End If
'------------------------------------------------
If Flaga100ms = 1 Then
Flaga100ms = 0
End If
'-----------------------------------------------
If Flaga500ms = 1 Then
Toggle Led_live
Flaga500ms = 0
End If
'------------------------------------------------
If Flaga1s = 1 Then
Debug #usb , "En_impuls " ; En_impuls
Pomiar1 = En_impuls / 1000
Pomiar2 = Pomiar1 * 60
Pomiar3 = Pomiar2
Debug #usb , "wynik " ; wynik
Debug #usb , "OBR/MIN " ; Wynik1
En_impuls = 0
Flaga1s = 0
End If
'****************************************************************
Wynik = Str(pomiar3)
Wynik = Fusing(pomiar3 , "###.#")
Wynik1 = Val(wynik)
Loop
End
'****************************************************************
Const Pina_0_int_flag = 0
Port_a_int0__isr:
Set Porta_intflags.pina_0_int_flag
If pina.0 = 0 Then
If pina.1 = 0 Then
Incr En_impuls
End If
End If
Return