Ports for Embedded SystemsAn hserin statement can read a byte at the serial port:
serial_in var byteif (PIR1.5 = 1) then' A byte is available. Read it.hserin [serial_in]
endif
Instead of checking RCIF before calling hserin, a statement can call hserin with
a timeout that jumps to a label if a byte doesn’t arrive. Reading RCIF is more
efficient because the code doesn’t waste time waiting, but a timeout can be use-
ful if the application is expecting data and has no other urgent tasks.
serial_in var byte
timeout var wordtimeout = 1000' Wait for a byte on the serial port.hserin timeout, give_up, [serial_in]' A byte was received. Do something with it.' Jump here if hserin times out.give_up: The DataRdyUSART function returns 1 when RCIF =1. The getcUSART
function reads a byte from the port. The ReadUSART function is identical to
getcUSART.
unsigned char serial_in;
if DataRdyUSART()
{
// A byte is available.serial_in = getcUSART();
}