PIC16F877A UART CODE
When a microcontroller communicates with the outside world, it provides the data in byte-sized chunks. In some cases,such as printers, the information is simply grabbed from the 8-bit databus and presented to the 8 bit data bus of the printer. This can work only if the cable is not too long, because long cables diminish and even distort signals.
Furthermore the 8 bit path is expensive.For these reasons,serial communication is used for transferring data between two systems located at the distances of hundreds of feet to millions of miles apart.
For a serial communication data to work, the bytes of data must be converted to serial bits using a parallel-in-serial-out shift register, then it can be transmitted over a single data line.This also means that at the receiving end there must be a serial in parallel out shift register to receive the serial data and pack them into a byte.
Serial communication uses two methods,asynchronous and synchronous.
The synchronous method transfer a block of data (char) at a time whereas the asynchronous method transfers a single byte at a time. It is possible to write software to use either of these methods.
Example 1 :
This code is used to send letter 'S' serially at 9600 baud.at 10MHZ crystal.
![]() |
Figure 1:PIC16F877A code for transmit a char using USART |
The following diagram (made in Proteus) shows the PIC microcontroller circuit diagram.
![]() |
Figure 2 :USART OUTPUT |
Comments
Post a Comment