예제 #1
0
파일: main.c 프로젝트: Jimmy-Dinis/flm02
int main(void)
{
	uint8_t i;

	cli();
	MCUSR = 0;
	wdt_disable();

	//TODO replace by an ana comp polling loop
	_delay_ms(10);

	setup_datastructs();
	setup_led();
	setup_ar_uart();
	setup_adc();
	setup_pulse_input();
	setup_analog_comparator();
	setup_timer0();
	setup_timer1();
	
	// initialize the CTRL buffers
	ctrlInit();
	// initialize the SPI in slave mode
	setup_spi(SPI_MODE_0, SPI_MSB, SPI_INTERRUPT, SPI_SLAVE);

	// initialize the Si4421/RFM12 radio and buffers
	rfm12_init();

	// the clk/8 fuse bit is set
	clock_prescale_set(clock_div_1);
	FLAG_CLR_ICF1();
	sei();


	for(;;) {
		if (spi_status & SPI_NEW_CTRL_MSG) {
			ctrlDecode();
			spi_status &= ~SPI_NEW_CTRL_MSG;
		}

		for (i = 0; i < max_analog_sensors; i++) {
			if (state[i].flags & STATE_POWER_CALC) {
				calculate_power(&state[i]);
				state[i].flags &= ~STATE_POWER_CALC;
				state[i].flags |= STATE_POWER;
			}
		}

		rfm12_tick();
	}

	return 0;
}
예제 #2
0
파일: main.c 프로젝트: jgoller/flm02
int main(void)
{
	uint8_t i;

	cli();

	// RS-485: Configure PD5=DE as output pin with low as default
	DDRD |= (1<<DDD5);
	// set high to transmit
	//PORTD |= (1<<PD5);

	setup_datastructs();
	setup_led();
	setup_adc();
	setup_pulse_input();
	setup_analog_comparator();
	setup_timer1();
	
	// initialize the CTRL buffers
	ctrlInit();
	// initialize the UART hardware and buffers
	uartInit();
	// initialize the SPI in slave mode
	setup_spi(SPI_MODE_2, SPI_MSB, SPI_INTERRUPT, SPI_SLAVE);

	sei();


	for(;;) {
		if (spi_status & SPI_NEW_CTRL_MSG) {
			ctrlDecode();
			spi_status &= ~SPI_NEW_CTRL_MSG;
		}

		for (i = 0; i < MAX_ANALOG_SENSORS; i++) {
			if (state[i].flags & STATE_POWER_CALC) {
				calculate_power(&state[i]);
				state[i].flags &= ~STATE_POWER_CALC;
				state[i].flags |= STATE_POWER;
			}
		}
	}

	return 0;
}