2013-03-27 21:50:31 -06:00
|
|
|
#include <avr/io.h>
|
2013-06-30 14:19:41 -06:00
|
|
|
#include <avr/interrupt.h>
|
|
|
|
|
|
|
|
/* This only works out for a 16MHz or 8MHz clock */
|
|
|
|
#define CLOCK_HZ 16000000
|
|
|
|
#define TICKS_PER_SECOND (CLOCK_HZ / 256)
|
|
|
|
#define TICKS_PER_JIFFY (TICKS_PER_SECOND / 10)
|
|
|
|
|
|
|
|
volatile uint32_t jiffies = 0;
|
|
|
|
|
|
|
|
ISR(TIM1_COMPA_vect)
|
2013-03-07 23:55:05 -07:00
|
|
|
{
|
2013-06-30 14:19:41 -06:00
|
|
|
jiffies += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
unsigned char counter;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set PORTB for output
|
|
|
|
*/
|
|
|
|
DDRB = 0xFF;
|
|
|
|
PORTB = 0x00;
|
|
|
|
|
|
|
|
TCCR1A = 0;
|
|
|
|
TCCR1B = 0;
|
|
|
|
TCNT1 = 0;
|
|
|
|
OCR1A = TICKS_PER_JIFFY - 1;
|
|
|
|
TCCR1B |= (1 << WGM12);
|
|
|
|
TCCR1B |= (1 << CS12);
|
|
|
|
TIMSK1 |= (1 << OCIE1A);
|
|
|
|
|
|
|
|
sei();
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
PORTB = 0xFF * ((jiffies/ 10) % 2);
|
2013-03-27 21:50:31 -06:00
|
|
|
}
|
2013-06-30 14:19:41 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|