Modify for Susan's second layout

This commit is contained in:
Neale Pickett 2013-12-26 11:47:30 -07:00
parent 4667e6dbfb
commit d619a7a360
5 changed files with 29 additions and 41 deletions

View File

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

9
avr.c
View File

@ -5,8 +5,8 @@
#include "avr.h" #include "avr.h"
/* Clock must be a multiple of 2MHz or there will be clock drift */ /* Clock must be a multiple of 2MHz or there will be clock drift */
#define TICKS_PER_SECOND (CLOCK_HZ / 64) #define TICK_HZ (CLOCK_HZ / 8 / 64)
#define TICKS_PER_JIFFY (TICKS_PER_SECOND / 10) #define TICKS_PER_JIFFY (TICK_HZ / 10)
#define cbi(byt, bit) (byt &= ~_BV(bit)) #define cbi(byt, bit) (byt &= ~_BV(bit))
#define sbi(byt, bit) (byt |= _BV(bit)) #define sbi(byt, bit) (byt |= _BV(bit))
@ -31,10 +31,11 @@ init(void)
TCCR1A = 0; TCCR1A = 0;
TCCR1B = 0; TCCR1B = 0;
TCNT1 = 0; TCNT1 = 0; // reset counter
OCR1A = TICKS_PER_JIFFY - 1; OCR1A = TICKS_PER_JIFFY - 1;
TCCR1B |= _BV(WGM12); TCCR1B |= _BV(WGM12);
TCCR1B |= _BV(CS11) | _BV(CS10); TCCR1B |= _BV(CS11) | _BV(CS10); // prescale: clk_io / 64
TIMSK1 |= _BV(OCIE1A); TIMSK1 |= _BV(OCIE1A);
bit(PORTA, _BV(7), true); bit(PORTA, _BV(7), true);

40
blink.c
View File

@ -1,41 +1,31 @@
#include <stdbool.h>
#include <avr/io.h> #include <avr/io.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
/* This only works out for a 16MHz or 8MHz clock */ #include "avr.h"
#define CLOCK_HZ 16000000
#define TICKS_PER_SECOND (CLOCK_HZ / 256)
#define TICKS_PER_JIFFY (TICKS_PER_SECOND / 10)
volatile uint32_t jiffies = 0; 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 int
main(void) main(void)
{ {
unsigned char counter; init();
/* for (;;) {
* set PORTB for output loop();
*/
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);
} }
return 0; return 0;

BIN
brain.fzz

Binary file not shown.

15
main.c
View File

@ -145,8 +145,8 @@ draw()
return; return;
} }
jclk = (abs(jam_clock / 600) % 10) * 1000; jclk = (abs(jam_clock / 10) / 60) * 100;
jclk += abs(jam_clock) % 600; jclk += abs(jam_clock / 10) % 60;
pclk = (abs(period_clock / 10) / 60) * 100; pclk = (abs(period_clock / 10) / 60) * 100;
pclk += abs(period_clock / 10) % 60; pclk += abs(period_clock / 10) % 60;
@ -170,10 +170,7 @@ draw()
#endif #endif
// Score A // Score A
write_num(score_b, 2); write_num(score_b, 3);
// Jam clock, least significant half
write_num(jclk % 100, 2);
// Period clock // Period clock
if (blank) { if (blank) {
@ -190,11 +187,11 @@ draw()
write_num(pclk, 4); write_num(pclk, 4);
} }
// Jam clock, most significant half // Jam clock
write_num(jclk / 100, 2); write_num(jclk, 3);
// Score A // Score A
write_num(score_a, 2); write_num(score_a, 3);
if (false) { if (false) {
int i; int i;