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.

One way RF communication between pic 16f877a.

Status
Not open for further replies.

areeckal

Member level 2
Joined
Jan 22, 2011
Messages
42
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,567
I need to establish RF communication between two pic 16f877a. I need to transmit a bit according to the sensor output. How to configure pic for this? I studied USART and I have written the following code:
Code:
#include <htc.h>
#include "usart.h"

unsigned int data;
void delay()
{
	for(int i=0;i<100;i++)
	{}
}

void main(void)
{
	INTCON=0;	// purpose of disabling the interrupts.

	init_comms();	// set up the USART - settings defined in usart.h

	data=PORTC;
	putch(data);
	delay();
	data=getch();
	PORTD=data;
}
 

I have written a simple code for transmitter and receiver.. Will this work fine?
Transmitter:
Code:
#include <htc.h>
#include "usart.h"

//Chip Settings
__CONFIG(1,0x0200);
__CONFIG(2,0X1E1F);
__CONFIG(3,0X8100);
__CONFIG(4,0X00C1);
__CONFIG(5,0XC00F);

void main()
{
	unsigned int data;
	//Initialize the USART
	USARTInit();
	//Now Read some input
	while(1)
	{
		data=PORTC;
		/* 
      	Now send a Packet
      	Packet Format is AA<data><data inverse>Z
		total Packet size if 5 bytes.
      	*/
		//Stabilize the Tx Module By Sending JUNK data
		//J for Junk
		USARTWriteByte('J');
		//Send 'A'
      	USARTWriteByte('A');
	    //Send Another 'A'
    	USARTWriteByte('A');
	   	//Send the data;
      	USARTWriteByte(data);
	    //Send inverse of data for error detection purpose
	    USARTWriteByte(~data);
		//End the packet by writing 'Z'
      	USARTWriteByte('Z');
		_delay(10);

	}
}
Receiver:
Code:
#include <htc.h>
#include "usart.h"

//Chip Settings
__CONFIG(1,0x0200);
__CONFIG(2,0X1E1F);
__CONFIG(3,0X8100);
__CONFIG(4,0X00C1);
__CONFIG(5,0XC00F);

void main()
{
	unsigned int packet[2],data;
	TRISC=0x00;
	//Initialize the USART
	USARTInit();
	//Get data from Tx
	while(1)
	{
			
		//Wait for a packet
		if(USARTReadByte()=='A')
		{
			if(USARTReadByte()=='A')
			{
				packet[0]=USARTReadByte();
				packet[1]=USARTReadByte();
				if((packet[0]!=~(packet[1]))&&(USARTReadByte()!='Z'))
					continue;
				else
				{
					data=packet[0];
					PORTC=data;
				}
			}
		}
	

		
	}
}

I have a doubt. In this case, I am presenting a 1 byte value each time. Ie, iam sending a 5 byte packet. So when TxREG is equal to say 0x01 after transmission, RCREG will get it immediately? Will RCIF will be set to 1 after transmission of a single byte?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top