now am doing R&D project...need serial communication code...

Status
Not open for further replies.

ganesh dvk

Junior Member level 1
Joined
Oct 11, 2012
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
chennai
Activity points
1,359
hi ,
i have a one problem for serial communication...am using pic16f877a controler...compiler HI-TECH C...am using 3 transmitting kit and one receiving kit...thats all............
3 multiple transmitt path(zigbee) to single(zigbee) receiving path and display the same time.... if its possible or not...pls seniors help me...
 

ok..if its possible to send to the code in mikroc.....i convert to my own code...........
 

use Zigbee star topology [single coordinator and multiple end devices].

3 transmitters : end devices
receiver : Coordinator
 

here is code for transmitting and receiving the data using USART of PIC16F877A

transmitting

Code:
#include<htc.h>
#include<pic.h>
//#include <pic16f877a.h>
#define _XTAL_FREQ 4000000
 
 
__CONFIG(0x1f3a); 
 
 
void main(void)
{
 
ADCON1 =0x06 ;      // Changes PORTA and PORTE to digital
TRISA = 0x00 ;      // Configure PORTA as output
TRISD = 0X00 ;      // Configure PORTD as output
TRISB = 0x00 ;      // Configure PORTB as output
TRISC = 0x00 ;      // Configure PORTC as output
TRISE = 0x00 ;      // Configure PORTE as output
 
 
SPBRG=25;           //setting the Baud Rate
RCSTA=0X80;         //Enabling the Serial Communication
TXSTA=0X26;         //Enabling Transmission in Serial Communication, Selecting Mode and Speed
 
TXREG='H';
while(TXIF==0 || TRMT==0);
 
TXREG='E';
while(TXIF==0 || TRMT==0);
 
TXREG='L';
while(TXIF==0 || TRMT==0);
 
TXREG='L';
while(TXLIF==0 || TRMT==0);
 
TXREG='O';
while(TXIF==0 || TRMT==0);
 
TXREG=' ';
while(TXIF==0 || TRMT==0);
 
TXREG='T';
while(TXIF==0 || TRMT==0);
 
TXREG='E';
while(TXIF==0 || TRMT==0);
 
TXREG='C';
while(TXIF==0 || TRMT==0);
 
TXREG='H';
while(TXIF==0 || TRMT==0);
 
TXREG='N';
while(TXIF==0 || TRMT==0);
 
TXREG='O';
while(TXIF==0 || TRMT==0);
 
TXREG='L';
while(TXIF==0 || TRMT==0);
 
TXREG='O';
while(TXIF==0 || TRMT==0);
 
TXREG='G';
while(TXIF==0 || TRMT==0);
 
TXREG='Y';
while(TXIF==0 || TRMT==0);
 
 
 
 
 
while(1);
 
}

receiving

Code:
/*Serial Receive Program Using PIC16F877A mmicrocontroller
Baud Rate is 9600
PortB - data lines
PortC - control lines
*/


#include<htc.h>

#define _XTAL_FREQ 4000000 	// defines the crystal used


__CONFIG(0x1f3a); 

void ready()
{
	TRISB7=1;
	RB7 = 1;
    RE0=0;
    RE1=1;
    while (RB7==1)
    {
 		RE2=0;
        RE2=1;
    }
	TRISB7=0;
}

//To send the COMMANDS for LCD
void command(unsigned char i)
{ 
 ready();
 PORTB=i;
 RE0=0;
 RE1=0;
 RE2=1;
 RE2=0;
}

//To send the DATA for LCD
void da_dis1(unsigned char i)
{

	ready();
	PORTB=i;
	RE0=1;
	RE1=0;
	RE2=1;
	RE2=0;
}

void lcd_init()
{

command(0x38);
command(0x0e);
command(0x01);
command(0x06);
command(0x80); 
}



void main(void)
{
char i;


ADCON1 =0x06 ; 		// Changes PORTA and PORTE to digital
TRISA = 0x00 ; 		// Configure PORTA as output
TRISD = 0X00 ;		// Configure PORTD as output
TRISB = 0x00 ;		// Configure PORTB as output
TRISC = 0x00 ;		// Configure PORTC as output
TRISE = 0x00 ;		// Configure PORTE as output
TRISC7=1;

lcd_init();

PORTA=0x00;
SPBRG=25;			//setting the baud rate
TXSTA=0x04;			//selecting the Asynchronous mode
RCSTA=0X90;			//Enabling the Serial Communication and Configuration of Receiving Mode

da_dis1('T');
da_dis1('E');
da_dis1('X');
da_dis1('T');
da_dis1(' ');
da_dis1('R');
da_dis1('E');
da_dis1('C');
da_dis1('E');
da_dis1('I');
da_dis1('V');
da_dis1('I');
da_dis1('E');
da_dis1('D');


while(1)
{
	
	if(RCIF==1)
	{
		i=RCREG;
		command(0xc0);
		da_dis1(i);		//Displaying the data Received using UART.
		
	
	}
	if(OERR==1 || FERR==1)		//If any Error Occurred
	{
		CREN=0;
		CREN=1;
			
	}


}





}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…