Library for Sure Electronics HT1632 based LED matrix displays. Supports multiple displays connected together.

Dependents:   HT1632MsgScroller SMS_LEDMatrixPrinter

Committer:
SomeRandomBloke
Date:
Tue Nov 20 13:08:43 2012 +0000
Revision:
6:80f554fd77a0
Parent:
5:33b2bfce06b7
Child:
9:8a3c981babd9
tweeks

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SomeRandomBloke 6:80f554fd77a0 1 /** Library for Holtek HT1632 LED driver chip,
SomeRandomBloke 6:80f554fd77a0 2 * As implemented on the Sure Electronics DE-DP10X display board
SomeRandomBloke 6:80f554fd77a0 3 * 8 x 32 dot matrix LED module.)
SomeRandomBloke 6:80f554fd77a0 4 *
SomeRandomBloke 6:80f554fd77a0 5 * Original code by:
SomeRandomBloke 6:80f554fd77a0 6 * Nov, 2008 by Bill Westfield ("WestfW")
SomeRandomBloke 6:80f554fd77a0 7 * Copyrighted and distributed under the terms of the Berkely license
SomeRandomBloke 6:80f554fd77a0 8 * (copy freely, but include this notice of original author.)
SomeRandomBloke 6:80f554fd77a0 9 *
SomeRandomBloke 6:80f554fd77a0 10 * Adapted for 8x32 display by FlorinC.
SomeRandomBloke 6:80f554fd77a0 11 *
SomeRandomBloke 6:80f554fd77a0 12 * Arduino Library Created and updated by Andrew Lindsay October/November 2009
SomeRandomBloke 6:80f554fd77a0 13 *
SomeRandomBloke 6:80f554fd77a0 14 * Ported to Mbed platform by Andrew Lindsay, November 2012
SomeRandomBloke 6:80f554fd77a0 15 *
SomeRandomBloke 6:80f554fd77a0 16 * @author Andrew Lindsay
SomeRandomBloke 6:80f554fd77a0 17 *
SomeRandomBloke 6:80f554fd77a0 18 * @section LICENSE
SomeRandomBloke 6:80f554fd77a0 19 *
SomeRandomBloke 6:80f554fd77a0 20 * Copyright (c) 2012 Andrew Lindsay (andrew [at] thiseldo [dot] co [dot] uk)
SomeRandomBloke 6:80f554fd77a0 21 *
SomeRandomBloke 6:80f554fd77a0 22 * Permission is hereby granted, free of charge, to any person obtaining a copy
SomeRandomBloke 6:80f554fd77a0 23 * of this software and associated documentation files (the "Software"), to deal
SomeRandomBloke 6:80f554fd77a0 24 * in the Software without restriction, including without limitation the rights
SomeRandomBloke 6:80f554fd77a0 25 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
SomeRandomBloke 6:80f554fd77a0 26 * copies of the Software, and to permit persons to whom the Software is
SomeRandomBloke 6:80f554fd77a0 27 * furnished to do so, subject to the following conditions:
SomeRandomBloke 6:80f554fd77a0 28
SomeRandomBloke 6:80f554fd77a0 29 * The above copyright notice and this permission notice shall be included in
SomeRandomBloke 6:80f554fd77a0 30 * all copies or substantial portions of the Software.
SomeRandomBloke 6:80f554fd77a0 31 *
SomeRandomBloke 6:80f554fd77a0 32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
SomeRandomBloke 6:80f554fd77a0 33 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
SomeRandomBloke 6:80f554fd77a0 34 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
SomeRandomBloke 6:80f554fd77a0 35 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
SomeRandomBloke 6:80f554fd77a0 36 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
SomeRandomBloke 6:80f554fd77a0 37 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
SomeRandomBloke 6:80f554fd77a0 38 * THE SOFTWARE.
SomeRandomBloke 6:80f554fd77a0 39 *
SomeRandomBloke 6:80f554fd77a0 40 * @section DESCRIPTION
SomeRandomBloke 6:80f554fd77a0 41 * Definitions for Holtek HT1632 LED driver
SomeRandomBloke 6:80f554fd77a0 42 *
SomeRandomBloke 6:80f554fd77a0 43 */
SomeRandomBloke 4:7513dd37efed 44
SomeRandomBloke 4:7513dd37efed 45 #ifndef _HT1632_LEDMATRIX_H
SomeRandomBloke 4:7513dd37efed 46 #define _HT1632_LEDMATRIX_H
SomeRandomBloke 4:7513dd37efed 47
SomeRandomBloke 6:80f554fd77a0 48 // To include the graphic functions use the following. Comment out to exclude them
SomeRandomBloke 4:7513dd37efed 49 #define USE_GRAPHIC
SomeRandomBloke 4:7513dd37efed 50
SomeRandomBloke 4:7513dd37efed 51 #include <inttypes.h>
SomeRandomBloke 4:7513dd37efed 52
SomeRandomBloke 4:7513dd37efed 53 /*
SomeRandomBloke 4:7513dd37efed 54 * commands written to the chip consist of a 3 bit "ID", followed by
SomeRandomBloke 4:7513dd37efed 55 * either 9 bits of "Command code" or 7 bits of address + 4 bits of data.
SomeRandomBloke 4:7513dd37efed 56 */
SomeRandomBloke 4:7513dd37efed 57 #define HT1632_ID_CMD 4 /* ID = 100 - Commands */
SomeRandomBloke 4:7513dd37efed 58 #define HT1632_ID_RD 6 /* ID = 110 - Read RAM */
SomeRandomBloke 4:7513dd37efed 59 #define HT1632_ID_WR 5 /* ID = 101 - Write RAM */
SomeRandomBloke 4:7513dd37efed 60
SomeRandomBloke 4:7513dd37efed 61 #define HT1632_CMD_SYSDIS 0x00 /* CMD= 0000-0000-x Turn off oscil */
SomeRandomBloke 4:7513dd37efed 62 #define HT1632_CMD_SYSON 0x01 /* CMD= 0000-0001-x Enable system oscil */
SomeRandomBloke 4:7513dd37efed 63 #define HT1632_CMD_LEDOFF 0x02 /* CMD= 0000-0010-x LED duty cycle gen off */
SomeRandomBloke 4:7513dd37efed 64 #define HT1632_CMD_LEDON 0x03 /* CMD= 0000-0011-x LEDs ON */
SomeRandomBloke 4:7513dd37efed 65 #define HT1632_CMD_BLOFF 0x08 /* CMD= 0000-1000-x Blink ON */
SomeRandomBloke 4:7513dd37efed 66 #define HT1632_CMD_BLON 0x09 /* CMD= 0000-1001-x Blink Off */
SomeRandomBloke 4:7513dd37efed 67 #define HT1632_CMD_SLVMD 0x10 /* CMD= 0001-00xx-x Slave Mode */
SomeRandomBloke 4:7513dd37efed 68 #define HT1632_CMD_MSTMD 0x14 /* CMD= 0001-01xx-x Master Mode */
SomeRandomBloke 4:7513dd37efed 69 #define HT1632_CMD_RCCLK 0x18 /* CMD= 0001-10xx-x Use on-chip clock */
SomeRandomBloke 4:7513dd37efed 70 #define HT1632_CMD_EXTCLK 0x1C /* CMD= 0001-11xx-x Use external clock */
SomeRandomBloke 4:7513dd37efed 71 #define HT1632_CMD_COMS00 0x20 /* CMD= 0010-ABxx-x commons options */
SomeRandomBloke 4:7513dd37efed 72 #define HT1632_CMD_COMS01 0x24 /* CMD= 0010-ABxx-x commons options */
SomeRandomBloke 4:7513dd37efed 73 #define HT1632_CMD_COMS10 0x28 /* CMD= 0010-ABxx-x commons options */
SomeRandomBloke 4:7513dd37efed 74 #define HT1632_CMD_COMS11 0x2C /* CMD= 0010-ABxx-x commons options */
SomeRandomBloke 4:7513dd37efed 75 #define HT1632_CMD_PWM 0xA0 /* CMD= 101x-PPPP-x PWM duty cycle */
SomeRandomBloke 4:7513dd37efed 76
SomeRandomBloke 4:7513dd37efed 77 #define PIXEL_OFF 0
SomeRandomBloke 4:7513dd37efed 78 #define PIXEL_ON 1
SomeRandomBloke 4:7513dd37efed 79
SomeRandomBloke 6:80f554fd77a0 80 /** class HT1632_LedMatrix
SomeRandomBloke 6:80f554fd77a0 81 */
SomeRandomBloke 4:7513dd37efed 82 class HT1632_LedMatrix //: public Print
SomeRandomBloke 4:7513dd37efed 83 {
SomeRandomBloke 4:7513dd37efed 84 private:
SomeRandomBloke 6:80f554fd77a0 85 /** Select a specific display
SomeRandomBloke 6:80f554fd77a0 86 *
SomeRandomBloke 6:80f554fd77a0 87 * @param chip number
SomeRandomBloke 6:80f554fd77a0 88 */
SomeRandomBloke 4:7513dd37efed 89 void chipselect( uint8_t );
SomeRandomBloke 4:7513dd37efed 90 void chipfree( uint8_t );
SomeRandomBloke 4:7513dd37efed 91 void writebits( uint8_t, uint8_t );
SomeRandomBloke 4:7513dd37efed 92 void writedatabits( uint8_t, uint8_t );
SomeRandomBloke 4:7513dd37efed 93 void sendcmd( uint8_t, uint8_t );
SomeRandomBloke 4:7513dd37efed 94 void senddata( uint8_t, uint8_t, uint8_t );
SomeRandomBloke 4:7513dd37efed 95 void sendcol( uint8_t, uint8_t, uint8_t );
SomeRandomBloke 4:7513dd37efed 96
SomeRandomBloke 4:7513dd37efed 97 public:
SomeRandomBloke 6:80f554fd77a0 98 /** Default Constructor
SomeRandomBloke 6:80f554fd77a0 99 */
SomeRandomBloke 4:7513dd37efed 100 HT1632_LedMatrix( );
SomeRandomBloke 4:7513dd37efed 101
SomeRandomBloke 4:7513dd37efed 102 // Init/Clear/position functions
SomeRandomBloke 4:7513dd37efed 103 void init( uint8_t, uint8_t );
SomeRandomBloke 5:33b2bfce06b7 104 void displayOff( void ) ;
SomeRandomBloke 5:33b2bfce06b7 105 void displayOn( void ) ;
SomeRandomBloke 4:7513dd37efed 106 void clear(void);
SomeRandomBloke 4:7513dd37efed 107 void setBrightness( unsigned char );
SomeRandomBloke 4:7513dd37efed 108 uint8_t putChar( int, int, char );
SomeRandomBloke 4:7513dd37efed 109 void write( uint8_t );
SomeRandomBloke 4:7513dd37efed 110 void putString( int, int, char* );
SomeRandomBloke 4:7513dd37efed 111 void plot( int, int, char );
SomeRandomBloke 4:7513dd37efed 112 void gotoXY(int , int);
SomeRandomBloke 4:7513dd37efed 113 void getXY(int* , int*);
SomeRandomBloke 4:7513dd37efed 114 void getXYMax(int*, int*);
SomeRandomBloke 4:7513dd37efed 115 void shiftCursorX(int );
SomeRandomBloke 4:7513dd37efed 116 void setCustomChar( int, unsigned char[]);
SomeRandomBloke 4:7513dd37efed 117 void setCustomChar( int, unsigned char[], uint8_t );
SomeRandomBloke 4:7513dd37efed 118 void scrollLeft(uint8_t, uint8_t);
SomeRandomBloke 4:7513dd37efed 119 void putShadowRam();
SomeRandomBloke 4:7513dd37efed 120 void putShadowRam(uint8_t);
SomeRandomBloke 4:7513dd37efed 121 // Graphic functions
SomeRandomBloke 4:7513dd37efed 122 #ifdef USE_GRAPHIC
SomeRandomBloke 4:7513dd37efed 123 void drawLine(unsigned char x1, unsigned char y1,
SomeRandomBloke 4:7513dd37efed 124 unsigned char x2, unsigned char y2, unsigned char c);
SomeRandomBloke 4:7513dd37efed 125 void drawRectangle(unsigned char x1, unsigned char y1,
SomeRandomBloke 4:7513dd37efed 126 unsigned char x2, unsigned char y2, unsigned char c);
SomeRandomBloke 4:7513dd37efed 127 void drawFilledRectangle(unsigned char x1, unsigned char y1,
SomeRandomBloke 4:7513dd37efed 128 unsigned char x2, unsigned char y2, unsigned char c);
SomeRandomBloke 4:7513dd37efed 129 void drawCircle(unsigned char xc, unsigned char yc,
SomeRandomBloke 4:7513dd37efed 130 unsigned char r, unsigned char c);
SomeRandomBloke 4:7513dd37efed 131 #endif
SomeRandomBloke 4:7513dd37efed 132
SomeRandomBloke 4:7513dd37efed 133 };
SomeRandomBloke 4:7513dd37efed 134
SomeRandomBloke 4:7513dd37efed 135 #endif //_HT1632_LEDMATRIX_H