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 mode(on) bit(PORTA, _BV(0), on)
#define sin(on) bit(PORTA, _BV(1), on)
#define sclk(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 sin(on) bit(PORTA, _BV(0), on)
#define sclk(on) bit(PORTA, _BV(1), on)
#define sltch(on) bit(PORTA, _BV(2), on)
#define NESOUT 6
#define nesclk(on) bit(PORTA, _BV(4), on)
#define nesltch(on) bit(PORTA, _BV(5), on)
#define nesclk(on) bit(PORTA, _BV(3), on)
#define nesltch(on) bit(PORTA, _BV(4), on)
#define NESOUT 5
#define nesout() ((PINA & _BV(NESOUT)) << NESOUT)
void init(void);

Binary file not shown.

91
main.c
View File

@ -9,7 +9,7 @@
// Number of shift registers in your scoreboard
// If you want scores to go over 199, you need 8
const int nsr = 6;
const int nsr = 8;
//
// Timing stuff
@ -62,8 +62,8 @@ const uint8_t setup_digits[] = {
void
latch()
{
xlat(true);
xlat(false);
sltch(true);
sltch(false);
}
void
@ -82,12 +82,9 @@ write(uint8_t number)
// MSB first
for (i = 7; i >= 0; i -= 1) {
sin(number & (1 << i));
for (j = 0; j < 12; j += 1) {
pulse();
}
}
}
void
write_num(uint16_t number, int digits)
@ -99,8 +96,13 @@ write_num(uint16_t number, int digits)
// Overflow indicator
if ((i == digits - 1) && (number > 9)) {
// Blink to indicate double-rollover
if ((number > 19) && (jiffies % 3 == 0)) {
// leave it blank
} else {
out ^= 0x80;
}
}
write(out);
number /= 10;
@ -113,39 +115,51 @@ write_num(uint16_t number, int digits)
void
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);
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[1]);
write(setup_digits[1]);
write(setup_digits[0]);
} else {
clk = (abs(jam_clock / 600) % 10) * 1000;
clk += abs(jam_clock) % 600;
write_num(clk, 4);
write_num(pclk, 4);
}
if ((state == TIMEOUT) && (jam_clock % 8 == 0)) {
// Blank it out
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);
}
// Jam clock, most significant half
write_num(jclk / 100, 2);
// Score A
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();
pulse();
}
@ -192,6 +206,10 @@ update_controller()
last_change = jiffies;
last_val = cur;
}
// Select means subtract
if (cur & BTN_SELECT) {
inc = -1;
}
if ((pressed & BTN_A) && ((state != JAM) || (jam_clock == 0))) {
state = JAM;
@ -241,33 +259,22 @@ update_controller()
void
setup()
{
int i;
// The TLC5941 required some setup.
// The TPIC doesn't.
// Hooray.
// TLC594 datasheet says you have to do this before DC initialization.
// 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);
PORTB = 0xff;
}
void
loop()
{
uint32_t i;
update_controller();
if (tick) {
tick = false;
update_controller();
if (jiffies % 10 == 0) {
if (jiffies % 5 == 0) {
PORTB ^= 0xff;
}
@ -285,10 +292,10 @@ loop()
jam_clock += 1;
}
}
}
draw();
}
}
int
main(void)