According to datasheet (page 13) it is always advantageous to enable it, as it can eliminate errors during communication.Īs said earlier we will be working in Asynchronous mode, hence the bit SYNC should be made zero and bit SPEM must be made high to enable serial pins (TRISC6 and TRICSC5) The bit BRGH has to be made high to enable high speed bit rate. SPBRG = ( ( _XTAL_FREQ/16 ) / Baud_rate) – 1
The value of the baud rate has to be set using the register SPBRG, the value depends on the value of the External crystal frequency, the formulae to calculate the baud rate is shown below: **Initialize SPBRG register for requiredīaud rate and set BRGH for fast baud_rate**/ This can be one of the many default values, but in this program we are using 9600 since its the most used baud rate. The baud rate is the rate at which information is transferred in a communication channel. According to datasheet let’s declare TX as output and RX as input. The Tx and Rx pins are physically present at the pins RC6 and RC7. Initializing the UART module of the PIC Microcontroller: Let’s define the configuration bits and start with the UART initialization function. Like all modules (ADC, Timer, PWM) we should also initialize our USART module of our PIC16F877A MCU and instruct it to work in UART 8-bit communication mode. Programming PIC Microcontroller for UART Communication: But, if it doesn’t relax!!! Use the comment section and I will help you out.
Note: Each RS232 to USB converter would require a special driver to be installed most of them should get installed automatically as soon as you plug in the device. The one which we are using is shown below
There are ways to design your own circuit instead of buying your own module but they are not reliable as they are subjected noise. Detailed Video is also given at the end of this tutorial.Ī RS232 to USB converter is required to convert the serial data into computer readable form. We will test the output using Hyper Terminal in computer. The status of the LED will be sent to your laptop from the PIC MCU. This type of communication does not share a common clock hence a common ground is very important for the system to work.Īt the end of this tutorial you will be able establish a communication (UART) between your computer and your PIC Microcontroller and toggle an LED on the PIC board from your laptop. The ground of both devices should also be made common. UART uses two data lines for sending (Tx) and receiving (Rx) data. As it is asynchronous it doesn't need to send clock signal along with the data signals. There are also two different modes namely the 8-bit and 9-bit mode, in this tutorial we will configure the USART module to work in Asynchronous mode with 8-bit communication system, since it is the most used type of communication. The USART can be configured in the following modes: