Problems with Microcontroller Projects? You may face many Problems, but do not worry we are ready to solve your Problems. All you need to do is just leave your Comments. We will assure you that you will find a solution to your project along with future tips. On Request we will Mail you the Codes for Registered Members of this site only, at free service...Follow Me.

pic16f628a BASED UART Library to Communicate with PC

MikroC has two sets of built-in library functions for UART communications: Software UART and Hardware UART. Since PIC16F628A has a built-in hardware USART module, we are going to use the Hardware UART library. Some PICs don't have hardware USART, such as PIC16F84A. In such cases, any digital I/O pins of PIC can be used for Asynchronous Serial Data Transfer using mikroC Software UART libraries.

Experimental Setup

The UART Rx and Tx pins in PIC16F628A are multiplexed with RB1 and RB2 pins. In this experiment, we are just sending some character data from PIC to a PC as demonstration of the technique. On PC, the HyperTerminal program should be running to receive data from the PIC16F628A. Since our PIC board does not have a TTL to RS232 voltage level shifter, we are going to construct it on a breadboard. Here is my Level Shifter Circuit:




Connect Tx on PIC side to RB2 pin and leave Rx open, as we are not receiving any data from PC. And,  the same circuit on breadboard is shown below. I am using BC557 transistor. The diode in the circuit is any general purpose diode.

BC557 Transistor PinsRelevant Links


I have one COM Port on my PC to which I have connected a RS232 DB9 female connector. We need to make a common ground between RS232 and our experiment board. So connect pin 5 (which is ground) of  DB9 connector to our circuit ground. 

Male DB9 Connector Pin descriptions. (Source:http://tk5ep.free.fr/tech/ts850/if232/img/db9_pinouts.gif )

The same signal pins for a female DB9 connector. See, how the pins are flipped around horizontal.

Complete Setup for this Experiment

We are going to set 9600 baud rate for data transfer, so next step is to setup the Hyperterminal on PC. I am running this on Windows XP.
  1. Go to Start-> All Programs -> Accessories -> Communications -> Hyper Terminal
  2. Setup a New Connection to a proper COM port number with
      • bps : 9600
      • Databits: 8
      • Parity : None
      • Stop Bits : 1
      • Flow Control : Hardware
Click OK and now the HyperTerminal is ready to receive data from PIC.

Software
As mentioned earlier, mikroC has in-built library functions for hardware UART. Check out the manual here.

/*
 * Project name:
     Asynchronous Serial Data Transfer from PIC16F628A to a PC HyperTerminal
 * Copyright:
     (c) Rajendra Bhatt, 2009.

*/

void main() {
CMCON = 7;       // Disable Comparators
UART1_Init(9600);     // Baud Rate 9600
Delay_ms(100);
while(1) {
//UART1_Write(_data);
UART1_Write_Text(" UART Test Successful! ");   // Character Message to be Sent
UART1_Write(10); // Line Feed
UART1_Write(13); // Carriage Return
delay_ms(2000);     // Send the message every 2 seconds
}
}

Experimental Output

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

Recent Comments

Popular Projects

Give Support

Give Support
Encourage Me through Comments

Microcontroller Projects

Total Pageviews