#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);
}
}