7 Segment LED Displaydriver, I2C interface, SAA1064
SAA1064.h@1:79cb73f852da, 2013-09-10 (annotated)
- Committer:
- wim
- Date:
- Tue Sep 10 19:59:35 2013 +0000
- Revision:
- 1:79cb73f852da
- Parent:
- 0:48adc4a70511
First release version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wim | 0:48adc4a70511 | 1 | /* SAA1064 - I2C LED Driver used in multiplex mode (4x 7 Segments and Decimal Point) |
wim | 0:48adc4a70511 | 2 | * Copyright (c) 2013 Wim Huiskamp |
wim | 0:48adc4a70511 | 3 | * |
wim | 0:48adc4a70511 | 4 | * Released under the MIT License: http://mbed.org/license/mit |
wim | 0:48adc4a70511 | 5 | * |
wim | 0:48adc4a70511 | 6 | * version 0.2 Initial Release |
wim | 0:48adc4a70511 | 7 | */ |
wim | 0:48adc4a70511 | 8 | #ifndef _SAA1064_H |
wim | 0:48adc4a70511 | 9 | #define _SAA1064_H |
wim | 0:48adc4a70511 | 10 | |
wim | 1:79cb73f852da | 11 | /** Driver for SAA1064 I2C 4-Digit 7-Segment LED Driver |
wim | 1:79cb73f852da | 12 | * |
wim | 1:79cb73f852da | 13 | * @code |
wim | 1:79cb73f852da | 14 | * #include "mbed.h" |
wim | 1:79cb73f852da | 15 | * #include "SAA1064.h" |
wim | 1:79cb73f852da | 16 | * |
wim | 1:79cb73f852da | 17 | * // I2C Communication |
wim | 1:79cb73f852da | 18 | * I2C i2c_lcd(p28,p27); // SDA, SCL for LPC1768 |
wim | 1:79cb73f852da | 19 | * //I2C i2c_lcd(P0_10,P0_11); // SDA, SCL for LPC812 |
wim | 1:79cb73f852da | 20 | * |
wim | 1:79cb73f852da | 21 | * SAA1064 LED(&i2c_lcd); // I2C bus, Default SAA1064 Slaveaddress |
wim | 1:79cb73f852da | 22 | * |
wim | 1:79cb73f852da | 23 | * int main() { |
wim | 1:79cb73f852da | 24 | * uint8_t count = 0; |
wim | 1:79cb73f852da | 25 | * |
wim | 1:79cb73f852da | 26 | * // Display 0, 1, 2, 3 |
wim | 1:79cb73f852da | 27 | * LED.write(SAA1064_SEGM[0], SAA1064_SEGM[1], SAA1064_SEGM[2], SAA1064_SEGM[3]); |
wim | 1:79cb73f852da | 28 | * wait(1); |
wim | 1:79cb73f852da | 29 | * |
wim | 1:79cb73f852da | 30 | * while(1) { |
wim | 1:79cb73f852da | 31 | * wait(0.3); |
wim | 1:79cb73f852da | 32 | * count++; |
wim | 1:79cb73f852da | 33 | * |
wim | 1:79cb73f852da | 34 | * LED.writeInt(-150 + count, 3, false); // Display value, dont suppress leading zero's |
wim | 1:79cb73f852da | 35 | * } |
wim | 1:79cb73f852da | 36 | * |
wim | 1:79cb73f852da | 37 | * } |
wim | 1:79cb73f852da | 38 | * @endcode |
wim | 1:79cb73f852da | 39 | */ |
wim | 1:79cb73f852da | 40 | |
wim | 1:79cb73f852da | 41 | |
wim | 0:48adc4a70511 | 42 | //Address Defines for SAA1064 |
wim | 0:48adc4a70511 | 43 | #define SAA1064_SA0 0x70 |
wim | 0:48adc4a70511 | 44 | #define SAA1064_SA1 0x72 |
wim | 0:48adc4a70511 | 45 | #define SAA1064_SA2 0x74 |
wim | 0:48adc4a70511 | 46 | #define SAA1064_SA3 0x76 |
wim | 0:48adc4a70511 | 47 | |
wim | 0:48adc4a70511 | 48 | //Register Defines for SAA1064 |
wim | 0:48adc4a70511 | 49 | #define SAA1064_CTRL 0x00 |
wim | 0:48adc4a70511 | 50 | #define SAA1064_DIG1 0x01 |
wim | 0:48adc4a70511 | 51 | #define SAA1064_DIG2 0x02 |
wim | 0:48adc4a70511 | 52 | #define SAA1064_DIG3 0x03 |
wim | 0:48adc4a70511 | 53 | #define SAA1064_DIG4 0x04 |
wim | 0:48adc4a70511 | 54 | |
wim | 0:48adc4a70511 | 55 | //Control Register Defines for SAA1064 |
wim | 0:48adc4a70511 | 56 | //Static display (2 digits) or Multiplexed (4 digits) |
wim | 0:48adc4a70511 | 57 | #define SAA1064_MPX 0x01 |
wim | 0:48adc4a70511 | 58 | //Digits 1 and 2 On |
wim | 0:48adc4a70511 | 59 | #define SAA1064_B0 0x02 |
wim | 0:48adc4a70511 | 60 | //Digits 3 and 4 On |
wim | 0:48adc4a70511 | 61 | #define SAA1064_B1 0x04 |
wim | 0:48adc4a70511 | 62 | //Intensity of display |
wim | 0:48adc4a70511 | 63 | #define SAA1064_INT0 0x00 |
wim | 0:48adc4a70511 | 64 | #define SAA1064_INT1 0x10 |
wim | 0:48adc4a70511 | 65 | #define SAA1064_INT2 0x20 |
wim | 0:48adc4a70511 | 66 | #define SAA1064_INT3 0x30 |
wim | 0:48adc4a70511 | 67 | #define SAA1064_INT4 0x40 |
wim | 0:48adc4a70511 | 68 | #define SAA1064_INT5 0x50 |
wim | 0:48adc4a70511 | 69 | #define SAA1064_INT6 0x60 |
wim | 0:48adc4a70511 | 70 | #define SAA1064_INT7 0x70 |
wim | 0:48adc4a70511 | 71 | |
wim | 0:48adc4a70511 | 72 | //Default Mode: Multiplex On, All Digits On |
wim | 0:48adc4a70511 | 73 | #define SAA1064_CTRL_DEF (SAA1064_MPX | SAA1064_B0 | SAA1064_B1) |
wim | 0:48adc4a70511 | 74 | |
wim | 0:48adc4a70511 | 75 | |
wim | 0:48adc4a70511 | 76 | //Pin Defines for SAA1064 |
wim | 0:48adc4a70511 | 77 | #define D_L0 0x01 |
wim | 0:48adc4a70511 | 78 | #define D_L1 0x02 |
wim | 0:48adc4a70511 | 79 | #define D_L2 0x04 |
wim | 0:48adc4a70511 | 80 | #define D_L3 0x08 |
wim | 0:48adc4a70511 | 81 | #define D_L4 0x10 |
wim | 0:48adc4a70511 | 82 | #define D_L5 0x20 |
wim | 0:48adc4a70511 | 83 | #define D_L6 0x40 |
wim | 0:48adc4a70511 | 84 | #define D_L7 0x80 |
wim | 0:48adc4a70511 | 85 | |
wim | 0:48adc4a70511 | 86 | //Defines for Segments |
wim | 1:79cb73f852da | 87 | const uint8_t SAA1064_SEGM[] = {0x3F, //0 |
wim | 1:79cb73f852da | 88 | 0x06, //1 |
wim | 1:79cb73f852da | 89 | 0x5B, //2 |
wim | 1:79cb73f852da | 90 | 0x4F, //3 |
wim | 1:79cb73f852da | 91 | 0x66, //4 |
wim | 1:79cb73f852da | 92 | 0x6D, //5 |
wim | 1:79cb73f852da | 93 | 0x7D, //6 |
wim | 1:79cb73f852da | 94 | 0x07, //7 |
wim | 1:79cb73f852da | 95 | 0x7F, //8 |
wim | 1:79cb73f852da | 96 | 0x6F, //9 |
wim | 1:79cb73f852da | 97 | 0x77, //A |
wim | 1:79cb73f852da | 98 | 0x7C, //B |
wim | 1:79cb73f852da | 99 | 0x39, //C |
wim | 1:79cb73f852da | 100 | 0x5E, //D |
wim | 1:79cb73f852da | 101 | 0x79, //E |
wim | 1:79cb73f852da | 102 | 0x71}; //F |
wim | 0:48adc4a70511 | 103 | |
wim | 1:79cb73f852da | 104 | #define SAA1064_DP 0x80 //Decimal Point |
wim | 1:79cb73f852da | 105 | #define SAA1064_MINUS 0x40 //Minus Sign |
wim | 1:79cb73f852da | 106 | #define SAA1064_BLNK 0x00 //Blank Digit |
wim | 1:79cb73f852da | 107 | #define SAA1064_ALL 0xFF //All Segments On |
wim | 0:48adc4a70511 | 108 | |
wim | 0:48adc4a70511 | 109 | |
wim | 1:79cb73f852da | 110 | |
wim | 1:79cb73f852da | 111 | |
wim | 1:79cb73f852da | 112 | /** Create an SAA1064 object connected to the specified I2C bus and deviceAddress |
wim | 0:48adc4a70511 | 113 | * |
wim | 0:48adc4a70511 | 114 | */ |
wim | 0:48adc4a70511 | 115 | class SAA1064 { |
wim | 0:48adc4a70511 | 116 | public: |
wim | 1:79cb73f852da | 117 | /** Create a SAA1064 LED displaydriver object using a specified I2C bus and slaveaddress |
wim | 1:79cb73f852da | 118 | * |
wim | 1:79cb73f852da | 119 | * @param I2C &i2c the I2C port to connect to |
wim | 1:79cb73f852da | 120 | * @param char deviceAddress the address of the SAA1064 |
wim | 1:79cb73f852da | 121 | */ |
wim | 1:79cb73f852da | 122 | SAA1064(I2C *i2c, uint8_t deviceAddress = SAA1064_SA0); |
wim | 1:79cb73f852da | 123 | |
wim | 1:79cb73f852da | 124 | /** Set segment brightness |
wim | 1:79cb73f852da | 125 | * |
wim | 1:79cb73f852da | 126 | * @param intensity intensity value, valid Range between 0-7, 0 = 0 mA/segment, 1 = 3 mA/segment etc |
wim | 1:79cb73f852da | 127 | */ |
wim | 1:79cb73f852da | 128 | void setIntensity(uint8_t intensity); |
wim | 1:79cb73f852da | 129 | |
wim | 1:79cb73f852da | 130 | |
wim | 1:79cb73f852da | 131 | /** Write digits |
wim | 1:79cb73f852da | 132 | * |
wim | 1:79cb73f852da | 133 | * @param digit1 LED segment pattern for digit1 (MSB) |
wim | 1:79cb73f852da | 134 | * @param digit2 LED segment pattern for digit2 |
wim | 1:79cb73f852da | 135 | * @param digit3 LED segment pattern for digit3 |
wim | 1:79cb73f852da | 136 | * @param digit4 LED segment pattern for digit4 (LSB) |
wim | 1:79cb73f852da | 137 | */ |
wim | 1:79cb73f852da | 138 | void write(uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4); |
wim | 0:48adc4a70511 | 139 | |
wim | 1:79cb73f852da | 140 | /** Write Integer |
wim | 1:79cb73f852da | 141 | * |
wim | 1:79cb73f852da | 142 | * @param value integer value to display, valid range -999...9999 |
wim | 1:79cb73f852da | 143 | * @param dp_digit digit where decimal point is set, valid range 1..4 (no DP shown for dp_digit = 0) |
wim | 1:79cb73f852da | 144 | * @param leading suppress leading zero (false=show leading zero, true=suppress leading zero) |
wim | 1:79cb73f852da | 145 | */ |
wim | 1:79cb73f852da | 146 | void writeInt(int value, uint8_t dp_digit=0, bool leading=true); |
wim | 0:48adc4a70511 | 147 | |
wim | 0:48adc4a70511 | 148 | |
wim | 1:79cb73f852da | 149 | /** snake: show a short animation |
wim | 1:79cb73f852da | 150 | * |
wim | 1:79cb73f852da | 151 | * @param count number of times animation is repeated, valid range 0..15 |
wim | 1:79cb73f852da | 152 | * |
wim | 1:79cb73f852da | 153 | */ |
wim | 1:79cb73f852da | 154 | void snake(uint8_t count); |
wim | 1:79cb73f852da | 155 | |
wim | 1:79cb73f852da | 156 | /** splash: show a short animation |
wim | 1:79cb73f852da | 157 | * |
wim | 1:79cb73f852da | 158 | * @param count number of times animation is repeated, valid range 0..15 |
wim | 1:79cb73f852da | 159 | * |
wim | 1:79cb73f852da | 160 | */ |
wim | 1:79cb73f852da | 161 | void splash (uint8_t count); |
wim | 1:79cb73f852da | 162 | |
wim | 0:48adc4a70511 | 163 | protected: |
wim | 1:79cb73f852da | 164 | I2C *_i2c; //I2C bus reference |
wim | 1:79cb73f852da | 165 | uint8_t _slaveAddress; //I2C Slave address of device |
wim | 0:48adc4a70511 | 166 | |
wim | 1:79cb73f852da | 167 | /** Initialise LED driver |
wim | 1:79cb73f852da | 168 | * |
wim | 1:79cb73f852da | 169 | */ |
wim | 0:48adc4a70511 | 170 | void _init(); |
wim | 0:48adc4a70511 | 171 | }; |
wim | 0:48adc4a70511 | 172 | |
wim | 0:48adc4a70511 | 173 | #endif |