int main( void ) { /* init peripherals */ timer_init(); uart_init(); soft_uart_init(); adc_init(); sei(); /* enter mainloop */ while( 1 ) { if(timer_periodic()) periodic_task(); if (soft_uart_error) { LINK_TMTC_SEND_ERROR(soft_uart_error); soft_uart_error = 0; } if (soft_uart_got_byte) { input_buf[input_buf_idx] = soft_uart_byte; input_buf_idx++; if (input_buf_idx >= INPUT_BUF_LEN) { LINK_TMTC_SEND_DATA(input_buf, input_buf_idx); input_buf_idx = 0; } soft_uart_got_byte = FALSE; } if (adc_got_val) { saved_valim = adc_alim; adc_got_val = FALSE; } } return 0; }
int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer if (CALBC1_1MHZ==0xFF) { // If calibration constants erased while(1); // do not load, trap CPU!! } // Frequency DCOCTL = 0; // Select lowest DCOx and MODx settings BCSCTL1 = CALBC1_1MHZ; // 1mhz is required for the UART DCOCTL = CALDCO_1MHZ; // UART P1SEL = UART_TXD + UART_RXD; // Timer function for TXD/RXD pins P1DIR |= UART_TXD; // ADC /* P1SEL |= BIT3; // ADC input pin P1.3 */ /* // Vcc & Vss as reference, Sample and hold for 64 Clock cycles, ADC on */ /* // Don't use interrupts just poll */ /* ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON; */ /* ADC10CTL1 = INCH_3 + ADC10DIV_3 ; // Channel 3, ADC10CLK/3 */ /* ADC10AE0 |= BIT3; */ __enable_interrupt(); soft_uart_init(NULL); // Start Timer_A UART for (;;) { // Update board outputs according to received byte unsigned char rxBuffer = soft_uart_get(); char value_string[5] = { 0 }; switch (rxBuffer) { case '1': /* __delay_cycles(1000); */ /* ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start */ /* while (ADC10CTL1 & BUSY); */ /* // itoa(adc_step_to_volt(ADC10MEM, 3000, 1024), value_string, 10); */ /* itoa(ADC10MEM, value_string, 10); */ itoa(ADC_single_meas(INCH_4), value_string, 10); soft_uart_print("A3: "); soft_uart_print(value_string); soft_uart_print("mV\r\n"); break; default: break; } } }
void setup_hw(void) { /* * save some power * */ DDRB = 0x00; // all inputs PORTB = 0xFF; // all pull-ups on ACSR |= _BV(ACD); // disable the analog comparator, ACIE is already zero (default value) PRR |= _BV(PRTIM1) | _BV(PRUSI) | _BV(PRADC); // turn off the clock for TIMER1, USI and ADC system_ticker_setup(); sei(); // turn global irq flag on, also needed as a wakeup source #ifdef USE_PWM setup_pwm(); #endif soft_uart_init(); }