Library for Sure Electronics HT1632 based LED matrix displays. Supports multiple displays connected together.
Dependents: HT1632MsgScroller SMS_LEDMatrixPrinter
Revision 14:b051965066db, committed 2013-07-29
- Comitter:
- SomeRandomBloke
- Date:
- Mon Jul 29 21:10:07 2013 +0000
- Parent:
- 13:9a869360d0ae
- Child:
- 15:9323fab1db01
- Commit message:
- Updated library to specify pin names in constructor
Changed in this revision
HT1632_LedMatrix.cpp | Show annotated file Show diff for this revision Revisions of this file |
HT1632_LedMatrix.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/HT1632_LedMatrix.cpp Mon Apr 08 20:54:20 2013 +0000 +++ b/HT1632_LedMatrix.cpp Mon Jul 29 21:10:07 2013 +0000 @@ -53,17 +53,12 @@ * For mbed, use WR=p7, DATA=p5, cs1=p17, cs2=p18, cs3=p19, cs4=p20 */ -DigitalOut ht1632_wrclk(p7); -DigitalOut ht1632_data(p5); -DigitalOut ht1632_cs1(p17); -DigitalOut ht1632_cs2(p18); -DigitalOut ht1632_cs3(p19); -DigitalOut ht1632_cs4(p20); - // CS pins 17, 18, 19, 20 used. -//DigitalOut ht1632_cs[4] = {p17, p18, p19, p20}; // Chip Select (1, 2, 3, 4) -//DigitalOut ht1632_cs[4] = {p19, p18, p20, p17}; // Chip Select (1, 2, 3, 4) -DigitalOut ht1632_cs[4] = {p19, p17, p18, p20}; // Chip Select (1, 2, 3, 4) +// Stripboard +//DigitalOut _cs[4] = {p17, p18, p19, p20}; // Chip Select (1, 2, 3, 4) +// PCB +DigitalOut *_cs[4]; // = { NC,NC,NC,NC}; //= { +//p19, p17, p18, p20}; // Chip Select (1, 2, 3, 4) // helper macros #define chip_number(x,y) (x >> 5) + (y >> 3)*numYDevices @@ -107,14 +102,21 @@ }; -// Default constructor -HT1632_LedMatrix::HT1632_LedMatrix( void ) +// Default constructor p19, p17, p18, p20 +//HT1632_LedMatrix::HT1632_LedMatrix( void ) { } + +HT1632_LedMatrix::HT1632_LedMatrix( PinName _clk, PinName _dat, PinName cs1, PinName cs2, PinName cs3, PinName cs4 ) : + _wrclk(_clk), _data(_dat), _cs1(cs1), _cs2(cs2), _cs3(cs3), _cs4(cs4) { + _cs[0] = &_cs1; + _cs[1] = &_cs2; + _cs[2] = &_cs3; + _cs[3] = &_cs4; } - 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; @@ -133,7 +135,11 @@ // Disable all display CS lines by taking high for( uint8_t i = 0; i < 4; i++ ) - ht1632_cs[i] = HIGH; + _cs[i] = HIGH; +// _cs1 = HIGH; +// _cs2 = HIGH; +// _cs3 = HIGH; +// _cs4 = HIGH; for (uint8_t chipno=0; chipno<4; chipno++) { chipfree(chipno); // unselect it @@ -157,6 +163,7 @@ } cursorX = 0; cursorY = 0; + } void HT1632_LedMatrix::displayOff( void ) @@ -184,14 +191,12 @@ ***********************************************************************/ void HT1632_LedMatrix::chipselect(uint8_t chipno) { -// for(int i=0; i<4; i++) - ht1632_cs[chipno] = LOW; + *_cs[chipno] = LOW; } void HT1632_LedMatrix::chipfree(uint8_t chipno) { -// for(int i=0; i<4; i++) - ht1632_cs[chipno] = HIGH; + *_cs[chipno] = HIGH; } /** @@ -204,13 +209,14 @@ void HT1632_LedMatrix::writebits (uint8_t bits, uint8_t firstbit) { while (firstbit) { - ht1632_wrclk = LOW; + _wrclk = LOW; +// for( int i=0; i<2; i++); if (bits & firstbit) { - ht1632_data = HIGH; + _data = HIGH; } else { - ht1632_data = LOW; + _data = LOW; } - ht1632_wrclk = HIGH; + _wrclk = HIGH; firstbit >>= 1; } } @@ -224,9 +230,10 @@ void HT1632_LedMatrix::writedatabits (uint8_t bits, uint8_t count) { while (count) { - ht1632_wrclk = LOW; - ht1632_data = bits & 1; - ht1632_wrclk = HIGH; + _wrclk = LOW; +// for( int i=0; i<2; i++); + _data = bits & 1; + _wrclk = HIGH; count--; bits >>= 1; } @@ -408,24 +415,26 @@ return colsLeft; } -int HT1632_LedMatrix::_putc(int c) { - if (c == '\n') { - cursorY += 8; - cursorX = 0; - } else if (c == '\r') { - // skip em - } else { - putChar(cursorX, cursorY, c); - cursorX += 6; +int HT1632_LedMatrix::_putc(int c) +{ + if (c == '\n') { + cursorY += 8; + cursorX = 0; + } else if (c == '\r') { + // skip em + } else { + putChar(cursorX, cursorY, c); + cursorX += 6; // if (wrap && (cursorX > (_width - 6))) { // cursorY += 8; // cursorX = 0; // } - } + } - return c; + return c; } -int HT1632_LedMatrix::_getc() { +int HT1632_LedMatrix::_getc() +{ return -1; }
--- a/HT1632_LedMatrix.h Mon Apr 08 20:54:20 2013 +0000 +++ b/HT1632_LedMatrix.h Mon Jul 29 21:10:07 2013 +0000 @@ -45,10 +45,11 @@ #ifndef _HT1632_LEDMATRIX_H #define _HT1632_LEDMATRIX_H -#include <inttypes.h> +#include "mbed.h" +#include "inttypes.h" // To include the graphic functions use the following. Comment out to exclude them -#define USE_GRAPHIC +#undef USE_GRAPHIC // Defines for display sizes #define HT1632_08x32 1 @@ -85,72 +86,12 @@ */ class HT1632_LedMatrix : public Stream { -private: - /** Select a specific display, numbers as 0 to 3 - * - * @param chip number - */ - void chipselect( uint8_t ); - /** Deselect a specific display, numbers as 0 to 3 - * - * @param chip number - */ - void chipfree( uint8_t ); - - /** 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. - * @param bits - * @param firstbit - */ - void writebits( uint8_t, uint8_t ); - - /** 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 - * @param bits - * @param count - */ - void writedatabits( uint8_t, uint8_t ); - - /** * Send a command to the ht1632 chip. - * A command consists of a 3-bit "CMD" ID, an 8bit command, and - * one "don't care bit". - * Select 1 0 0 c7 c6 c5 c4 c3 c2 c1 c0 xx Free - * @param chipno the number of the chip/display to write command to - * @param command to send - */ - void sendcmd( uint8_t, uint8_t ); - - /** Send a nibble (4 bits) of data to a particular memory location of the - * ht1632. The command has 3 bit ID, 7 bits of address, and 4 bits of data. - * Select 1 0 1 A6 A5 A4 A3 A2 A1 A0 D0 D1 D2 D3 Free - * Note that the address is sent MSB first, while the data is sent LSB first! - * This means that somewhere a bit reversal will have to be done to get - * zero-based addressing of words and dots within words. - * @param chipno - * @param address - * @param data - */ - void senddata( uint8_t, uint8_t, uint8_t ); - - /** Send a byte of data to a particular memory location of the - * ht1632. The command has 3 bit ID, 7 bits of address, and 8 bits of data. - * Select 1 0 1 A6 A5 A4 A3 A2 A1 A0 D0 D1 D2 D3 D4 D5 D6 D7 D8 Free - * Note that the address is sent MSB first, while the data is sent LSB first! - * This means that somewhere a bit reversal will have to be done to get - * zero-based addressing of words and dots within words. - * @param chipno - * @param address - * @param data - */ - void sendcol( uint8_t, uint8_t, uint8_t ); - public: /** Default Constructor for the display driver */ - HT1632_LedMatrix( ); +// HT1632_LedMatrix( ); + HT1632_LedMatrix( PinName clk, PinName dat, PinName cs1, PinName cs2 , PinName cs3, PinName cs4); + /** Initialise the library with the display configuration * @param Number of horizontal displays, max 4 @@ -307,7 +248,76 @@ unsigned char r, unsigned char c); #endif -protected: +private: + /** Select a specific display, numbers as 0 to 3 + * + * @param chip number + */ + void chipselect( uint8_t ); + /** Deselect a specific display, numbers as 0 to 3 + * + * @param chip number + */ + void chipfree( uint8_t ); + + /** 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. + * @param bits + * @param firstbit + */ + void writebits( uint8_t, uint8_t ); + + /** 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 + * @param bits + * @param count + */ + void writedatabits( uint8_t, uint8_t ); + + /** * Send a command to the ht1632 chip. + * A command consists of a 3-bit "CMD" ID, an 8bit command, and + * one "don't care bit". + * Select 1 0 0 c7 c6 c5 c4 c3 c2 c1 c0 xx Free + * @param chipno the number of the chip/display to write command to + * @param command to send + */ + void sendcmd( uint8_t, uint8_t ); + + /** Send a nibble (4 bits) of data to a particular memory location of the + * ht1632. The command has 3 bit ID, 7 bits of address, and 4 bits of data. + * Select 1 0 1 A6 A5 A4 A3 A2 A1 A0 D0 D1 D2 D3 Free + * Note that the address is sent MSB first, while the data is sent LSB first! + * This means that somewhere a bit reversal will have to be done to get + * zero-based addressing of words and dots within words. + * @param chipno + * @param address + * @param data + */ + void senddata( uint8_t, uint8_t, uint8_t ); + + /** Send a byte of data to a particular memory location of the + * ht1632. The command has 3 bit ID, 7 bits of address, and 8 bits of data. + * Select 1 0 1 A6 A5 A4 A3 A2 A1 A0 D0 D1 D2 D3 D4 D5 D6 D7 D8 Free + * Note that the address is sent MSB first, while the data is sent LSB first! + * This means that somewhere a bit reversal will have to be done to get + * zero-based addressing of words and dots within words. + * @param chipno + * @param address + * @param data + */ + void sendcol( uint8_t, uint8_t, uint8_t ); + + DigitalOut _wrclk; + DigitalOut _data; + DigitalOut _cs1; + DigitalOut _cs2; + DigitalOut _cs3; + DigitalOut _cs4; + +//protected: virtual int _putc(int value); virtual int _getc();