Mikroelektronika MIKROE-350 データシート

ページ / 526
UARTx_Read_Text
473
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6
Prototype
sub procedure UARTx_Read_Text(dim byref Output as string[255],
dim byref Delimiter as string[10], dim Attempts as byte)
Returns
Nothing.
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 proce-
dure exits( if the delimiter is not found). Attempts defines number of received
characters in which Delimiter sequence is expected. If Attempts is set to 255,
this routine will continously try to detect the Delimiter sequence.
Requires
UART HW module must be initialized and communication established before
using this function. See UARTx_Init.
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, 'delim', 10)  ' reads text until
'delim' is found
UART1_Write_Text(output)              ' sends back text 
end if
wend.