/Users/fmalpartida/development/ardWorkspace/LiquidCrystal_I2C/LiquiCrystal_I2C/LiquidCrystal_SR2W.h
Go to the documentation of this file.

    00001 // ---------------------------------------------------------------------------
    00002 // Created/Adapted by Bill Perry 2012-03-16
    00003 // Copyright 2012 - Under creative commons license 3.0:
    00004 //        Attribution-ShareAlike CC BY-SA
    00005 //
    00006 // This software is furnished "as is", without technical support, and with no
    00007 // warranty, express or implied, as to its usefulness for any purpose.
    00008 //
    00009 // @file LiquidCrystal_SR2W.h
    00010 // Connects a hd44780 LCD using 2 pins from the Arduino, via an 8-bit
    00011 // ShiftRegister (SR2W from now on).
    00012 //
    00013 // @brief
    00014 // This is the 2 wire shift register interface class for the LCD library
    00015 //
    00016 // The functionality provided by this class and its base class is a superset of
    00017 // the original functionality of the Arduino LiquidCrystal library and can
    00018 // be used as such.
    00019 // See the LCD class for a full description of the API functions available.
    00020 //
    00021 // It works with a 8-bit unlatched, no-tristate, unidirectional SIPO (Serial-In-Parallel-Out)
    00022 // shift register (IE a very simple SR), and an hd44780 LCD in 4-bit mode.
    00023 // Any such shift register should do (pref. 74LS family IC's for 2-wire).
    00024 // 74LS164 and 74HC595 have been exstensively tested.
    00025 //
    00026 //
    00027 // 2 Pins required from the Arduino:
    00028 // - Data/Enable
    00029 // - Clock
    00030 // The Data pin is also used to control the enable signal
    00031 // LCD RW-pin hardwired to LOW (only writing to LCD).
    00032 // Busy Flag (BF, data bit D7) is not read.
    00033 //
    00034 //  Original project homepage: http://code.google.com/p/arduinoshiftreglcd/
    00035 //
    00036 // Shift register bits
    00037 // Bit  #0   - (cannot be used on 74HC595)
    00038 // Bit  #1   - optional backlight control
    00039 // Bit  #2   - connects to RS (Register Select) on the LCD
    00040 // Bit  #3   - connects to LCD data inputs D4
    00041 // Bit  #4   - connects to LCD data inputs D5
    00042 // Bit  #5   - connects to LCD data inputs D6
    00043 // Bit  #6   - connects to LCD data inputs D7
    00044 // Bit  #7   - enables the LCD enable-puls (via the diode-resistor AND "gate")
    00045 //
    00046 // Wiring for a 74LS164
    00047 // ---------------------
    00048 //                          1k/4.7k
    00049 //              +--------[ Resistor ]--------+---(LCD Enable)
    00050 //              |                            |
    00051 //              |          74LS164    (VCC)  |
    00052 //              |        +----u----+    |   _V_ diode
    00053 // (data pin)---+---+--1-|A     VCC|-14-+    |
    00054 //                  |    |         |         |
    00055 //                  +--2-|B      Q7|-13------+
    00056 //                     3-|Q0     Q6|-12--(LCD D7)
    00057 // (BL Circuit)--------4-|Q1     Q5|-11--(LCD D6)
    00058 // (LCD RS)------------5-|Q2     Q4|-10--(LCD D5)
    00059 // (LCD D4)------------6-|Q3    /MR|--9--(VCC)
    00060 //                   +-7-|GND    CP|--8--(clock pin)
    00061 //                   |   +---------+
    00062 //                   |      0.1uf
    00063 //                 (gnd)-----||----(vcc)
    00064 //
    00065 // Wiring for a 74HC595
    00066 // --------------------
    00067 // NOTE: the 74HC595 is a latching shift register. In order to get it to operate
    00068 // in a "non latching" mode, RCLK and SCLK are tied together. The side effect of this
    00069 // is that the latched output is one clock behind behind the internal shift register bits.
    00070 // To compensate for this the wiring is offset by one bit position lower.
    00071 // For example, while the backlight is hooked to Q0 it is still using bit 1 of
    00072 // of the shift register because the outputs are 1 clock behind the real internal shift
    00073 // register.
    00074 //
    00075 //                         74HC595    (VCC)
    00076 //                       +----u----+    |  +-----------------------(BL circuit)
    00077 // (LCD RS)------------1-|Q1    VCC|-16-+  |  +--------------------(data pin)
    00078 // (LCD D4)------------2-|Q2     Q0|-15----+  |      1k/4.7k
    00079 // (LCD D5)------------3-|Q3    SER|-14-------+---[ Resistor ]--+--(LCD Enable)
    00080 // (LCD D6)------------4-|Q4    /OE|-13--(gnd)                  |
    00081 // (LCD D7)------------5-|Q5   RCLK|-12-------+                 |
    00082 //                       |         |          |                 |
    00083 //              +------6-|Q6   SCLK|-11-------+--(clock pin)    |
    00084 //              |      7-|Q7    /MR|-10--(VCC)                  |
    00085 //              |    +-8-|GND   Q6'|--9                         |
    00086 //              |    |   +---------+                    diode  _V_
    00087 //              |    |      0.1uf                               |
    00088 //              |  (gnd)-----||----(vcc)                        |
    00089 //              +-----------------------------------------------+
    00090 //
    00091 //
    00092 // Backlight Control circuit
    00093 // -------------------------
    00094 // Because the shift resiter is not latching the outputs, the backlight circuitry
    00095 // will "see" the output bits as they are shifted into the shift register which
    00096 // can cause the backlight to flicker rather than remain constantly on/off.
    00097 // The circuit below slows down the transitions to the transistor to remove
    00098 // the visible flicker. When the BL input is HIGH the LCD backlight will turn on.
    00099 //
    00100 //                (value depends on LCD, 100ohm is usually safe)
    00101 // (LCD BL anode)---[ resistor ]---(vcc)
    00102 //
    00103 // (LCD BL cathode)-------------------------------+
    00104 //                                                |
    00105 //                                                D
    00106 //                                                |
    00107 // (BL input)----[ 4.7k Resistor ]----+-------G-|-<  (2N7000 FET)
    00108 //                                    |           |
    00109 //                          (0.1uf)   =           S
    00110 //                                    |           |
    00111 //                                  (gnd)        (gnd)
    00112 //
    00113 //
    00114 //
    00115 //
    00116 // History
    00117 // 2012.03.16  bperrybap - creation/adaption from SR header to create SR2W header.
    00118 //                         Fixed typo in SR2W mask define names
    00119 // @author B. Perry - bperrybap@opensource.billsworld.billandterrie.com
    00120 // --------------------------------------------------------------------------------
    00121 #ifndef _LIQUIDCRYSTAL_SR2W_
    00122 #define _LIQUIDCRYSTAL_SR2W_
    00123
    00124 #include <inttypes.h>
    00125 #include "LCD.h"
    00126 #include "FastIO.h"
    00127
    00128
    00129 // two-wire SR output bit constants
    00130 // ---------------------------------------------------------------------------
    00131
    00132 #define SR2W_BL_MASK 0x02
    00133 #define SR2W_RS_MASK 0x04
    00134 #define SR2W_DATA_MASK 0x78     // data bits are hard coded to be SR bits 6,5,4,3
    00135 #define SR2W_EN_MASK 0x80       // cannot ever be changed
    00136
    00137 class LiquidCrystal_SR2W : public LCD
    00138 {
    00139 public:
    00151    LiquidCrystal_SR2W (uint8_t srdata, uint8_t srclock, t_backlighPol blpol = POSITIVE);
    00152
    00165    virtual void send(uint8_t value, uint8_t mode);
    00166
    00167
    00177    void setBacklight ( uint8_t mode );
    00178
    00179 private:
    00180
    00186    void init ( uint8_t srdata, uint8_t srclock, t_backlighPol blpol, uint8_t lines, uint8_t font );
    00187
    00192    void loadSR (uint8_t val);
    00193
    00194    fio_register _srDataRegister; // Serial Data pin
    00195    fio_bit _srDataMask;
    00196    fio_register _srClockRegister; // Clock Pin
    00197    fio_bit _srClockMask;
    00198
    00199    uint8_t _blPolarity;
    00200    uint8_t _blMask;
    00201 };
    00202 #endif

All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines