/* * $Revision: 1.10 $ * $Date: 2011-02-07 21:39:21 $ * $Author: higgins $ * $State: Exp $ */ #include #include #include "pine_car.h" // there are two main things going on here: // (1) the leds are being pulsed to power consumption, and the // pulsing is being staggered to reduce switching spikes. // (2) on a much slower scale, two leds are flashing. // // (1) should not be perceptable, (2) should. // the timer is set up to create an interrupt every 1mS Led data[N_LEDS] = { // {, , , }, {0, _BV(0), 1, 0}, {2, _BV(1), 1, 0}, {4, _BV(2), 4, 0}, {6, _BV(3), 4, 0}, {8, _BV(4), 10, 0}, {10, _BV(5), 10, 0}, }; // incremented by isr... uint16_t count_ms = 0; ISR(TIMER1_COMPA_vect) { uint8_t phase = count_ms & 0x0f; // use lower 4 bits for delay... uint8_t bits = LED_PORT; // assign to LED_PORT at end... // turn off any leds that have 'expired'... for(uint8_t i = 0; i>8) & 0x1; if (slow_count) { bits &= ~_BV(2); } else { bits &= ~_BV(3); } LED_PORT = bits; count_ms++; } int main(void) { // just for readability... const static int NO_PRESCALING = _BV(CS10); const static int MODE_4_CTC = _BV(WGM12); const static int TIMER1_OUT_COMP_A_INT_ENABLE = _BV(OCIE1A); const static int DELAY = 999; // 1mS @ 1 Mhz TCCR1B = MODE_4_CTC|NO_PRESCALING; TIMSK = TIMER1_OUT_COMP_A_INT_ENABLE; OCR1A = DELAY; LED_PORT = 0; // all off... sei(); DDRB = 0xFF; // set port B to output only while (1) { } }