// RF TX Code for locust // //#case #include <16C84.H> // Configure PIC to use: HS clock, a Watchdog Timer, // no code protection, enable Power Up Timer // #fuses HS,WDT,NOPROTECT,PUT // tell compiler clock is 4MHz. This is required for DELAY_MS() // and for serial I/O, all of which use software delay loops. // #use DELAY(clock=4000000) // declare that we'll manually establish the data direction of // each I/O pin on port B. // #use fast_io(A) #use fast_io(B) // Standard definitions for the irx2_1 board // #define RS232_XMIT PIN_B1 // (output) RS232 serial transmit #define RED_LED PIN_B2 // (output) Red LED (low true) #define IR_LED PIN_B3 // (output) Infrared LED (low true) #define IR_SENSOR PIN_B4 // (input) IR sensor (Sharp IS1U30) #define RS232_RCV PIN_B5 // (input) RS232 serial receive #define RF_XMIT PIN_A2 // (output) RF Output // Macros to simplify I/O operations // #define RED_LED_ON output_low(RED_LED) #define RED_LED_OFF output_high(RED_LED) #define IR_LED_ON output_low(IR_LED) #define IR_LED_OFF output_high(IR_LED) #define RF_ON output_high(RF_XMIT) #define RF_OFF output_low(RF_XMIT) // Default tri-state port direction bits: // all PORT A bits are output // all PORT B bits are output except for // IR_SENSOR (bit 4) and RC232_RCV (bit 5). // #define IRX_A_TRIS 0b00000000 #define IRX_B_TRIS 0b00110000 // define an array in which to hold the ID char RF_data[6]; // Inform printf() and friends of the desired baud rate // and which pins to use for RF I/O. // #use rs232(baud=1200, xmit=RF_XMIT, rcv=RS232_RCV) void put_RF(char c) { putc(c); } void RF_TX() { int i; // Header put_RF(0xF0); put_RF(0xF0); put_RF(0xF0); put_RF(0xF0); put_RF(0xFF); // Data 4 Bytes of Data 2 Check Bytes based on // Check 1 = (Byte 1 + Byte 2 + Byte 3) % 256 // Check 2 = (Byte 2 + Byte 3 + Byte 4) % 256 for (i = 0; i < 6; i++) put_RF(RF_data[i]); } void main() { int i; // since we've declared #use fast_io(A) and #use fast_io(B) // (above), we MUST include a call to set_tris_b() at startup. // set_tris_a(IRX_A_TRIS); set_tris_b(IRX_B_TRIS); // This data should be read from the EEPROM RF_data[0] = 4; RF_data[1] = 3; RF_data[2] = 2; RF_data[3] = 1; RF_data[4] = 9; // See RF_TX() for how Check Bytes are calculated. RF_data[5] = 6; // Ditto. for (i = 0; i < 4; i++) { RED_LED_ON; // reality check at startup to indicate we are alive delay_ms(125); RED_LED_OFF; delay_ms(125); } setup_counters(RTCC_INTERNAL, WDT_288MS); i = 0; while (1) { RF_TX(); // Transmit our unique ID // delay based on ID, then sleep. delay_ms(RF_data[i]); if (i==5) i=0; else i++; restart_wdt(); sleep(); } }