Chapter 11
An hserin statement can return on receiving a specified value or receiving the
specified number of bytes, whichever comes first. This statement waits to
receive 10 bytes or a CR code:
hserin [STR received_text\10\$0d]
Another option is to store bytes as they arrive and check each byte for the CR
code. Reading individual bytes in a task loop eliminates blocking while waiting
for the CR.
index var byte
received_data var byte[80]
receive_serial_data:
if (PIR1.5 = 1) then
' A byte is available to read.
hserin [received_data[index]]
if received_data[index] = 13 then
' It's a CR code. Do something with the received data.
' Reset the index.
index = 0
else
' Increment the index, resetting to 0 if the buffer is full.
if index < 79 then
index = index + 1
else
index = 0
endif
endif
endif
return