Hi,
This is totally untested but could serve as a starting point for a polled receive buffer. Short of this you need to use interrupts to receive the data in the background but I suspect that with your timing sensetive loop even that might cause to much problem.
Code:
RC1IF VAR PIR1.5 'Alias to Interrupt request bit for USART1, double check against datasheet.
RxData VAR BYTE[5]
Value VAR WORD
ByteCount VAR BYTE
TestVar1 VAR WORD
TestVar2 VAR WORD
ByteCount = 0 ' Reset buffer pointer.
Main:
' Main loop has to run faster than the bytes can arrive.
If RC1IF THEN ' Is there a byte in the receive buffer?
HSERIN[RxData[ByteCount]] ' Get it and put in the buffer array, RCIF will be cleared by the hardware.
IF ByteCount = 4 THEN ' Do we have 5 bytes yet?
GOSUB ProcessFrame 'If so go process them...
ELSE
ByteCount = ByteCount + 1 ' If not, get ready for the next.
ENDIF
ENDIF
Goto Main
ProcessFrame:
ByteCount = 0 ' Get ready for next frame.
' Now convert the next 4 bytes from ASCII to a numeric value.
' Could probably use ArrayRead here instead.
Value = (RXData[1] - 48) * 1000
Value = Value + ((RxData[2] - 48) * 100)
Value = Value + ((RxData[3] - 48) * 10)
Value = Value + (RxData[4] - 48)
If RxData[0] = "A" THEN
TestVar1 = Value
ENDIF
If RxData[0] = "B" THEN
TestVar2 = Value
ENDIF
RETURN
/Henrik.
Bookmarks