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.

help with code for rfPIC12F675

Status
Not open for further replies.

mariuszoll

Member level 5
Member level 5
Joined
Aug 28, 2012
Messages
82
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Visit site
Activity points
2,147
Hi,

Could you help me please with an example of C code for rfPIC12F675?
It is my first RF application.
The application is going to work at 433MHZ, ASK mode.

Thank you.
 

Could you give me please a "Hello World" example?
For instance, if I press the button from Tx board, the LED from Rx board turns on.
 

I started to write the software for the transmitter board, but unfortunately it doesn't work.
Could you help me please to fix it?
Please find attached my C code:

Code:
#include <htc.h>
#include <pic.h>
#include <picrf675f.h>

// Internal registers configuration

/* Data Memory Code Protection disabled (CPD_OFF)
* Program Memory Code Protection disabled(CP_OFF)
* Brown-out Detection disabled(BOREN_OFF)
* MCLR pin function is I/O(MCLR_OFF)
* Power-up Timer disabled(PWRTE_OFF)
* Watchdog Timer disabled(WDTE_OFF)
* Internal Oscillator(FOSC_INTRCCLK) */

__CONFIG(INTIO&CPD_OFF&CP_OFF&BOREN_OFF&MCLRE_OFF&PWRTE_OFF&WDTE_OFF&FOSC_INTRCCLK);

// definitions
#define _XTAL_FREQ 4000000

#define TXD		GPIO2 	// serial data out
#define RFEN	GPIO5	// transmitter enable
#define SW1		GPIO3	// Button1
#define SW2		GPIO4	// Button2

unsigned char temp;
char encoded[2];	// this is an array of two bytes(manchester encoded that represent the one byte put in)

void SendData(unsigned char txbyte)
{
	int i,j,b,me;

	b=txbyte;

	for(i=0;i<2;i++)	// manchester encoded txbyte
	{
		me=0;
		for(j=0;j<4;j++)
		{
			me>>=2;
			if(b&(1)!=0) 
			{	
				me|=0x40;	// 1->0; 01000000
			}
			else
			{
				me|=0x80;	// 0->1; 10000000
			}
			b>>=1;
		}	
		encoded[i]=me;
	}
}

// main function
void main(void)
{
	// GPIO settings
	TRISIO=0b00010000;	// GP3 and GP4 inputs
	ANSEL=0;			// configurred port as digital
	WPU=0b00010000;		// pull-up on for GP4 
	IOC=0b00011000;		//	wake up on change enabled for GP3 and GP4

	// Interrupts
	INTCON=0b00010000;	// enable port change wakeup from sleep

	// Comparator module-- setings for sleep mode
	CMCON=7;			// Comparator disable
	VRCON=0;			// disable the voltage reference

	// Configurations
	OPTION_REG=0;		// GPIO pull-ups enabled

	TXD=0;				// no data transmitted
	RFEN=0;				// RF transmitter off	

	while(1)
	{
		if((SW1==1)&&(SW2==1))
		{
			RFEN=0;		// disable transmission
		}
		if(SW1==1)		// button1 pressed
		{
			temp=0x23;	// data to be sent
			SendData(temp);
		}
		if(SW2==1)		// button 2 pressed
		{
			temp=0x43;	// data to be sent
			SendData(temp);
		}
	}
 

U require port change interrupt bit3 & u enable bit 4 which is external interrupt. Also no ISR routine if interrupt occur. no Global interrupt enable.

Also what is switch default condition. If it is high then u require pull up. If it low then u require pull down /............
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top