version used at 28 Jul scrimmage

This commit is contained in:
Neale Pickett 2013-07-28 21:42:25 -06:00
parent 37a9d7c170
commit 7ea4e6e6e0
3 changed files with 74 additions and 71 deletions

16
avr.h
View File

@ -7,17 +7,13 @@
#define bit(pin, bit, on) pin = (on ? (pin | bit) : (pin & ~bit)) #define bit(pin, bit, on) pin = (on ? (pin | bit) : (pin & ~bit))
#define mode(on) bit(PORTA, _BV(0), on) #define sin(on) bit(PORTA, _BV(0), on)
#define sin(on) bit(PORTA, _BV(1), on) #define sclk(on) bit(PORTA, _BV(1), on)
#define sclk(on) bit(PORTA, _BV(2), on) #define sltch(on) bit(PORTA, _BV(2), on)
#define xlat(on) bit(PORTA, _BV(3), on)
// Connect GSCLK to SCLK
// Connect BLANK to XLAT
// TRUST ME, THIS TOTALLY WORKS
#define NESOUT 6 #define nesclk(on) bit(PORTA, _BV(3), on)
#define nesclk(on) bit(PORTA, _BV(4), on) #define nesltch(on) bit(PORTA, _BV(4), on)
#define nesltch(on) bit(PORTA, _BV(5), on) #define NESOUT 5
#define nesout() ((PINA & _BV(NESOUT)) << NESOUT) #define nesout() ((PINA & _BV(NESOUT)) << NESOUT)
void init(void); void init(void);

Binary file not shown.

121
main.c
View File

@ -9,7 +9,7 @@
// Number of shift registers in your scoreboard // Number of shift registers in your scoreboard
// If you want scores to go over 199, you need 8 // If you want scores to go over 199, you need 8
const int nsr = 6; const int nsr = 8;
// //
// Timing stuff // Timing stuff
@ -62,8 +62,8 @@ const uint8_t setup_digits[] = {
void void
latch() latch()
{ {
xlat(true); sltch(true);
xlat(false); sltch(false);
} }
void void
@ -82,10 +82,7 @@ write(uint8_t number)
// MSB first // MSB first
for (i = 7; i >= 0; i -= 1) { for (i = 7; i >= 0; i -= 1) {
sin(number & (1 << i)); sin(number & (1 << i));
pulse();
for (j = 0; j < 12; j += 1) {
pulse();
}
} }
} }
@ -99,7 +96,12 @@ write_num(uint16_t number, int digits)
// Overflow indicator // Overflow indicator
if ((i == digits - 1) && (number > 9)) { if ((i == digits - 1) && (number > 9)) {
out ^= 0x80; // Blink to indicate double-rollover
if ((number > 19) && (jiffies % 3 == 0)) {
// leave it blank
} else {
out ^= 0x80;
}
} }
write(out); write(out);
@ -113,39 +115,51 @@ write_num(uint16_t number, int digits)
void void
draw() draw()
{ {
uint16_t clk;
// XXX testing uint16_t jclk;
uint16_t pclk;
bool blank = ((state == TIMEOUT) && (jiffies % 8 == 0));
jclk = (abs(jam_clock / 600) % 10) * 1000;
jclk += abs(jam_clock) % 600;
pclk = (abs(period_clock / 10) / 60) * 100;
pclk += abs(period_clock / 10) % 60;
// Score A
write_num(score_b, 2); write_num(score_b, 2);
if (state == SETUP) { // Jam clock, least significant half
write_num(jclk % 100, 2);
// Period clock
if (blank) {
write(0);
write(0);
write(0);
write(0);
} else if (state == SETUP) {
write(setup_digits[2]); write(setup_digits[2]);
write(setup_digits[1]); write(setup_digits[1]);
write(setup_digits[1]); write(setup_digits[1]);
write(setup_digits[0]); write(setup_digits[0]);
} else { } else {
clk = (abs(jam_clock / 600) % 10) * 1000; write_num(pclk, 4);
clk += abs(jam_clock) % 600;
write_num(clk, 4);
} }
if ((state == TIMEOUT) && (jam_clock % 8 == 0)) { // Jam clock, most significant half
// Blank it out write_num(jclk / 100, 2);
for (clk = 0; clk < 4; clk += 1) {
write(setup_digits[1]);
}
} else {
clk = (abs(period_clock / 10) / 60) * 100;
clk += abs(period_clock / 10) % 60;
write_num(clk, 4);
}
// Score A
write_num(score_a, 2); write_num(score_a, 2);
write_num(jiffies % 200, 2); if (false) {
int i;
for (i = 0; i < 12; i += 1) {
write_num(jiffies / 10, 1);
}
}
// Tell chips to start displaying new values
latch(); latch();
pulse(); pulse();
} }
@ -192,6 +206,10 @@ update_controller()
last_change = jiffies; last_change = jiffies;
last_val = cur; last_val = cur;
} }
// Select means subtract
if (cur & BTN_SELECT) {
inc = -1;
}
if ((pressed & BTN_A) && ((state != JAM) || (jam_clock == 0))) { if ((pressed & BTN_A) && ((state != JAM) || (jam_clock == 0))) {
state = JAM; state = JAM;
@ -241,53 +259,42 @@ update_controller()
void void
setup() setup()
{ {
int i; // The TLC5941 required some setup.
// The TPIC doesn't.
// Hooray.
// TLC594 datasheet says you have to do this before DC initialization. PORTB = 0xff;
// In practice it doesn't seem to matter, but what the hey.
draw();
// Initialize dot correction logic
mode(true);
sin(true);
for (i = 0; i < nsr * 96; i += 1) {
pulse();
}
latch();
mode(false);
} }
void void
loop() loop()
{ {
uint32_t i; update_controller();
if (tick) { if (tick) {
tick = false; tick = false;
update_controller(); if (jiffies % 5 == 0) {
if (jiffies % 10 == 0) {
PORTB ^= 0xff; PORTB ^= 0xff;
} }
switch (state) { switch (state) {
case SETUP: case SETUP:
break; break;
case JAM: case JAM:
case LINEUP: case LINEUP:
if (period_clock) { if (period_clock) {
period_clock += 1; period_clock += 1;
} }
// fall through // fall through
case TIMEOUT: case TIMEOUT:
if (jam_clock) { if (jam_clock) {
jam_clock += 1; jam_clock += 1;
} }
} }
draw();
} }
draw();
} }
int int