Sign in

Not a member? | Forgot your Password?

Search Comp.Arch.Embedded

Search tips

Free PDF Downloads

Advanced Linux Programming

What Every Programmer Should Know About Memory

Introduction to Embedded Systems

C++ Tutorial

Embedded Systems - Theory and Design Methodology

Microcontroller Programming and Interfacing

Introduction to Microcontrollers


More Free PDF Downloads

Recent Blogs on EmbeddedRelated

Someday We’ll Find It, The Kelvin Connection
posted by Jason Sachs


Reverse engineering wireless wall outlets
posted by Fabien Le Mentec


Short Circuit Execution vs. Unit Testing
posted by Stephen Friederichs


Practical protection against dust and water (i.e. IP protection)
posted by Dr Cagri Tanriover


Specifying the Maximum Amplifier Noise When Driving an ADC
posted by Rick Lyons


How to make a heap profiler
posted by Yossi Kreinin


Introduction to Microcontrollers

1 - Beginnings

2 - Further Beginnings

3 - Hello World

4 - More On GPIO

5 - Interrupts

6 - More On Interrupts

7 - Timers

8 - Adding Some Real-World Hardware

9 - More Timers and Displays

10 - Buttons and Bouncing

11 - Button Matrix & Auto Repeating

12 - Driving WS2812 RGB LEDs

See Also

ElectronicsDSPFPGA

Find us on Facebook





Discussion Groups | Comp.Arch.Embedded | pic16f877a uart c code problm

There are 6 messages in this thread.

You are currently looking at messages 1 to 6.


So far in July, you have voted 0 times ou of a total of 0 votes by the community.
Please help us clean the archives from unuseful discussion threads by using the voting system! Details here.

pic16f877a uart c code problm - sivaramakrishna - 2008-11-11 03:49:00

Hai to all, 

Iam trying to communicate from pic 16f877a to the pc's hyperterminal at
9600 baud rate. Iam posting my code for this. 
Iam able to simulate with mplab but I could not implement with hardware. I
checked for max232, rs232. They seem to be working perfect. But iam not
getting the data through hyperterminal comm port. 

My crystal oscillator is 8mhz. 


/* uart serial communication at 9600 baud rate*/ 
/*spbrg=(8Mhz/(9600)/16)-1*/ 

#include<pic.h> 
//unsigned char data[6]="fabmax"; 
unsigned char i; 
/*void interrupt isr(void) 
{ 
if(TXIF==1) 
{ 

for(i=0;i<=5;i++) 
TXREGÚta[i]; //transmitted data 
} 
if(RCIF==1) 
{ 
for(i=0;i<=5;i++) 
data[i]=RCREG; //received data 
} 
}*/ 
void main (void) 
{ 
// unsigned char data[6]="fabmax"; 
unsigned char i; 
TRISC6=0; 
TRISC7=1; 
SPBRG=0x33; // for 9600 baoud rate 
// GIE=1; 
// PEIE=1; 
BRGH=1; 
SPEN=1; //serial comm enabled 
SYNC=0; //synchronous mode disabled 
// TXIE=1; 
// RCIE=1; 
TXEN=1; //transmission enabled 
// RCEN=1; 
while(1) 
{ 
TXREG='f'; 
TXREG='z'; 
} 
} 

Re: pic16f877a uart c code problm - Bill Chernoff - 2008-11-11 10:40:00

Can you communicate with other serial devices with hyperterminal?

Are you getting anything out of the max232 on your board?

Is your serial cable wired the way you think it is?




Re: pic16f877a uart c code problm - James Beck - 2008-11-11 11:12:00

In article <r...@giganews.com>, 
s...@gmail.com says...
> Hai to all, 
> 
> Iam trying to communicate from pic 16f877a to the pc's hyperterminal at
> 9600 baud rate. Iam posting my code for this. 
> Iam able to simulate with mplab but I could not implement with hardware. I
> checked for max232, rs232. They seem to be working perfect. But iam not
> getting the data through hyperterminal comm port. 
> 
> My crystal oscillator is 8mhz. 
> 
> 
> while(1) 
> { 
> TXREG='f'; 
> TXREG='z'; 
> } 

There is no test here to make sure the data has left before you shove 
the next value in.  Look at the data sheet for the transmit complete 
flag.  The start of the code looks like you were playing with the UART 
interrupts at one point or another, but that's not going to help you 
with the above code.



Re: pic16f877a uart c code problm - 2008-11-11 17:31:00

On Nov 11, 8:49�am, "sivaramakrishna" <siva.g...@gmail.com> wrote:
> Hai to all,
>
> Iam trying to communicate from pic 16f877a to the pc's hyperterminal at
> 9600 baud rate. Iam posting my code for this.
> Iam able to simulate with mplab but I could not implement with hardware. I
> checked for max232, rs232. They seem to be working perfect. But iam not
> getting the data through hyperterminal comm port.
>
> My crystal oscillator is 8mhz.
>
> /* uart serial communication at 9600 baud rate*/
> /*spbrg=(8Mhz/(9600)/16)-1*/
>
> #include<pic.h>
> //unsigned char data[6]="fabmax";
> unsigned char i;
> /*void interrupt isr(void)
> {
> if(TXIF==1)
> {
>
> for(i=0;i<=5;i++)
> TXREG=data[i]; //transmitted data}
>
> if(RCIF==1)
> {
> for(i=0;i<=5;i++)
> data[i]=RCREG; //received data}
> }*/
>
> void main (void)
> {
> // unsigned char data[6]="fabmax";
> unsigned char i;
> TRISC6=0;
> TRISC7=1;
> SPBRG=0x33; // for 9600 baoud rate
> // GIE=1;
> // PEIE=1;
> BRGH=1;
> SPEN=1; //serial comm enabled
> SYNC=0; //synchronous mode disabled
> // TXIE=1;
> // RCIE=1;
> TXEN=1; //transmission enabled
> // RCEN=1;
> while(1)
> {
> TXREG='f';
> TXREG='z';
>
>
>
> }
> }- Hide quoted text -
>
> - Show quoted text -

You need an interupt driven, buffered, handshaking system to get
performance. Email me for some code, it's not for a pic but it's
easily modified, more for instruction as to what to do and how to do
it.

Re: pic16f877a uart c code problm - Stonethrower - 2008-11-11 17:38:00

> Iam trying ...
> /*void interrupt isr(void)
/snap/
> }*/

Seems you commented out interrupt routines (ISRs); why did you do that? To 
make a joke?

-- 
StoneThrower
www.dgmicrosys.com 


Re: pic16f877a uart c code problm - Andrew Jackson - 2008-11-12 02:20:00

> Iam trying to communicate from pic 16f877a to the pc's hyperterminal at
> 9600 baud rate. Iam posting my code for this. 

Try using TeraTerm instead of HyperTerminal: its much more forgiving 
(see numerous past posts on the subject).  In particular HyperTerminal 
has a tendency to require the modem control signals even when you tell 
it to ignore them.

> Iam able to simulate with mplab but I could not implement with hardware. I
> checked for max232, rs232. They seem to be working perfect. But iam not
> getting the data through hyperterminal comm port. 

Have you checked that you are seeing the correct voltages on the PIC's 
TX line and the MAX232 TX?  You can do this by wobbling the port not 
just sending a character.  That way you can be sure that the hardware 
path is correct before worrying about serial communication.  Have you 
checked that the lead you are using to the PC is correct?

> 
> My crystal oscillator is 8mhz. 


> if(TXIF==1) 
> { 
> 
> for(i=0;i<=5;i++) 

The PIC's serial port is only single buffered: you can only put a single 
character into it each time TXIF is set.

> TXREGÚta[i]; //transmitted data 
> } 
> if(RCIF==1) 
> { 
> for(i=0;i<=5;i++) 
> data[i]=RCREG; //received data 

Ditto for receive.

> } 
> }*/ 
> void main (void) 
> { 
> // unsigned char data[6]="fabmax"; 
> unsigned char i; 
> TRISC6=0; 
> TRISC7=1; 
> SPBRG=0x33; // for 9600 baoud rate 
> // GIE=1; 
> // PEIE=1; 
> BRGH=1; 
> SPEN=1; //serial comm enabled 
> SYNC=0; //synchronous mode disabled 
> // TXIE=1; 
> // RCIE=1; 
> TXEN=1; //transmission enabled 
> // RCEN=1; 
> while(1) 
> { 
> TXREG='f'; 
> TXREG='z'; 
> } 
> } 

As others have pointed out you need to wait for TXIF to become set.

The basic port configuration looks correct so I'd look at your hardware. 
  You might want to set TX9 and RX9 to zero to ensure that you are 
dealing with 8 bit data.

	Andrew