UART Remappable Library
UART Remappable hardware module is available with these MCUs: 18F2xJ11, 18F4xJ11, 18F2xJ50 and 18F4xJ50. mikroPascal PRO for PIC UART Remappable Library provides comfortable work with the Asynchronous (full duplex) mode.
You can easily communicate with other devices via RS-232 protocol (for example with PC, see the figure at the end of the topic – RS-232 HW connection). Then, simply use the functions listed below.

Library Dependency Tree

Library Routines
- UART_Remappable_Init
- UART_Remappable_Data_Ready
- UART_Remappable_Tx_Idle
- UART_Remappable_Read
- UART_Remappable_Read_Text
- UART_Remappable_Write
- UART_Remappable_Write_Text
UART_Remappable_Init
Prototype |
procedure UART_Remappable_Init(const baud_rate: longint); |
---|---|
Returns |
Nothing. |
Description |
Initializes hardware UART Remappable module with the desired baud rate. Refer to the device data sheet for baud rates allowed for specific Parameters :
![]() Refer to the device data sheet for baud rates allowed for specific Fosc. |
Requires |
You'll need PIC MCU with hardware UART module and remappable feature.
![]() Therefore, compiler needs to know the value of the parameter in the compile time. That is why this parameter needs to be a constant, and not a variable. |
Example |
This will initialize hardware UART module and establish the communication at 2400 bps: UART_Remappable_Init(2400); |
UART_Remappable_Data_Ready
Prototype |
function UART_Remappable_Data_Ready(): byte; |
---|---|
Returns |
Function returns 1 if data is ready or 0 if there is no data. |
Description |
The function tests if data in receive buffer is ready for reading. |
Requires |
MCU with the UART module and remappable feature. The UART module must be initialized before using this routine. See the UART_Remappable_Init routine. |
Example |
var receive: byte; ... // read data if ready if (UART_Remappable_Data_Ready() = 1) then receive := UART_Remappable_Read(); |
UART_Remappable_Tx_Idle
Prototype |
function UART_Remappable_Tx_Idle(): byte |
---|---|
Returns |
|
Description |
Use the function to test if the transmit shift register is empty or not. |
Requires |
UART HW module must be initialized and communication established before using this function. See UART_Remappable_Init. |
Example |
// If the previous data has been shifted out, send next data: if (UART_Remappable_Tx_Idle() <> 0) begin ... end; |
UART_Remappable_Read
Prototype |
function UART_Remappable_Read(): byte; |
---|---|
Returns |
Received byte. |
Description |
The function receives a byte via UART. Use the UART_Remappable_Data_Ready function to test if data is ready first. |
Requires |
MCU with the UART module and remappable feature. The UART module must be initialized before using this routine. See UART_Remappable_Init routine. |
Example |
var receive: byte; ... // read data if ready if (UART_Remappable_Data_Ready() = 1) then receive := UART_Remappable_Read(); |
UART_Remappable_Read_Text
Prototype |
procedure UART_Remappable_Read_Text(var Output, Delimiter : array[255] of byte; Attempts : byte); |
---|---|
Returns |
Nothing. |
Description |
Reads characters received via UART until the delimiter sequence is detected. The read sequence is stored in the parameter This is a blocking call: the delimiter sequence is expected, otherwise the procedure exits( if the delimiter is not found). Parameter |
Requires |
UART HW module must be initialized and communication established before using this function. See UART_Remappable_Init. |
Example |
Read text until the sequence “OK” is received, and send back what’s been received: UART_Remappable_Init(4800); // initialize UART module Delay_ms(100); while TRUE do begin if (UART_Remappable_Data_Ready() = 1) then // if data is received begin UART_Remappable_Read_Text(output, 'OK', 10); // reads text until 'OK' is found UART_Remappable_Write_Text(output); // sends back text end; end; |
UART_Remappable_Write
Prototype |
procedure UART_Remappable_Write(TxData: byte); |
---|---|
Returns |
Nothing. |
Description |
The function transmits a byte via the UART module. Parameters :
|
Requires |
MCU with the UART module and remappable feature. The UART module must be initialized before using this routine. See UART_Remappable_Init routine. |
Example |
var data_: byte; ... data := 0x1E UART_Remappable_Write(data_); |
UART_Remappable_Write_Text
Prototype |
procedure UART_Remappable_Write_Text(var uart_text : string); |
---|---|
Returns |
Nothing. |
Description |
Sends text (parameter |
Requires |
UART HW module must be initialized and communication established before using this function. See UART_Remappable_Init. |
Example |
Read text until the sequence “OK” is received, and send back what’s been received: UART_Remappable_Init(4800); // initialize UART module Delay_ms(100); while TRUE do begin if (UART_Remappable_Data_Ready() = 1) then // if data is received begin UART_Remappable_Read_Text(output, 'OK', 10); // reads text until 'OK' is found UART_Remappable_Write_Text(output); // sends back text end; end; |
What do you think about this topic ? Send us feedback!