Mikroelektronika MIKROE-724 データシート
460
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
Software UART Library
mikroBasic PRO for dsPIC30/33 and PIC24 provides library which implements Software UART communication.
These routines are hardware independent and can be used with any MCU. The Software UART Library provides easy
communication with other devices via the RS232 protocol.
Important: The Software UART library implements time-based activities, so interrupts need to be disabled when using it.
Library Routines
- Soft_UART_Init
- Soft_UART_Read
- Soft_UART_Write
- Soft_UART_Break
Soft_UART_Init
Prototype
sub function Soft_UART_Init(dim byref port as word, dim rx, tx as word, dim
baud_rate as longword, dim inverted as word)
Description Configures and initializes the software UART module.
Software UART routines use Delay_Cyc routine. If requested baud rate is too low then calculated
parameter for calling
Delay_Cyc
exceeds
Delay_Cyc
argument range.
If requested baud rate is too high then rounding error of
Delay_Cyc
argument corrupts Software
UART timings.
Parameters -
port
: software UART port address
-
rx
: receiver pin
-
tx
: transmiter pin
-
baud_rate
: requested baudrate. Maximum baud rate depends on the MCU’s clock and working
conditions
-
inverted
: if set to non-zero value, indicates inverted logic on output
Returns
-
2
- error, requested baud rate is too low
-
1
- error, requested baud rate is too high
-
0
- successful initialization
Requires
Nothing.
Example
This will initialize software UART and establish the communication at 9600 bps:
‘ Initialize Software UART communication on pins RB1(Rx), RB2(Tx), at 9600
bps
Soft_UART_Init(PORTB, 1, 2, 9600, 0)
Notes
The Software UART library implements time-based activities, so interrupts need to be disabled when
using it.