Mikroelektronika MIKROE-350 Fiche De Données

Page de 526
Soft_UART_Init
352
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6
Prototype
sub function Soft_UART_Init(dim baud_rate as longworddim
inverted 
as byteas 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
dim Soft_UART_Rx_Pin           as sbit at PIND.B0        
dim Soft_UART_Tx_Pin           as sbit at PORTD.B1       
dim Soft_UART_Rx_Pin_Direction as sbit at DDRD.B0
dim Soft_UART_Tx_Pin_Direction as sbit at DDRD.B1
' Soft UART connections
' Initialize Software UART communication on pins Rx, Tx, at 9600
bps
Soft_UART_Init(9600, 0)