PIC serial communication

24 July 2009:

I am currently working on serial communication using PIC16F877A. More details to follow.

September 08 2009:

This shows how I procrastinate things. Finally, I achieved it. I have communicated to my PC using PIC16F877A. It took more than 48 hours to achieve this task!

Well! My two cents on serial communications is “Datasheet is your Bible!’

Never digress from the procedure mentioned in the datasheet!

In the rudimentary stages, I blindly followed the rules and I was able to send the letter ‘h’ to the hyper terminal. But I faced problems with the set baud rate of my microcontroller and it was sending some unknown characters to the terminal.

The frequency of my crystal oscillator was 11Mhz. Hence my Baud rate value would be 71 which was arrived at by using the formula given in the data sheet.

The screen shot of the letter h being received at the terminal is shown below!

First data from uC

I had to follow this procedure to declare an array containing the data ‘hello world’ which gives the satisfaction of winning a noble prize to any rookie.

The word ‘hello’ over the terminal  is shown below:

Hell from uCThe Pic 16F877A data sheet can be downloaded from the Microchip website!

The code used for serial port communication was:

#include<pic.h>

void delay(unsigned int n)

{

while(n- -);

}

unsigned char data[17]=” hello world ‘”;

int i;

void main()

{

TRISC = 0x80;

SYNC =0;

SPEN = 1;

TXIE = 1;

TX9 = 0;

BRGH = 1;

GIE = 1;

PEIE = 1;

RCIE = 0;

SPBRG = 71;

while(1)

{

TXEN=1;

}

}

void interrupt isr(void)

{

for(i=0; i<=6; i++)

{

TXREG = data[i];

delay(500);

}

}

Happy Programming!
#include<pic.h>
void delay(unsigned int n)
{
while(n–);
}
unsigned char data[17]=” hello world””;
int i;
void main()
{
TRISC = 0x80;
SYNC =0;
SPEN = 1;
TXIE = 1;
TX9 = 0;
BRGH = 1;
GIE = 1;
PEIE = 1;
RCIE = 0;
SPBRG = 71;
while(1)
{
TXEN=1;
}
}
void interrupt isr(void)
{
for(i=0; i<=6; i++)
{
TXREG = data[i];
delay(500);
}
}

Advertisements

2 Responses to PIC serial communication

  1. Srihari says:

    That’s a lot of hellos! Nice work!!

  2. yamanoorsai says:

    Thank you Very much!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: