After teaching it the correct variable syntax here is the revised program. Note that ASM is not used this time:
Code:
'PIC18FxxK22 Configuration Bit Settings
'CONFIG1H
#CONFIG
FOSC = INTIO67 'Internal oscillator block, port function on RA6 and RA7
PLLCFG = ON '4X PLL Enable (Oscillator multiplied by 4)
PRICLKEN = ON 'Primary clock is always enabled
FCMEN = OFF 'Fail-Safe Clock Monitor disabled
IESO = OFF 'Oscillator Switchover mode disabled
#ENDCONFIG
'CONFIG2L
#CONFIG
PWRTEN = ON 'Power up timer enabled
BOREN = SBORDIS 'BOR enabled in hardware (SBOREN is ignored)
BORV = 2 'Brown-out Reset Voltage bits (2.7V)
BORPWR = ZPBORMV 'BORMV set to ZPBORMV instead of ZPBORMV42
WDTEN = OFF 'WDT disabled (control is placed on SWDTEN bit)
WDTPS = 32768 'Watchdog timer postscaler
#ENDCONFIG
'CONFIG2H
#CONFIG
CCP2MX = PORTC1 'CCP2 input/output is multiplexed with RC1
PBADEN = OFF 'PORTB<5:0> pins are configured as digital I/O on reset
LPT1OSC = OFF
#ENDCONFIG
' Declare variables
RingBuffer var Byte[16] ' Ring buffer to store received data
RxBufIndex var Byte ' Index to the next empty location in the ring buffer
RxCtr var Byte ' Counter to keep track of the number of received bytes
RxByte var Byte ' Variable to store the received byte
' Initialize variables
RxBufIndex = 0 ' Start from the beginning of the ring buffer
RxCtr = 0 ' No bytes received yet
' Main program loop
Do
' Check if there is any data available in the UART receive buffer
If UART1_Data_Ready() Then
' Read the received byte from the UART receive buffer
RxByte = UART1_Read()
' Store the received byte in the ring buffer
RingBuffer[RxBufIndex] = RxByte
' Update the index to the next empty location in the ring buffer
RxBufIndex = (RxBufIndex + 1) Mod 16
' Increment the counter to keep track of the number of received bytes
RxCtr = RxCtr + 1
' Check if all 16 bytes have been received
If RxCtr = 16 Then
' Do something with the received data
' Reset the counter and start over
RxCtr = 0
End If
End If
Loop
Ioannis
Bookmarks