'============================================
' (c) 2020, enniom
' BASCOM AVR Programmer's Assistant
'
' Sample code interfacing with Python GUI
'============================================
$regfile = "xm192a3udef.dat"
$hwstack = 128
$swstack = 128
$framesize = 128
$version 1 , 0 , 22
'============================================
'====[ Config XMega Clock ]===================
'============================================
Osc_dfllctrl.0 = 1
Dfllrc32m_ctrl.0 = 1 'enable CALIBRATION
$crystal = 32000000
Config Osc = Disabled , 32mhzosc = Enabled ' 32 MHz enabled
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1 'use 32 MHz
'============================================
'====[ USART XMega ]=========================
'============================================
'(
COM1 - Uart_c0 Portc.3 Portc.2 Serialin Or Serialin0
COM2 - UART_C1 PORTC.7 PORTC.6 SERIALIN1
Com3 - Uart_d0 Portd.3 Portd.2 Serialin2
COM4 - UART_D1 PORTD.7 PORTD.6 SERIALIN3
COM5 - Uart_e0 Porte.3 Porte.2 Serialin4
Com6 - Uart_e1 Porte.7 Porte.6 Serialin5
COM7 - UART_F0 PORTF.3 PORTF.2 SERIALIN6
COM8 - Uart_f1 Portf.7 Portf.6 Serialin7
')
Config Serialin6 = Buffered , Size = 64 , Bytematch = &H7F
Config Serialout6 = Buffered , Size = 64 'Uses USARTF0_DRE Interrupt
Config Com7 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Open "COM7:" For Binary As #1
Dim Column As Byte At _rs232inbuf7(3) Overlay
Dim Msg_ovl As String * 3 At _rs232inbuf7(5) Overlay
Dim Usart_ready As Byte
'============================================
'====[ Interrupt Priority ]==================
'============================================
Config Priority = Static , Vector = Application , Lo = Enabled , Med = Enabled , Hi = Enabled
Usartf0_ctrla.5 = 1 : Usartf0_ctrla.4 = 1 'set high priority interrupt
'============================================
'====[ Config SOFT Clock ]===================
'============================================
Config Clock = Soft , Rtc = 1khz_int32khz_ulp , Gosub = Sectic 'select internal 1 KHz clock from the 32KHz internal oscillator
Config Date = Mdy , Separator = Dot
Date$ = "02.01.20" : Time$ = "00:00:00"
Dim Long_time As Long
Long_time = Syssec()
'============================================
'====[ Timer Example ]=======================
'============================================
Config Tcc1 = Normal , Prescale = 1024 , Resolution = Normal
Tcc1_per = &HFFFF ' period register
On Tcc1_ovf Example_timer_isr
Enable Tcc1_ovf , Lo
Start Tcc1
Dim Timer_ready As Byte
'====[ Scratchpad Vars ]=====================
Dim I As Byte
Enable Interrupts
'====[ Setup Programmer Assistant ]==========
Print #1 , "T,A," ; "TIMER TCC1" ; "," 'Column "A" Title
Print #1 , "A,1," ; "TCC1_CNT" ; "," 'Use Comma-Delimited Messages
Print #1 , "A,4," ; "Timer_ready" ; "," 'messages must end with "," CRLF
Print #1 , "B,1," ; "Hello World" ; "," 'Comment inserted in COL "B" ROW 1
Print #1 , "T,C," ; "XMega RTC" ; "," 'Column "C" TITLE
Print #1 , "C,1," ; "uC_Time" ; ","
Print #1 , "T,F," ; "What We Know" ; "," 'Various examples
Print #1 , "F,1," ; "XMega " ; _xmega ; "," 'Columns and Rows are addressable (eg: Excel)
Print #1 , "F,2," ; "Clk " ; _xtal ; ","
Print #1 , "F,3," ; "Num USARTS " ; _uarts ; ","
Print #1 , "F,12," ; "Loop Count" ; ","
Waitms 50
'============================================
'====[ Main Loop ]===========================
'============================================
Do
'(
Perform Other Tasks
')
Incr I 'loop count
Waitms 50 'This may be reduced for PC's with fast processors
'====[ Example Updates Using LIVE DATA ]=======
'====[ This replaces messages normally ]=======
'====[ sent to terminal program .... ]=======
Print #1 , "A,2," ; Hex(tcc1_cnt) ; "," 'all Printable forms are supported
Print #1 , "A,5," ; Timer_ready ; ","
Print #1 , "C,3," ; Time$ ; ","
Print #1 , "F,13," ; I ; "," 'Addressable ROW range is 1-13
Print #1 , "G,1," ; Timer_ready ; "," '"G,1" sends Data Feed to REAL-TIME Graph
If Timer_ready > 0 Then Timer_ready = 0
'====[ Example Sending Messages to uC ]=======
'====[ This replaces messages normally ]=======
'====[ sent from terminal program .. ]=======
If Usart_ready = 1 Then
Select Case Column 'A to F
Case 65
Case 66
Case 67
Print #1 , "C,13," ; Usart_ready ; ","
_hour = Val(msg_ovl)
Long_time = Syssec()
Case 68
Case 69
Case 70
End Select
Clear Serialin6
Usart_ready = 0
Else
If _sec = 0 Then Print #1 , "C,13," ; Usart_ready ; ","
End If
Loop
End 'Main Loop
'============================================
'====[ Interrupt Routines ]==================
'============================================
Serial6charmatch:
'Pushall
Usart_ready = 1
'Popall
Return
Example_timer_isr:
Incr Timer_ready
Return
Sectic:
Incr Long_time
Return |