Library for Sure Electronics HT1632 based LED matrix displays. Supports multiple displays connected together.
Dependents: HT1632MsgScroller SMS_LEDMatrixPrinter
Diff: HT1632_LedMatrix.cpp
- Revision:
- 9:8a3c981babd9
- Parent:
- 8:61130f9b5b79
- Child:
- 10:af973a9c48b2
--- a/HT1632_LedMatrix.cpp Sat Nov 24 21:58:03 2012 +0000 +++ b/HT1632_LedMatrix.cpp Wed Nov 28 14:03:35 2012 +0000 @@ -75,6 +75,8 @@ uint8_t numYDevices = 1; // Number of vertical devices uint8_t xMax = 32 * numXDevices-1; uint8_t yMax = 8 * numYDevices-1; +uint8_t displayWidth = 32; +uint8_t displayHeight = 8; // Variables used to keep track of cursor position int cursorX = 0; @@ -109,15 +111,24 @@ } -void HT1632_LedMatrix::init( uint8_t xDevices, uint8_t yDevices ) +void HT1632_LedMatrix::init( uint8_t xDevices, uint8_t yDevices, uint8_t displayType ) { // Set up the display size based on number of devices both horizontal and vertical + numXDevices = xDevices; - xMax = 32 * numXDevices-1; numYDevices = yDevices; - yMax = 8 * numYDevices-1; numDevices = numXDevices * numYDevices; + if( displayType == HT1632_24x16 ) { + displayWidth = 24; + displayHeight = 16; + } else { + displayWidth = 32; + displayHeight = 8; + } + xMax = displayWidth * numXDevices-1; + yMax = displayHeight * numYDevices-1; + // Disable all display CS lines by taking high for( uint8_t i = 0; i < 4; i++ ) ht1632_cs[i] = HIGH; @@ -129,8 +140,13 @@ sendcmd(chipno, HT1632_CMD_LEDON); // LEDs on sendcmd(chipno, HT1632_CMD_BLOFF); // Blink Off sendcmd(chipno, HT1632_CMD_MSTMD); // Master Mode - sendcmd(chipno, HT1632_CMD_RCCLK); // Internal Oscillator - sendcmd(chipno, HT1632_CMD_COMS00); // 08*32, NMOS drivers + sendcmd(chipno, HT1632_CMD_RCCLK); // Internal Oscillator + if( displayType == HT1632_24x16 ) { +// TODO - check + sendcmd(chipno, HT1632_CMD_COMS10); // 16*24, NMOS drivers + } else { + sendcmd(chipno, HT1632_CMD_COMS00); // 08*32, NMOS drivers + } sendcmd(chipno, HT1632_CMD_PWM | 0x0c); // PWM Duty for (uint8_t i=0; i<96; i++) @@ -176,9 +192,9 @@ ht1632_cs[chipno] = HIGH; } -/* +/** * writebits - * Write bits to h1632 on pins HT1632_DATA, HT1632_WRCLK + * Write bits to HT1632 on pins HT1632_DATA, HT1632_WRCLK * Chip is assumed to already be chip-selected * Bits are shifted out from MSB to LSB, with the first bit sent * being (bits & firstbit), shifted till firsbit is zero. @@ -199,7 +215,7 @@ /* * writedatabits - * Write databits to h1632 on pins HT1632_DATA, HT1632_WRCLK + * Write databits to HT1632 on pins HT1632_DATA, HT1632_WRCLK * Chip is assumed to already be chip-selected * Bits are shifted out from LSB to MSB */ @@ -245,7 +261,7 @@ chipselect(chipno); // Select chip writebits(HT1632_ID_WR, 0x04); // send ID: WRITE to RAM writebits(0, 0x40); // Send address - for (i = 0; i < 32; i++) // Clear entire display + for (i = 0; i < displayWidth; i++) // Clear entire display writedatabits(0, 8); // send 8 bits of data chipfree(chipno); // done for (i=0; i < 64; i++) @@ -313,7 +329,7 @@ } /* - * Copy a character glyph from the smallFont data structure to + * Copy a character glyph from the font data structure to * display memory, with its upper left at the given coordinate * This is unoptimized and simply uses plot() to draw each dot. */ @@ -323,7 +339,7 @@ } /* - * Copy a character glyph from the myfont data structure to + * Copy a character glyph from the font data structure to * display memory, with its upper left at the given coordinate * This is unoptimized and simply uses plot() to draw each dot. * returns number of columns that didn't fit @@ -358,7 +374,7 @@ chipno = chip_number(x,y); addr = chip_byte_address(x,y); // compute which memory byte this is in if (x <= xMax && y <= yMax) { - shadowram[(addr>>1)+32*chipno] = colData; + shadowram[(addr>>1) + displayWidth * chipno] = colData; sendcol(chipno,addr,colData); x++; } else { @@ -375,7 +391,7 @@ chipno = chip_number(x,y); addr = chip_byte_address(x,y); // compute which memory byte this is in if (x <= xMax && y <= yMax) { - shadowram[(addr>>1)+32*chipno] = colData; + shadowram[(addr>>1) + displayWidth * chipno] = colData; sendcol(chipno,addr,colData); x++; } else { @@ -435,12 +451,12 @@ char bitval = 1<<(y&7); // compute which bit will need set if (val) { // Modify the shadow memory - shadowram[shadowAddress +32*chipno] |= bitval; + shadowram[shadowAddress + displayWidth * chipno] |= bitval; } else { - shadowram[shadowAddress +32*chipno] &= ~bitval; + shadowram[shadowAddress + displayWidth * chipno] &= ~bitval; } // Now copy the new memory value to the display - sendcol(chipno, addr, shadowram[shadowAddress +32*chipno]); + sendcol(chipno, addr, shadowram[shadowAddress + displayWidth * chipno]); } @@ -493,7 +509,7 @@ void HT1632_LedMatrix::putShadowRam(uint8_t chipno) { for (int i=0; i<64; i+=2) { - sendcol(chipno,i,shadowram[(i>>1)+32*chipno]); + sendcol(chipno,i,shadowram[(i>>1)+ displayWidth * chipno]); } }