hw-rollerderby-scoreboard/avr.c

44 lines
754 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-07-02 19:54:39 -06:00
/* Clock must be a multiple of 2MHz or there will be clock drift */
#define TICKS_PER_SECOND (CLOCK_HZ / 64)
2013-06-30 14:57:44 -06:00
#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;
2013-07-02 19:54:39 -06:00
TCCR1B |= _BV(WGM12);
TCCR1B |= _BV(CS11) | _BV(CS10);
TIMSK1 |= _BV(OCIE1A);
2013-07-14 07:51:30 -06:00
bit(PORTA, _BV(7), true);
2013-06-30 14:57:44 -06:00
sei();
2013-03-31 21:13:51 -06:00
}