void display_init(uint8_t brightness) { // outputs DATA_DDR |= _BV(DATA_BIT); CLOCK_DDR |= _BV(CLOCK_BIT); LATCH_DDR |= _BV(LATCH_BIT); BLANK_DDR |= _BV(BLANK_BIT); // inputs SIGNATURE_DDR &= ~(_BV(SIGNATURE_BIT_0)); SIGNATURE_DDR &= ~(_BV(SIGNATURE_BIT_1)); SIGNATURE_DDR &= ~(_BV(SIGNATURE_BIT_2)); // enable pullups for shield bits SIGNATURE_PORT |= _BV(SIGNATURE_BIT_0); SIGNATURE_PORT |= _BV(SIGNATURE_BIT_1); SIGNATURE_PORT |= _BV(SIGNATURE_BIT_2); LATCH_ENABLE; clear_display(); detect_shield(); // Inititalize timer for multiplexing TCCR0B |= (1<<CS01); // Set Prescaler to clk/8 : 1 click = 1us. CS21=1 TIMSK0 |= (1<<TOIE0); // Enable Overflow Interrupt Enable TCNT0 = 0; // Initialize counter set_brightness(brightness); }
void display_init(uint8_t brightness) { // outputs DATA_DDR |= _BV(DATA_BIT); CLOCK_DDR |= _BV(CLOCK_BIT); STROBE_DDR |= _BV(STROBE_BIT); BLANK_DDR |= _BV(BLANK_BIT); EXTRA1_DDR |= _BV(EXTRA1_BIT); EXTRA2_DDR |= _BV(EXTRA2_BIT); EXTRA1_LOW; EXTRA2_LOW; STROBE_LOW; BLANK_LOW; // Unblank display clear_display(); detect_shield(); // PD2 is Strobe // PB2/OC0A is Blank (with 10k pullup) // We use Timer0 for both the display multiplext interrupt // and for PWM on OC0A for blanking // Inititalize Timer1 for multiplexing interrupt // TCCR1B = (1<<CS11); // Set Prescaler to clk/8 : 1 click = 1us. CS01=1 // TCCR1B = (1<<CS10); // Set Prescaler to clk/1 : 1 click = 1us. CS00=1 (8 bit timer) // TCCR1A |= _BV(WGM10); // Set TOP 0x00ff - makes Timer1 an 8 bit timer // TIMSK |= (1<<TOIE1); // Enable Overflow Interrupt // TCNT1 = 0; // Initialize counter // Inititalize Timer0 for PWM on PB2/OC0A (Blank) TCCR0B = (1<<CS00); // Set Prescaler to clk: 1 click = ???. CS00=1 // fast PWM, 8 bit (TOP=0xff), clear OC0A (Blank pin) on match TCCR0A |= _BV(COM0A1) | _BV(WGM01) | _BV(WGM00); TIMSK |= (1<<TOIE0); // Enable Timer0 Overflow Interrupt for Strobe TCNT0 = 0; // Initialize counter set_brightness(10); }