diff --git a/Makefile b/Makefile index dc5608a..8c163f1 100644 --- a/Makefile +++ b/Makefile @@ -12,12 +12,11 @@ LDFLAGS += -mmcu=$(MCU) AVDFLAGS += -p $(MCU) AVDFLAGS += -c usbtiny -CLOCK_HZ = 1600000 +CLOCK_HZ = 16000000 FUSES += -U lfuse:w:0x7f:m FUSES += -U hfuse:w:0xdd:m FUSES += -U efuse:w:0xff:m - upload: .upload .upload: $(PROG).hex @@ -28,9 +27,10 @@ fuses: avrdude $(AVDFLAGS) $(FUSES) main: main.o avr.o +blink: blink.o avr.o avr.o: CFLAGS += -DCLOCK_HZ=$(CLOCK_HZ) -$(PROG).hex: $(PROG) +%.hex: % avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $< $@ clean: diff --git a/avr.c b/avr.c index 14b1d2c..f85a573 100644 --- a/avr.c +++ b/avr.c @@ -5,8 +5,8 @@ #include "avr.h" /* 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 TICK_HZ (CLOCK_HZ / 8 / 64) +#define TICKS_PER_JIFFY (TICK_HZ / 10) #define cbi(byt, bit) (byt &= ~_BV(bit)) #define sbi(byt, bit) (byt |= _BV(bit)) @@ -31,10 +31,11 @@ init(void) TCCR1A = 0; TCCR1B = 0; - TCNT1 = 0; + TCNT1 = 0; // reset counter + OCR1A = TICKS_PER_JIFFY - 1; TCCR1B |= _BV(WGM12); - TCCR1B |= _BV(CS11) | _BV(CS10); + TCCR1B |= _BV(CS11) | _BV(CS10); // prescale: clk_io / 64 TIMSK1 |= _BV(OCIE1A); bit(PORTA, _BV(7), true); diff --git a/blink.c b/blink.c index 745985b..11952a9 100644 --- a/blink.c +++ b/blink.c @@ -1,41 +1,31 @@ +#include #include #include -/* 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) +#include "avr.h" volatile uint32_t jiffies = 0; +volatile bool tick = false; -ISR(TIM1_COMPA_vect) +void +loop(void) { - jiffies += 1; + if (tick) { + tick = false; + + if (jiffies % 10 == 0) { + PORTB ^= 0xff; + } + } } int main(void) { - unsigned char counter; + init(); - /* - * 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); + for (;;) { + loop(); } return 0; diff --git a/brain.fzz b/brain.fzz index 9f92ee1..071aebf 100644 Binary files a/brain.fzz and b/brain.fzz differ diff --git a/main.c b/main.c index 26bd0e8..35384fc 100644 --- a/main.c +++ b/main.c @@ -145,8 +145,8 @@ draw() return; } - jclk = (abs(jam_clock / 600) % 10) * 1000; - jclk += abs(jam_clock) % 600; + jclk = (abs(jam_clock / 10) / 60) * 100; + jclk += abs(jam_clock / 10) % 60; pclk = (abs(period_clock / 10) / 60) * 100; pclk += abs(period_clock / 10) % 60; @@ -170,10 +170,7 @@ draw() #endif // Score A - write_num(score_b, 2); - - // Jam clock, least significant half - write_num(jclk % 100, 2); + write_num(score_b, 3); // Period clock if (blank) { @@ -190,11 +187,11 @@ draw() write_num(pclk, 4); } - // Jam clock, most significant half - write_num(jclk / 100, 2); + // Jam clock + write_num(jclk, 3); // Score A - write_num(score_a, 2); + write_num(score_a, 3); if (false) { int i;