int main(void) { di(); OSCCON = 0x78; led_init(); //sound_init(); radio_init(); motors_init(); adc_init(); ei(); while (1) { /* Listen for incoming radio packet */ if (radio_rx()) { /* If a radio packet is pending * send it immediately */ if (radio_len != 0) { /* Send a packet */ unsigned char c; LATB |= 0x01; radio_tx_start(); radio_tx_data(radio_len); for (c = 0; c < radio_len; c++) radio_tx_data(radio_data[c]); radio_tx_finish(); LATB &= ~0x01; } } /* Read ADC values sequentally */ { static char adc_ptr = 0; const char adc_addr[6] = {4, 15, 11, 9, 30, 13}; /* Reading value */ char adc_id = adc_addr[adc_ptr]; adc_measure(adc_id); adc_data[adc_ptr << 1] = ADRESH; adc_data[(adc_ptr << 1) | 1] = ADRESL; /* Incrementing address */ adc_ptr++; if (adc_ptr >= 6) adc_ptr = 0; #ifdef FALSE_DEF /* Checking battery voltage */ if (adc_id == 13) { /* Voltage less then 3.0V */ if (ADRESH == 0 && ADRESL < 144) { /* Power off */ LATA = 0; LATB = 0; LATC = 0; di(); SLEEP(); } } #endif } } }
void radio_tx_finish() { radio_tx_data(radio_tx_crc); radio_off(); ei(); }
//*********************************************************************** //** Function: packet_tx //** //** Description: Transmits a packet //** //** Parameters: void *data - Pointer to data to transmit //** char len - Number of bytes to transmit //** Returns: None //*********************************************************************** void packet_tx(void *data, char len) { (void)radio_tx_data(len, data); }