hw-rollerderby-scoreboard/avr.c

43 lines
730 B
C
Raw Normal View History

2013-03-31 21:13:51 -06:00
#include <stdint.h>
#include <stdbool.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "avr.h"
2013-06-30 14:57:44 -06:00
/* 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)
2013-03-31 21:13:51 -06:00
#define cbi(byt, bit) (byt &= ~_BV(bit))
#define sbi(byt, bit) (byt |= _BV(bit))
extern volatile bool tick;
extern volatile uint32_t jiffies;
2013-06-30 14:57:44 -06:00
// Interrupt called every jiffy
ISR(TIM1_COMPA_vect)
2013-03-31 21:13:51 -06:00
{
2013-06-30 14:57:44 -06:00
jiffies += 1;
tick = true;
2013-03-31 21:13:51 -06:00
}
void
init(void)
{
2013-06-30 14:57:44 -06:00
int i;
2013-03-31 21:13:51 -06:00
2013-05-04 19:46:18 -06:00
DDRA = ~(_BV(NESOUT));
2013-03-31 21:13:51 -06:00
DDRB = 0xff;
2013-06-30 14:57:44 -06:00
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = TICKS_PER_JIFFY - 1;
TCCR1B |= (1 << WGM12);
TCCR1B |= (1 << CS12);
TIMSK1 |= (1 << OCIE1A);
sei();
2013-03-31 21:13:51 -06:00
}