7 Segment LED Displaydriver, I2C interface, SAA1064

Dependents:   812_hello

Committer:
wim
Date:
Sun Sep 08 22:23:52 2013 +0000
Revision:
0:48adc4a70511
Child:
1:79cb73f852da
SAA1064 test and LPC812 test

Who changed what in which revision?

UserRevisionLine numberNew 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 0:48adc4a70511 11 //Address Defines for SAA1064
wim 0:48adc4a70511 12 #define SAA1064_SA0 0x70
wim 0:48adc4a70511 13 #define SAA1064_SA1 0x72
wim 0:48adc4a70511 14 #define SAA1064_SA2 0x74
wim 0:48adc4a70511 15 #define SAA1064_SA3 0x76
wim 0:48adc4a70511 16
wim 0:48adc4a70511 17 //Register Defines for SAA1064
wim 0:48adc4a70511 18 #define SAA1064_CTRL 0x00
wim 0:48adc4a70511 19 #define SAA1064_DIG1 0x01
wim 0:48adc4a70511 20 #define SAA1064_DIG2 0x02
wim 0:48adc4a70511 21 #define SAA1064_DIG3 0x03
wim 0:48adc4a70511 22 #define SAA1064_DIG4 0x04
wim 0:48adc4a70511 23
wim 0:48adc4a70511 24 //Control Register Defines for SAA1064
wim 0:48adc4a70511 25 //Static display (2 digits) or Multiplexed (4 digits)
wim 0:48adc4a70511 26 #define SAA1064_MPX 0x01
wim 0:48adc4a70511 27 //Digits 1 and 2 On
wim 0:48adc4a70511 28 #define SAA1064_B0 0x02
wim 0:48adc4a70511 29 //Digits 3 and 4 On
wim 0:48adc4a70511 30 #define SAA1064_B1 0x04
wim 0:48adc4a70511 31 //Intensity of display
wim 0:48adc4a70511 32 #define SAA1064_INT0 0x00
wim 0:48adc4a70511 33 #define SAA1064_INT1 0x10
wim 0:48adc4a70511 34 #define SAA1064_INT2 0x20
wim 0:48adc4a70511 35 #define SAA1064_INT3 0x30
wim 0:48adc4a70511 36 #define SAA1064_INT4 0x40
wim 0:48adc4a70511 37 #define SAA1064_INT5 0x50
wim 0:48adc4a70511 38 #define SAA1064_INT6 0x60
wim 0:48adc4a70511 39 #define SAA1064_INT7 0x70
wim 0:48adc4a70511 40
wim 0:48adc4a70511 41 //Default Mode: Multiplex On, All Digits On
wim 0:48adc4a70511 42 #define SAA1064_CTRL_DEF (SAA1064_MPX | SAA1064_B0 | SAA1064_B1)
wim 0:48adc4a70511 43
wim 0:48adc4a70511 44
wim 0:48adc4a70511 45 //Pin Defines for SAA1064
wim 0:48adc4a70511 46 #define D_L0 0x01
wim 0:48adc4a70511 47 #define D_L1 0x02
wim 0:48adc4a70511 48 #define D_L2 0x04
wim 0:48adc4a70511 49 #define D_L3 0x08
wim 0:48adc4a70511 50 #define D_L4 0x10
wim 0:48adc4a70511 51 #define D_L5 0x20
wim 0:48adc4a70511 52 #define D_L6 0x40
wim 0:48adc4a70511 53 #define D_L7 0x80
wim 0:48adc4a70511 54
wim 0:48adc4a70511 55 //Defines for Segments
wim 0:48adc4a70511 56 const char SAA1064_SEGM[] = {0x3F, //0
wim 0:48adc4a70511 57 0x06, //1
wim 0:48adc4a70511 58 0x5B, //2
wim 0:48adc4a70511 59 0x4F, //3
wim 0:48adc4a70511 60 0x66, //4
wim 0:48adc4a70511 61 0x6D, //5
wim 0:48adc4a70511 62 0x7D, //6
wim 0:48adc4a70511 63 0x07, //7
wim 0:48adc4a70511 64 0x7F, //8
wim 0:48adc4a70511 65 0x6F, //9
wim 0:48adc4a70511 66 0x77, //A
wim 0:48adc4a70511 67 0x7C, //B
wim 0:48adc4a70511 68 0x39, //C
wim 0:48adc4a70511 69 0x5E, //D
wim 0:48adc4a70511 70 0x79, //E
wim 0:48adc4a70511 71 0x71}; //F
wim 0:48adc4a70511 72
wim 0:48adc4a70511 73 #define SAA1064_DP 0x80 //Decimal Point
wim 0:48adc4a70511 74 #define SAA1064_MINUS 0x40 //Minus Sign
wim 0:48adc4a70511 75 #define SAA1064_BLNK 0x00 //Blank Digit
wim 0:48adc4a70511 76 #define SAA1064_ALL 0xFF //All Segments On
wim 0:48adc4a70511 77
wim 0:48adc4a70511 78
wim 0:48adc4a70511 79 /** Create an SAA1064 object connected to the specified I2C object and using the specified deviceAddress
wim 0:48adc4a70511 80 *
wim 0:48adc4a70511 81 * @param I2C &i2c the I2C port to connect to
wim 0:48adc4a70511 82 * @param char deviceAddress the address of the SAA1064
wim 0:48adc4a70511 83 */
wim 0:48adc4a70511 84 class SAA1064 {
wim 0:48adc4a70511 85 public:
wim 0:48adc4a70511 86 SAA1064(I2C *i2c, char deviceAddress = SAA1064_SA0);
wim 0:48adc4a70511 87 char read();
wim 0:48adc4a70511 88 void write(char byte);
wim 0:48adc4a70511 89
wim 0:48adc4a70511 90 void setIntensity(unsigned char intensity);
wim 0:48adc4a70511 91
wim 0:48adc4a70511 92 void write(unsigned char digit1, unsigned char digit2, unsigned char digit3, unsigned char digit4);
wim 0:48adc4a70511 93
wim 0:48adc4a70511 94 void writeInt(int value, unsigned char dp_digit=0, bool leading=true);
wim 0:48adc4a70511 95
wim 0:48adc4a70511 96 protected:
wim 0:48adc4a70511 97 I2C *_i2c;
wim 0:48adc4a70511 98 unsigned char _slaveAddress;
wim 0:48adc4a70511 99
wim 0:48adc4a70511 100 void _init();
wim 0:48adc4a70511 101 };
wim 0:48adc4a70511 102
wim 0:48adc4a70511 103 #endif