Mikroelektronika MIKROE-742 데이터 시트

다운로드
페이지 532
UARTx_Read
UARTx_Read_Text
480
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroPASCAL PRO for AVR
CHAPTER 6
Prototype
function UARTx_Read(): byte;
Returns
Received byte.
Description
The function receives a byte via UART. Use the Uart_Data_Ready function to
test if data is ready first.
Requires
MCU with the UART module.
The UART module must be initialized before using this routine. See UARTx_Init
routine.
Example
var receive: byte;
...
// read data if ready
if (UART1_Data_Ready() = 1) then
receive := UART1_Read();
Prototype
procedure UARTx_Read_Text(var Output : string[255]; var Delimiter
sting[10]; Attempts : 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). Parameter 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.
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 do
begin
if (UART1_Data_Ready() = 1)        // if data is received 
begin  
UART1_Read_Text(output, 'delim', 10); // reads text
until 'delim' is found
UART1_Write_Text(output);          // sends back text 
end;
end.