Allow wider range of clocks

This commit is contained in:
Neale Pickett 2013-07-02 19:54:39 -06:00
parent fa12096630
commit 7c5fd66f92
4 changed files with 25 additions and 31 deletions

View File

@ -12,9 +12,9 @@ LDFLAGS += -mmcu=$(MCU)
AVDFLAGS += -p $(MCU)
AVDFLAGS += -c usbtiny
CLOCK_HZ = 16000000
FUSES += -U lfuse:w:0xff:m
FUSES += -U hfuse:w:0xd9:m
CLOCK_HZ = 2000000
FUSES += -U lfuse:w:0x7f:m
FUSES += -U hfuse:w:0xdd:m
FUSES += -U efuse:w:0xff:m
@ -28,6 +28,7 @@ fuses:
avrdude $(AVDFLAGS) $(FUSES)
main: main.o avr.o
avr.o: CFLAGS += -DCLOCK_HZ=$(CLOCK_HZ)
$(PROG).hex: $(PROG)
avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $< $@

11
avr.c
View File

@ -4,9 +4,8 @@
#include <avr/interrupt.h>
#include "avr.h"
/* This only works out for a 16MHz or 8MHz clock */
#define CLOCK_HZ 16000000
#define TICKS_PER_SECOND (CLOCK_HZ / 256)
/* Clock must be a multiple of 2MHz or there will be clock drift */
#define TICKS_PER_SECOND (CLOCK_HZ / 64)
#define TICKS_PER_JIFFY (TICKS_PER_SECOND / 10)
#define cbi(byt, bit) (byt &= ~_BV(bit))
@ -34,9 +33,9 @@ init(void)
TCCR1B = 0;
TCNT1 = 0;
OCR1A = TICKS_PER_JIFFY - 1;
TCCR1B |= (1 << WGM12);
TCCR1B |= (1 << CS12);
TIMSK1 |= (1 << OCIE1A);
TCCR1B |= _BV(WGM12);
TCCR1B |= _BV(CS11) | _BV(CS10);
TIMSK1 |= _BV(OCIE1A);
sei();
}

4
avr.h
View File

@ -5,10 +5,6 @@
#include <avr/io.h>
#include <avr/interrupt.h>
// Make sure JIFFY_uS is going to be an integer and not a float!
#define JIFFIES_PER_SECOND 100
#define JIFFY_uS (1000000 / JIFFIES_PER_SECOND)
#define bit(pin, bit, on) pin = (on ? (pin | bit) : (pin & ~bit))
#define mode(on) bit(PORTA, _BV(0), on)

4
main.c
View File

@ -133,7 +133,7 @@ draw()
if ((state == TIMEOUT) && (jam_clock % 8 == 0)) {
// Blank it out
for (clk = 0; clk < 4; clk += 1) {
write(0);
write(setup_digits[1]);
}
} else {
clk = (abs(period_clock / 10) / 60) * 100;
@ -254,7 +254,6 @@ loop()
PORTB ^= 0xff;
}
if (jiffies == 0) {
switch (state) {
case SETUP:
break;
@ -272,7 +271,6 @@ loop()
draw();
}
}
}
int