int main(void) { unsigned char i; unsigned char ChkSum; //POWER ON indication: LED blink 3 times LED2_OUTPUT(); LED2_OFF(); MODULE_OFF(); //for reset for(i=0;i<3;i++){ Delay_ms(200); LED2_ON(); Delay_ms(200); LED2_OFF(); } LED2_OFF(); MODULE_ON(); //for reset Delay_ms(200); //Initialize command port RFXX_PORT_INIT(); //Initialize RF12 chip RF12_INIT(); //Init FIFO RFXX_WRT_CMD(0xCA81); while(1){ //Enable FIFO RFXX_WRT_CMD(0xCA83); ChkSum=0; //Receive payload data for(i=0;i<16;i++){ ChkSum+=RF12_RECV(); } //Receive Check sum i=RF12_RECV(); //Disable FIFO RFXX_WRT_CMD(0xCA81); //Package chkeck if(ChkSum==i){ LED2_ON(); Delay_ms(200); LED2_OFF(); } } }
int main(void) { uint8_t i; uint8_t ChkSum; cli(); //#asm("cli"); DDRB = 0x00; //PB INPUT; DDRD = 0x00; //PD INPUT; //POWER ON indication: both LEDR and LEDG blink 3 times LEDG_OFF(); LEDR_OFF(); LEDG_OUTPUT(); LEDR_OUTPUT(); for (i=0; i<3; i++) { _delay_ms(200); //Delay_ms(200); LEDG_ON(); LEDR_ON(); _delay_ms(200); //Delay_ms(200); LEDG_OFF(); LEDR_OFF(); } LEDG_OFF(); LEDR_OFF(); RFXX_PORT_INIT(); RF12_INIT(); DDRD |= (1 << RF12_DATA); PORTD |= (1 << RF12_DATA); // SET nFFS pin HI when using TX register DDRD &= ~(1 << DDD2); // PD2(INT0) while (1) { LEDR_ON(); rfxx_wrt_cmd(0x0000); //read status register rfxx_wrt_cmd(0x8239); //!er,!ebb,ET,ES,EX,!eb,!ew,DC ChkSum=0; rf12_send(0xAA); //PREAMBLE rf12_send(0xAA); //PREAMBLE rf12_send(0xAA); //PREAMBLE rf12_send(0x2D); //SYNC HI BYTE rf12_send(0xD4); //SYNC LOW BYTE // send data bytes for (i = 0x30; i<=0x3F; ++i) { rf12_send(i); ChkSum += i; } /* rf12_send(0x30); //DATA BYTE 0 ChkSum+=0x30; rf12_send(0x31); //DATA BYTE 1 ChkSum+=0x31; rf12_send(0x32); ChkSum+=0x32; rf12_send(0x33); ChkSum+=0x33; rf12_send(0x34); ChkSum+=0x34; rf12_send(0x35); ChkSum+=0x35; rf12_send(0x36); ChkSum+=0x36; rf12_send(0x37); ChkSum+=0x37; rf12_send(0x38); ChkSum+=0x38; rf12_send(0x39); ChkSum+=0x39; rf12_send(0x3A); ChkSum+=0x3A; rf12_send(0x3B); ChkSum+=0x3B; rf12_send(0x3C); ChkSum+=0x3C; rf12_send(0x3D); ChkSum+=0x3D; rf12_send(0x3E); ChkSum+=0x3E; rf12_send(0x3F); //DATA BYTE 15 ChkSum+=0x3F; */ rf12_send(ChkSum); //send chek sum rf12_send(0xAA); //DUMMY BYTE rf12_send(0xAA); //DUMMY BYTE rf12_send(0xAA); //DUMMY BYTE rfxx_wrt_cmd(0x8201); LEDR_OFF(); LEDG_OFF(); //for(i=0;i<10000;i++) // for(j=0;j<123;j++); //sleep 1 second appr. _delay_ms(1000); } }