Serial Data Transfer to PC(Personal Computer) using PIC16f877 Microcontroller USART




Here is a simple project on How to transmit serial data to pc using built in usart(universal Syncronous-Asyncronous receiver transmitter)of PIC 16f877 microcontroller. The data Transmitted by PIC microcontroller is received by computer through its (Serial)DB-9 Port and is displayed on Hyperterminal window. Since microcontrollers works on TTL  wave form and standard PC(Personal Computers) works on RS-232 wave form so we have to convert our transmitted data from microcontroller into RS-232 wave form. The best way is to use MAX-232 ic. It converts TTL wave form in to RS-232 and RS-232 to TTL.To learn about its Pin out and working below is a good tutorial.

Serial Data Transfer to PC(Personal Computer) using PIC16f877 Microcontroller USARTThe TX or transmission line of Usart is at pin 25 of PIC 16f877. Connect this transmission line to pin 10(T2IN) of MAX-232. Connect Pin# 7(T2OUT) of MAX-232 to pin# 2 of DB-9 port of your PC. Connect four Capacitors to MAX-232. The Capacitors should range between 1uf to 10uf. I recommend 10uf because i used it in mine project and the circuit is working fine. Apply 5v to vcc pin of microcontroller and MAx-232. Ground Gnd pins of microcontroller and MAX-232. Inserst 20MHz crystal between pins 13 and 14 of PIC 16f877. Crystal should be in parallel to two 33Pf capacitors.

Once you know about the registers associated with Usart transmission you can easily understand the code below.
First of all to enable the serial port or TX(Transmission) RX(Reception) line. The SPEN(Serial port enable bit) bit of register RCSTA(Receive status and control register) should be high.
Set the Baud Rate in SPBRG Register. Their are two formulas for Baud Rates Calculation. Depending on the BRGH bit of TXSTA Register. Formula for BRGH=1 is Different for BRGH=0. Since this bit BRGH selects High or Low Baud Rates thats why Baud Rate depends on this bit. 
Serial Data Transfer to PC(Personal Computer) using PIC16f877 Microcontroller USART SchematicI loaded 0x81 hexadecimal in it. Its equivalent binary is 10000001 and decimal value is 129. Since mine BRGH bit is high so by using the formula for BRGH=1 the Baud Rate value for 9600 is 129. Loading the value 129 in SPBRG and keeping BRGH=1 sets our Baud Rate to 9600.
The Data Which you want to transmit should be placed in TXREG(Transmit register) register. This register gives data to TSR Register. TSR then transmits the data serialy.  TSR Register is not available for user you can not access it. 




Leave a Comment

*
= 3 + 3

Read previous post:
SMART LED FLASHLIGHT - a tiny personal emergency Light sensing LED flashlight, made from available components and very simple for replicate itself in 20 minutes.
SMART LED FLASHLIGHT – a tiny personal emergency Light sensing LED flashlight.

How it works: The flashlight turns on automatic for 60 seconds when it senses that the room is dark enough....

Close
Scroll to top