//#include "C:\MentorProjects\Radio_PIC\PIC _Receive\last_code rf12\ccs pic_rf12_Receiver\ccs_rf12_receiver.h" typedef unsigned char uchar; typedef unsigned int uint; /********************************************************************************************** * Defines voor de RFM12 transceiver ***********************************************************************************************/ #define SDO PIN_B4 #define SDI PIN_C0 #define SCK PIN_C2 #define nSEL PIN_C6 #define nIRQ PIN_C7 uchar RF_RXBUF[19]; void Init_RF12(void); void Write0(void); void Write1(void); void WriteCMD (int16 cmd); uchar RF12_RDFIFO(void); void Init_RF12(void) { output_high(nSEL); output_high(SDI); output_low(SCK); output_low(SDO); WriteCMD(0x80E8);// enable register, 868MHz, 12.5pF WriteCMD(0x82D8);// WriteCMD(0xA640); WriteCMD(0xC647); WriteCMD(0x94C0); WriteCMD(0xC2AC); WriteCMD(0xCA80); WriteCMD(0xCA83); WriteCMD(0xC49B); WriteCMD(0x9850); WriteCMD(0xE000); WriteCMD(0xC800); WriteCMD(0xC000); } void Write0(void) { output_low(SDI); output_low(SCK); delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP output_high(SCK); delay_cycles( 1 ); // Same as a NOP } void Write1(void) { output_high(SDI); output_low(SCK); delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP output_high(SCK); delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP } void WriteCMD( int16 CMD) { uchar n=16; output_low(SCK); output_low(nSEL); while(n--) { if(CMD&0x8000) Write1(); else Write0(); CMD=CMD<<1; } output_low(SCK); output_high(nSEL); } uchar RF12_RDFIFO(void) { uchar i, Result; output_low(SCK); output_low(SDI); output_low(nSEL); for(i = 0; i<16; i++) { output_high(SCK); delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP output_low(SCK); delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP } Result = 0; for(i=0;i<8;i++) { Result=Result<<1; if(input(SDO)) { Result |= 1; } output_high(SCK); delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP output_low(SCK); delay_cycles( 1 ); // Same as a NOP delay_cycles( 1 ); // Same as a NOP } output_high(nSEL); return(Result); } /* void main() { uchar i=0, j=0; uint CheckSum; setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); Init_RF12(); while(1) { while(!(input(nIRQ))) { output_toggle(LED1); RF_RXBUF[i++]=RF12_RDFIFO(); if(i==17) { i=0; WriteCMD(0xCA80); WriteCMD(0xCA83); CheckSum=0; for(j=0;j<16;j++) CheckSum+=RF_RXBUF[j]; CheckSum&=0x0FF; if(CheckSum==RF_RXBUF[16]) { output_toggle(LED); } Delay_us(1); } } } }*/