Datasheet

Soft_UART_Init
365
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroPASCAL PRO for AVR
CHAPTER 6
Prototype
function Soft_UART_Init(baud_rate: dword; inverted: byte): byte;
Returns
- 2 - error, requested baud rate is too low
- 1 - error, requested baud rate is too high
-
0 - successfull initialization
Description
Configures and initializes the software UART module.
Parameters :
-
baud_rate: baud rate to be set. Maximum baud rate depends on the MCU’s
clock and working conditions.
- inverted: inverted output flag. When set to a non-zero value, inverted logic
on output is used.
Software UART routines use Delay_Cyc routine. If requested baud rate is too
low then calculated parameter for calling
Delay_Cyc exceeeds Delay_Cyc argu-
ment range.
If requested baud rate is too high then rounding error of
Delay_Cyc argument
corrupts Software UART timings.
Requires
Global variables:
-
Soft_UART_Rx_Pin: Receiver pin
-
Soft_UART_Tx_Pin: Transmiter pin
- Soft_UART_Rx_Pin_Direction: Direction of the Receiver pin
- Soft_UART_Tx_Pin_Direction: Direction of the Transmiter pin
must be defined before using this function.
Example
// Soft UART connections
var Soft_UART_Rx_Pin : sbit at PIND.B0;
var Soft_UART_Tx_Pin : sbit at PORTD.B1;
var Soft_UART_Rx_Pin_Direction : sbit at DDRD.B0;
var Soft_UART_Tx_Pin_Direction : sbit at DDRD.B1;
// Soft UART connections
...
// Initialize Software UART communication on pins Rx, Tx, at 9600
bps
Soft_UART_Init(9600, 0);