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

    00001 // ---------------------------------------------------------------------------
    00002 // Created by Francisco Malpartida on 7.3.2012.
    00003 // Copyright 2011 - 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 // Thread Safe: No
    00010 // Extendable: Yes
    00011 //
    00012 // @file LiquidCrystal_SR3W.h
    00013 // This file implements a basic liquid crystal library that comes as standard
    00014 // in the Arduino SDK but using a generic SHIFT REGISTER extension board.
    00015 //
    00016 // @brief
    00017 // This is a basic implementation of the LiquidCrystal library of the
    00018 // Arduino SDK. The original library has been reworked in such a way that
    00019 // this class implements the all methods to command an LCD based
    00020 // on the Hitachi HD44780 and compatible chipsets using a 3 wire latching
    00021 // shift register. While it has been tested with a 74HC595N shift register
    00022 // it should also work with other latching shift registers such as the MC14094
    00023 // and the HEF4094
    00024 //
    00025 // This particular driver has been created as generic as possible to enable
    00026 // users to configure and connect their LCDs using just 3 digital IOs from the
    00027 // AVR or Arduino, and connect the LCD to the outputs of the shiftregister
    00028 // in any configuration. The library is configured by passing the IO pins
    00029 // that control the strobe, data and clock of the shift register and a map
    00030 // of how the shiftregister is connected to the LCD.
    00031 //
    00032 //
    00033 //   +--------------------------------------------+
    00034 //   |                 MCU                        |
    00035 //   |   IO1           IO2           IO3          |
    00036 //   +----+-------------+-------------+-----------+
    00037 //        |             |             |
    00038 //        |             |             |
    00039 //   +----+-------------+-------------+-----------+
    00040 //   |    Strobe        Data          Clock       |
    00041 //   |          8-bit shift/latch register        | 74HC595N
    00042 //   |    Qa0  Qb1  Qc2  Qd3  Qe4  Qf5  Qg6  Qh7  |
    00043 //   +----+----+----+----+----+----+----+----+----+
    00044 //        |    |    |    |    |    |    |
    00045 //        |11  |12  |13  |14  |6   |5   |4   (LCD pins)
    00046 //   +----+----+----+----+----+----+----+----+----+
    00047 //   |    DB4  DB5  DB6  DB7  E    Rw   RS        |
    00048 //   |                 LCD Module                 |
    00049 //
    00050 // NOTE: Rw is not used by the driver so it can be connected to GND.
    00051 //
    00052 // The functionality provided by this class and its base class is identical
    00053 // to the original functionality of the Arduino LiquidCrystal library.
    00054 //
    00055 //
    00056 // @author F. Malpartida - fmalpartida@gmail.com
    00057 // ---------------------------------------------------------------------------
    00058 #ifndef _LIQUIDCRYSTAL_SR3W_H_
    00059 #define _LIQUIDCRYSTAL_SR3W_H_
    00060
    00061 #include <inttypes.h>
    00062 #include "LCD.h"
    00063 #include "FastIO.h"
    00064
    00065
    00066 class LiquidCrystal_SR3W : public LCD
    00067 {
    00068 public:
    00069
    00090    LiquidCrystal_SR3W(uint8_t data, uint8_t clk, uint8_t strobe);
    00091    // Constructor with backlight control
    00092    LiquidCrystal_SR3W(uint8_t data, uint8_t clk, uint8_t strobe,
    00093                       uint8_t backlighPin, t_backlighPol pol);
    00094
    00112    LiquidCrystal_SR3W(uint8_t data, uint8_t clk, uint8_t strobe,
    00113                       uint8_t En, uint8_t Rw, uint8_t Rs,
    00114                       uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7 );
    00115    // Constructor with backlight control
    00116    LiquidCrystal_SR3W( uint8_t data, uint8_t clk, uint8_t strobe,
    00117                       uint8_t En, uint8_t Rw, uint8_t Rs,
    00118                       uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7,
    00119                       uint8_t backlighPin, t_backlighPol pol);
    00120
    00133    virtual void send(uint8_t value, uint8_t mode);
    00134
    00143    void setBacklightPin ( uint8_t value, t_backlighPol pol );
    00144
    00154    void setBacklight ( uint8_t value );
    00155
    00156 private:
    00157
    00163    int  init(uint8_t data, uint8_t clk, uint8_t strobe,
    00164              uint8_t Rs, uint8_t Rw, uint8_t En,
    00165              uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
    00166
    00175    void write4bits(uint8_t value, uint8_t mode);
    00176
    00183    void loadSR(uint8_t value);
    00184
    00185
    00186    fio_bit      _strobe;           // shift register strobe pin
    00187    fio_register _strobe_reg;       // SR strobe pin MCU register
    00188    fio_bit      _data;             // shift register data pin
    00189    fio_register _data_reg;         // SR data pin MCU register
    00190    fio_bit      _clk;              // shift register clock pin
    00191    fio_register _clk_reg;          // SR clock pin MCU register
    00192    uint8_t      _En;               // LCD expander word for enable pin
    00193    uint8_t      _Rw;               // LCD expander word for R/W pin
    00194    uint8_t      _Rs;               // LCD expander word for Register Select pin
    00195    uint8_t      _data_pins[4];     // LCD data lines
    00196    uint8_t      _backlightPinMask; // Backlight IO pin mask
    00197    uint8_t      _backlightStsMask; // Backlight status mask
    00198
    00199 };
    00200
    00201 #endif
    00202

All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines