User`s manual
sub procedure USART_Init(const Baud_Rate)
Parameter Baud_rate is the desired baud rate;
Example:
USART_init(2400)
This will initialize PIC MCU USART hardware and establish the communication
at baud rate of 2400.
Refer to the device data sheet for baud rates allowed for specific Fosc. If you
specify the unsupported baud rate, compiler will report an error.
In order to keep this working, you should not override settings made by the proce-
dure USART_init as it uses some of the PIC MCU resources. (For example: pins
RC7, RC6 configured as input, output respectively; do not change TRISC settings
for this pins - procedure will set them automatically). Check the figure on the fol-
lowing page.
Following routines can be used after the communication has been established:
sub function USART_Data_Ready as byte
Returns 1 if data is ready; returns 0 if there is no data.
sub function USART_Read as byte
Receive a byte; if byte is not received return 0.
sub procedure USART_Write(dim Data as byte)
Transmit a byte.
The following code demonstrates how to use USART library procedures and func-
tions. When PIC MCU receives data via rs232 it immediately sends the same data
back. If PIC MCU is connected to the PC (see figure below), you can test it using
mikroBasic terminal for RS232 communication, menu choice Tools > Terminal.
mikroBASIC
- Basic Compiler for Microchip PIC microcontrollers
162
mikroBASIC
MikroElektronika: Development tools - Books - Compilers
making it simple...
page
Example