Mikroelektronika MIKROE-442 Datenbogen
626
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
UARTx_Read_Text
Prototype
sub procedure UARTx_Read_Text(dim byref output, delimiter as string; dim
Attempts as byte)
Description Reads characters received via UART until the delimiter sequence is detected. The read sequence is
stored in the parameter
output
; delimiter sequence is stored in the parameter
delimiter
.
This is a blocking call: the delimiter sequence is expected, otherwise the procedure exits (if the
delimiter is not found).
Parameters -
Output
: received text
-
Delimiter
: sequence of characters that identifies the end of a received string
-
Attempts
: defines number of received characters in which
Delimiter
sequence is expected. If
Attempts
is set to 255, this routine will continuously try to detect the
Delimiter
sequence.
Returns
Nothing.
Requires
Routine requires at least one UART module.
Used UART module must be initialized before using this routine. See UARTx_Init and UARTx_Init_
Advanced routines.
Example
Read text until the sequence “OK” is received, and send back what’s been received:
UART1_Init(4800) ‘ initialize UART module
Delay_ms(100)
while TRUE
if (UART1_Data_Ready() = 1) ‘ if data is received
UART1_Read_Text(output, “OK”, 10) ‘ reads text until ‘OK’ is found
UART1_Write_Text(output) ‘ sends back text
end if
wend.
Notes
UART library routines require you to specify the module you want to use. To select the desired UART
module, simply change the letter
x in the routine prototype for a number from 1 to 4.
Number of UART modules per MCU differs from chip to chip. Please, read the appropriate datasheet
before utilizing this library.