EHL

LedBadgeControl PanelEscape Hatch Labs?

LedBadge

X
  • Error:
    An error occurred while executing this script.
    Please check your request and we will attempt to debug the script with the error log.
  1. define BANK_A 0
  2. define BANK_B 1
  3. define BANK_C 2
  4. define BANK_D 3
  5. define CHARLIE_EXTENT 11
  6. define ARRAY_WIDTH 21
  7. define ARRAY_HEIGHT 7
  1. define sbi(var, mask) ((var) |= (uint8_t)(1 << mask))
  2. define cbi(var, mask) ((var) &= (uint8_t)~(1 << mask))

uint8_t g_BankBReg; uint8_t g_BankBDir; uint8_t g_BankCReg; uint8_t g_BankCDir;

uint8_t g_Rows[] = {PD0, PD1, PD2, PD3, PD4, PD5, PD6}; uint8_t g_currentRow = 0;

uint8_t g_Cols[][2] = { {BANK_C, PC4}, {BANK_C, PC5}, {BANK_C, PC6}, {BANK_C, PC7}, {BANK_B, PB7}, {BANK_B, PB6}, {BANK_B, PB5}, {BANK_B, PB4}, {BANK_B, PB3}, {BANK_B, PB2}, {BANK_B, PB1} };

// This holds the current picture uint8_t g_Matrix[ARRAY_HEIGHT][ARRAY_WIDTH]; uint8_t g_Flip = 0;

void selectRow(uint8_t row, uint8_t flip)

{ DDRC = 0; DDRC = 0; PORTC = 0; PORTC = 0;

DDRD = _BV(g_Rows[row]); PORTD = flip ? 0 : _BV(g_Rows[row]); }

void setColBit(uint8_t x, uint8_t bit, uint8_t flip)

{ if (!bit) return; switch(g_Cols[x][0]) { case BANK_B: sbi(g_BankBDir, g_Cols[x][1]); flip ? sbi(g_BankBReg, g_Cols[x][1]) : cbi(g_BankBReg, g_Cols[x][1]); break; case BANK_C: sbi(g_BankCDir, g_Cols[x][1]); flip ? sbi(g_BankCReg, g_Cols[x][1]) : cbi(g_BankCReg, g_Cols[x][1]); break; } }

void latchBanks()

{ PORTB = g_BankBReg; g_BankBReg = 0; DDRB = g_BankBDir; g_BankBDir = 0; PORTC = g_BankCReg; g_BankCReg = 0; DDRC = g_BankCDir; g_BankCDir = 0; }

void scanRow(uint8_t row, uint8_t flip)

{ if (!flip) { // scan left side (row high, col low) selectRow(row, 0); for (uint8_t x = 0; x < CHARLIE_EXTENT; x++) { setColBit(x, g_Matrix[row][x], 0); } } else { // scan right side(row low, col high) selectRow(row, 1); for (uint8_t x = 0; x < CHARLIE_EXTENT; x++) { setColBit(x, g_Matrix[row][x + CHARLIE_EXTENT], 1); } }

latchBanks(); }


SIGNAL(TIMER1_COMPA_vect){ scanRow(g_currentRow, g_Flip); if (g_Flip) { g_currentRow++; g_currentRow %= ARRAY_HEIGHT; } g_Flip = !g_Flip; }

Last modified 00:58 Sun, 1 May 2011 by Main. Accessed 1,277 times Children What Links Here share Share Except where expressly noted, this work is licensed under a Creative Commons License.