Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

prob with uart in pic 16f877a

Status
Not open for further replies.

sivaramakrishna

Newbie level 5
Joined
Oct 22, 2008
Messages
9
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,362
uart serial 16f877

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; //transmitted data
}
if(RCIF==1)
{
for(i=0;i<=5;i++)
data=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';
}
}
 

hyperterminal 16f877a

while(1)
{
TXREG='f';
TXREG='z';
}

You have a problem here! Before starting a new transmission (I mean, before loading TXREG) you have to be sure that the previous transmission, if any, is finished (I mean you have to be sure that TXREG is empty).

I may recommend the following:
Code:
while(1) 
{
    while(!TXIF);       //wait for current transmition to end 
    TXREG='f'; 
    while(!TXIF);       //wait for current transmition to end
    TXREG='z'; 
}

You should configure both RC7 and RC6 as inputs because both RX and TX lines should be kept on "1" logic when the lines are idle. More than this, if I remeber well, in the datasheet is specified that both RC7 and RC6 should be configured as inputs.
 

16f877 uart brgh

hai,
thanks for the idea. But i tried out with this code and also enabled the GIE AND PEIE. But i could still transmit any data....
Please help me out.

Thanks in advance
 

pic + usart + wait for receive

HAI,

The solution for the above problem with the piece of code below :
Code:
#include <pic.h> 

__CONFIG(HS & PWRTEN & WDTDIS & LVPDIS & BOREN & DEBUGDIS);

void main (void) 
{ 
	unsigned char ch[7]="fabmax ";
	unsigned char i;	
   	/* Configure IO pins. */ 
   	TRISC6 = 1; 
   	TRISC7 = 1; 

   	/* Set baud rate. */ 
   	SPBRG = 51; 	//9600 at 8Mhz
   //	SPBRG = 129;	//9600 at 20MHz
   	BRGH = 1;
   
   	/* Select asynchron mode. */ 
   	SYNC  = 0; 

   	/* Enable transmission.*/ 
   	TX9   = 0;         //8 bit transmission 
   	TXEN  = 1;           //tx enabled    

   	/* Enable reception.*/ 
   	RX9   = 0;         //8 recption 
   	CREN  = 1;           //rx enabled 

   	/* Enable UART module.*/ 
   	SPEN  = 1; 

   	while(1) 
   	{ 
		for(i=0;i<=6;i++)
			{
     //	while(!RCIF);		//wait to receive a byte
     //	ch = RCREG;
      	while(!TXIF); 		//wait for current transmition to end 
      	TXREG = ch[i]; 
			}
   	} 
}
 
  • Like
Reactions: kevan

    kevan

    Points: 2
    Helpful Answer Positive Rating
Hi the digital waveform i saw from an oscilloscope from Proteus software, is it representing "fabmax"?? For the coding above
 

Hey guys, I need a simple C program to receive data from PIC Micro controller interface and understand it. I need to receive a command, they decode it, then switch ON a Camera attached to USB interface accordingly.

Pls Help
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top