libraries / Visuino_LiquidCrystal / Visuino_LiquidCrystal_SR.hon commit Added link to project report (97a3ba0)
   1// ---------------------------------------------------------------------------
   2// Created by Francisco Malpartida on 20/08/11.
   3// Copyright 2011 - Under creative commons license 3.0:
   4//        Attribution-ShareAlike CC BY-SA
   5//
   6// This software is furnished "as is", without technical support, and with no 
   7// warranty, express or implied, as to its usefulness for any purpose.
   8//
   9// Thread Safe: No
  10// Extendable: Yes
  11//
  12// @file LiquidCrystal_SR.h
  13//  Connects an LCD using 2 or 3 pins from the Arduino, via an 8-bit 
  14// ShiftRegister (SR from now on).
  15// 
  16// @brief 
  17// This is a port of the ShiftRegLCD library from raron and ported to the
  18// LCD library.
  19//
  20// The functionality provided by this class and its base class is identical
  21// to the original functionality of the Arduino LiquidCrystal library and can
  22// be used as such.
  23//
  24// Modified to work serially with the shiftOut() function, an 8-bit
  25// unlatched, no-tristate, unidirectional SIPO (Serial-In-Parallel-Out)
  26// shift register (IE a very simple SR), and an LCD in 4-bit mode.
  27// Any such shift register should do (pref. 74LS family IC's for 2-wire).
  28// I used 74LS164, for the reason that's what I had at hand.
  29//
  30// Connection description:
  31//
  32// SR output:
  33// Bit  #0   - N/C - not connected, used to hold a zero
  34// Bit  #1   - N/C
  35// Bit  #2   - connects to RS (Register Select) on the LCD
  36// Bits #3-6 - connects to LCD data inputs D4 - D7.
  37// Bit  #7   - enables the LCD enable-puls (via the diode-resistor AND "gate")
  38//
  39// 2 or 3 Pins required from the Arduino for Data, Clock and (optional) Enable
  40// If not using Enable, the Data pin will be used for the enable signal.
  41// 2 wire mode can be indicated by:
  42// - ommitting the enable pin in constructor
  43// - defining the same pin for Enable as for Data in constructor
  44// - by using the token TWO_WIRE for the enable pin.
  45//
  46// Data and Clock outputs/pins goes to the shiftregister.
  47// LCD RW-pin hardwired to LOW (only writing to LCD).
  48// Busy Flag (BF, data bit D7) is not read.
  49//
  50//  Original project homepage: http://code.google.com/p/arduinoshiftreglcd/
  51//
  52//
  53// History
  54// 2012.03.29  bperrybap - can now eliminate enable pin in constructor for two wire mode.
  55// 2011.10.29  fmalpartida - adaption of the library to the LCD class hierarchy.
  56// 2011.07.02  Fixed a minor flaw in setCursor function. No functional change, 
  57//             just a bit more memory efficient.
  58//             Thanks to CapnBry (from google code and github) who noticed it.
  59//             URL to his version of shiftregLCD:
  60//             https://github.com/CapnBry/HeaterMeter/commit/c6beba1b46b092ab0b33bcbd0a30a201fd1f28c1
  61// 2009.07.30  raron - minor corrections to the comments.
  62//             Fixed timing to datasheet safe. Fixed keyword highlights.
  63// 2009.07.28  Mircho / raron - a new modification to the schematics, and a
  64//             more streamlined interface
  65// 2009.07.27  Thanks to an excellent suggestion from mircho at the Arduiono 
  66//             playgrond forum, the number of wires now required is only two!
  67// 2009.07.25  raron - Fixed comments. I really messed up the comments before 
  68//             posting this, so I had to fix it.
  69//             Renamed a function, but no improvements or functional changes.
  70// 2009.07.23  Incorporated some proper initialization routines
  71//             inspired (lets say copy-paste-tweaked) from LiquidCrystal
  72//             library improvements from LadyAda.
  73// 2009.05.23  raron - first version, but based mostly (as in almost verbatim)
  74//             on the "official" LiquidCrystal library.
  75//
  76//
  77//
  78// @author F. Malpartida - fmalpartida@gmail.com
  79// ---------------------------------------------------------------------------
  80#ifndef _LIQUIDCRYSTAL_SR_
  81#define _LIQUIDCRYSTAL_SR_
  82
  83#include <inttypes.h>
  84#include "Visuino_LCD.h"
  85#include "Visuino_FastIO.h"
  86
  87
  88// two-wire indicator constant
  89// ---------------------------------------------------------------------------
  90#define TWO_WIRE  204
  91#define SR_RS_BIT 0x04
  92#define SR_EN_BIT 0x80
  93
  94class LiquidCrystal_SR : public LCD
  95{
  96public:
  97   /*!
  98    @method     
  99    @abstract   LCD SHIFT REGISTER constructors.
 100    @discussion Defines the pin assignment that the LCD will have.
 101    The constructor does not initialize the LCD. Assuming 1 line 8 pixel high 
 102    font.
 103    
 104    @param srdata[in]   pin for shiftregister data line.
 105    @param srclock[in]  pin for shiftregister clock line.
 106    @param enable[in]   optional direct enable pin for the LCD
 107    */
 108   LiquidCrystal_SR ( uint8_t srdata, uint8_t srclock, uint8_t enable=TWO_WIRE );
 109   
 110   /*!
 111    @function
 112    @abstract   Send a particular value to the LCD.
 113    @discussion Sends a particular value to the LCD for writing to the LCD or
 114    as an LCD command using the shift register.
 115    
 116    Users should never call this method.
 117    
 118    @param      value[in] Value to send to the LCD.
 119    @result     mode LOW - write to the LCD CGRAM, HIGH - write a command to
 120    the LCD.
 121    */
 122   virtual void send(uint8_t value, uint8_t mode);
 123   
 124   
 125   /*!
 126    @function
 127    @abstract   Sets the pin to control the backlight.
 128    @discussion Sets the pin in the device to control the backlight.
 129    @warning    Currently not supported
 130    
 131    @param      mode: backlight mode (HIGH|LOW)
 132    @param      pol: backlight polarity
 133    */
 134   void setBacklightPin ( uint8_t pin, t_backlighPol pol );
 135   
 136   /*!
 137    @function
 138    @abstract   Switch-on/off the LCD backlight.
 139    @discussion Switch-on/off the LCD backlight.
 140    The setBacklightPin has to be called before setting the backlight for
 141    this method to work. @see setBacklightPin.
 142    
 143    @param      mode: backlight mode (HIGH|LOW)
 144    */
 145   void setBacklight ( uint8_t mode );
 146   
 147private:
 148   
 149   /*!
 150    @method     
 151    @abstract   Initializes the LCD pin allocation
 152    @discussion Initializes the LCD pin allocation and configuration.
 153    */
 154   void init ( uint8_t srdata, uint8_t srclock, uint8_t enable, uint8_t lines, 
 155              uint8_t font );
 156   
 157   /*!
 158    * @method
 159    * @abstract takes care of shifting and the enable pulse
 160    */
 161   void shiftIt (uint8_t val);
 162   
 163   uint8_t _enable_pin;  // Enable Pin
 164   uint8_t _two_wire;    // two wire mode
 165   
 166   fio_register _srDataRegister; // Serial Data pin
 167   fio_bit _srDataBit;
 168   fio_register _srClockRegister; // Clock Pin
 169   fio_bit _srClockBit;
 170   fio_register _srEnableRegister; // Enable Pin
 171   fio_bit _srEnableBit;
 172   
 173};
 174
 175#endif
 176