Created
December 16, 2011 20:34
-
-
Save szczys/1487851 to your computer and use it in GitHub Desktop.
Balancing LED brightness for Binary Burst Clock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#define F_CPU 1000000 | |
void init_IO(void) { | |
DDRD |= (1<<PD0) | (1<<PD1) | (1<<PD2); | |
PORTD |= (1<<PD0) | (1<<PD1) | (1<<PD2); | |
} | |
void init_Timers(void) { | |
TIMSK0 |= (1<<TOIE0); //enable overflow interrupt | |
TCNT0 = (unsigned char)(signed short)-(((F_CPU / 64) * .0005) + 0.5); //Prewind 500us | |
sei(); //enable global interrupts | |
TCCR0B |= (1<<CS01) | (1<<CS00); //prescaler of 64 | |
} | |
int main (void) { | |
init_IO(); | |
init_Timers(); | |
while(1); | |
} | |
ISR(TIMER0_OVF_vect){ | |
PORTD = 0; | |
static unsigned char state = 0x07; | |
static unsigned char tracker = 0; | |
PORTD = state; | |
TCNT0 = (unsigned char)(signed short)-(((F_CPU / 64) * .0005) + 0.5); //Prewind for next interrupt (500us) | |
if (++tracker > 15) { | |
tracker = 0; | |
state = 0x07; | |
} | |
else if ((tracker > 1) && (tracker < 4)){ | |
state = 0x04; | |
} | |
else state = 0x00; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment