
Originally Posted by
CuriousOne
Can we see that code?
It is very interesting...
Code:
' Define the input serial port
DEFINE HSER_RXSTA 64
DEFINE HSER_RCSTA 128
DEFINE HSER_BAUD 9600
DEFINE HSER_CLROERR 1
' Define the size of the ring buffer
DEFINE BUFFER_SIZE 16
' Define the ring buffer
DIM buffer(BUFFER_SIZE) AS BYTE
DIM buffer_start AS BYTE
DIM buffer_end AS BYTE
' Initialize the buffer pointers
buffer_start = 0
buffer_end = 0
' Define the interrupt handler for receiving data on the serial port
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler HSER_RX_INT, _receive_data, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
' Define the subroutine to handle incoming data on the serial port
_receive_data:
' Read the incoming byte
buffer(buffer_end) = HSER_RCREG
' Update the buffer pointer
buffer_end = (buffer_end + 1) MOD BUFFER_SIZE
' Return from the interrupt
RETURN
' Main program loop
DO
' Check if there is data in the buffer
IF buffer_end <> buffer_start THEN
' Read the next byte from the buffer
BYTE next_byte = buffer(buffer_start)
' Do something with the byte here...
' Update the buffer pointer
buffer_start = (buffer_start + 1) MOD BUFFER_SIZE
ENDIF
' Insert a delay to avoid consuming too much processing power
PAUSE 10
LOOP
This program defines the input serial port using the DEFINE statement, sets the size of the ring buffer, and initializes the buffer pointers. It then defines an interrupt handler for receiving data on the serial port, which reads incoming bytes and stores them in the buffer. Finally, it sets up a main program loop that reads bytes from the buffer and processes them, and inserts a PAUSE statement to avoid consuming too much processing power. You may need to modify this program slightly to fit your specific requirements, but it should provide a good starting point.
All the above was the chatGPT answer to a Ring buffer request, including the last paragrapgh, explaining what it did! Very interesting although with some errors.
Ioannis
Bookmarks