#include /* Standard Integer Types */ #include /* Standard IO facilities */ #include /* General utilities */ #include /* Strings */ #include /* AVR device-specific IO definitions */ #include /* Convenience functions for busy-wait delay loops */ #include /* Interrupts */ #include "main.h" #include "uart.h" /* global variables */ volatile uint8_t pwr_ok; /* is power ok */ volatile uint8_t fan; /* fan signal state, to measure tachometer */ volatile uint8_t timer2_ovf = 0; /* to measure fan speed using timer 2 */ static const uint16_t TIMER2_PRESCALE[8] = {0,1,8,32,64,128,256,1024}; /* timer 2 CS2[2:0] values */ volatile uint16_t tachometer = 0; /* the tachometer time (from timer) */ volatile uint8_t ir; /* IR signal state, to measure IR code */ volatile uint8_t pulse_i = 1; /* pulse index */ # define PULSE_MAX 64 /* maximum number of pulses to save */ volatile uint16_t pulse[PULSE_MAX]; /* pulse times (from timer) */ /* power ok interrupt */ ISR(PCINT0_vect) { /* PCI0 Interrupt Vector for PCINT[7:0] */ if (pwr_ok!=(PINB&(1<0) { /* save pulse, except the first */ pulse[pulse_i-1] = TCNT1; pulse[pulse_i] = 0; } if (pulse_i0) { pulse_i = 0; OCR0A = ~OCR0A; } } static void ioinit(void) { /* configure power */ DDRB |= (1<0) { OCR0A--; } printf("decreasing LED: %u\n",OCR0A); break; case '+': if (OCR0A<0xff) { OCR0A++; } printf("increasing LED: %u\n",OCR0A); break; case 't': if (tachometer) { uint16_t prescale = TIMER2_PRESCALE[TCCR2B&((1<