Esempio n. 1
0
main(void)
{
    serial_baud_9600();
    serial_mode_8e1();
    serial_transmitter_enable();

    sleep_mode_idle();

    /* setup timer2 to trigger interrupt a
     * once every millisecond
     * 128 * (124 + 1) / 16MHz = 1ms */
    timer2_mode_ctc();
    timer2_clock_d128();
    timer2_compare_a_set(124);
    timer2_interrupt_a_enable();

    adc_reference_internal_5v();
    adc_pin_select(5);
    adc_clock_d128();
    adc_trigger_freerunning();
    adc_trigger_enable();
    adc_interrupt_enable();
    adc_enable();

    sei();
    while (1) {
        char *p;

        p = sprint_uint16_b10(buf, value);
        *p++ = '\n';
        *p = '\0';
        serial_puts(buf);
    }
}
Esempio n. 2
0
main()
{
	pin13_mode_output();

	serial_baud_9600();
	serial_mode_8e1();
	serial_transmitter_enable();

	sleep_mode_idle();

	/* setup timer2 to trigger interrupt a
	 * once every millisecond */
	timer2_mode_ctc();
	timer2_compare_a_set(124);
	timer2_clock_d128();
	timer2_interrupt_a_enable();

	sei();
	while (1) {
		uint16_t now = time;

		if (now >= 6000) {
			char *p;

			timer2_clock_reset();
			time = 0;

			p = sprint_uint16_b10(buf, now);
			*p++ = '\n';
			*p = '\0';
			serial_puts(buf);
		}

		sleep_enable();
		sleep_cpu();
		sleep_disable();
	}
}
Esempio n. 3
0
main()
{
	uint8_t state = 0;

	serial_baud_9600();
	serial_mode_8e1();
	serial_transmitter_enable();

	sleep_mode_idle();

	pin13_mode_output();
	pin13_low();

	/* setup timer2 to trigger interrupt a
	 * once every millisecond
	 * 128 * (124 + 1) / 16MHz = 1ms */
	timer2_mode_ctc();
	timer2_clock_d128();
	timer2_compare_a_set(124);
	timer2_interrupt_a_enable();

	adc_reference_internal_5v();
	adc_pin_select(5);
	adc_clock_d128();
	adc_trigger_freerunning();
	adc_trigger_enable();
	adc_interrupt_enable();
	adc_enable();

	sei();
	while (1) {
		uint16_t value;

		cli();
		if (!new_value) {
			sleep_enable();
			sei();
			sleep_cpu();
			sleep_disable();
			continue;
		}
		sei();

		value = adc_data();
		new_value = 0;

		if (state && value < BOUND_LOW) {
			uint16_t now = time;
			char *p;

			timer2_clock_reset();
			time = 0;

			pin13_low();

			p = sprint_uint16_b10(buf, now);
			*p++ = '\n';
			*p = '\0';
			serial_puts(buf);

			state = 0;
			continue;
		}

		if (value > BOUND_HIGH) {
			pin13_high();
			state = 1;
		}
	}
}