libraries / Visuino_LiquidCrystal / Visuino_LiquidCrystal.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.h
  13// This file implements a basic liquid crystal library that comes as standard
  14// in the Arduino SDK.
  15// 
  16// @brief 
  17// This is a basic implementation of the LiquidCrystal library of the
  18// Arduino SDK. The original library has been reworked in such a way that 
  19// this class implements the all methods to command an LCD based
  20// on the Hitachi HD44780 and compatible chipsets using the parallel port of
  21// the LCD (4 bit and 8 bit).
  22//
  23//
  24//
  25// @author F. Malpartida - fmalpartida@gmail.com
  26// ---------------------------------------------------------------------------
  27#ifndef LiquidCrystal_4bit_h
  28#define LiquidCrystal_4bit_h
  29
  30#include <inttypes.h>
  31
  32#include "Visuino_LCD.h"
  33#include "Visuino_FastIO.h"
  34
  35
  36/*!
  37 @defined 
  38 @abstract   Command execution time on the LCD.
  39 @discussion This defines how long a command takes to execute by the LCD.
  40 The time is expressed in micro-seconds.
  41 */
  42#define EXEC_TIME 37
  43
  44class LiquidCrystal : public LCD
  45{
  46public:
  47   /*!
  48    @method     
  49    @abstract   8 bit LCD constructors.
  50    @discussion Defines the pin assignment that the LCD will have.
  51    The constructor does not initialize the LCD.
  52    */
  53   LiquidCrystal(uint8_t rs, uint8_t enable,
  54                 uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
  55                 uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
  56   LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
  57                 uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
  58                 uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
  59   
  60   // Constructors with backlight control
  61   LiquidCrystal(uint8_t rs, uint8_t enable,
  62                 uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
  63                 uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7,
  64                 uint8_t backlightPin, t_backlighPol pol);
  65   LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
  66                 uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
  67                 uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7,
  68                 uint8_t backlightPin, t_backlighPol pol);   
  69   /*!
  70    @method     
  71    @abstract   4 bit LCD constructors.
  72    @discussion Defines the pin assignment that the LCD will have.
  73    The constructor does not initialize the LCD.
  74    */
  75   LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
  76                 uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
  77   LiquidCrystal(uint8_t rs, uint8_t enable,
  78                 uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
  79   
  80   // Constructors with backlight control
  81   LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
  82                 uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
  83                 uint8_t backlightPin, t_backlighPol pol);
  84   LiquidCrystal(uint8_t rs, uint8_t enable,
  85                 uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
  86                 uint8_t backlightPin, t_backlighPol pol);
  87   /*!
  88    @function
  89    @abstract   Send a particular value to the LCD.
  90    @discussion Sends a particular value to the LCD for writing to the LCD or
  91    as an LCD command.
  92    
  93    Users should never call this method.
  94    
  95    @param      value Value to send to the LCD.
  96    @result     mode LOW - write to the LCD CGRAM, HIGH - write a command to
  97    the LCD.
  98    */
  99   virtual void send(uint8_t value, uint8_t mode);
 100   
 101   /*!
 102    @function
 103    @abstract   Sets the pin to control the backlight.
 104    @discussion Sets the pin in the device to control the backlight.
 105    
 106    @param      pin: pin assigned to the backlight
 107    @param      pol: backlight pin control polarity (POSITIVE, NEGATIVE).
 108    */
 109   void setBacklightPin ( uint8_t pin, t_backlighPol pol );
 110   
 111   /*!
 112    @function
 113    @abstract   Switch-on/off the LCD backlight.
 114    @discussion Switch-on/off the LCD backlight.
 115    The setBacklightPin has to be called before setting the backlight for
 116    this method to work. @see setBacklightPin. For dimming control of the
 117    backlight, the configuration pin must be a PWM output pin. Dim control
 118    is achieved by passing a value from 1 to 255 as a parameter. If the
 119    pin configured when calling the setBacklightPin does not support PWM,
 120    then: (0) backlight off, (1..255) backlight on.
 121    
 122    @param      value: backlight value. 0: off, 1..255: dim control of the 
 123    backlight. For negative logic 255: off, 254..0: dim control.
 124    */
 125   void setBacklight ( uint8_t value );
 126   
 127private:
 128   
 129   /*!
 130    @method     
 131    @abstract   Initializes the LCD pin allocation and associated HW
 132    @discussion Initializes the LCD pin allocation and configuration.
 133    */
 134   void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
 135             uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
 136             uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
 137   
 138   /*!
 139    @method     
 140    @abstract   Writes numBits bits from value value to the LCD.
 141    @discussion Writes numBists bits (the least significant) to the LCD control 
 142    data lines.
 143    */   
 144   void writeNbits(uint8_t value, uint8_t numBits);
 145   
 146   /*!
 147    @method     
 148    @abstract   Pulse the LCD enable line (En).
 149    @discussion Sends a pulse of 1 uS to the Enable pin to execute an command
 150    or write operation.
 151    */ 
 152   void pulseEnable();
 153   
 154   uint8_t _rs_pin;       // LOW: command.  HIGH: character.
 155   uint8_t _rw_pin;       // LOW: write to LCD.  HIGH: read from LCD.
 156   uint8_t _enable_pin;   // activated by a HIGH pulse.
 157   uint8_t _data_pins[8]; // Data pins.
 158   uint8_t _backlightPin; // Pin associated to control the LCD backlight
 159};
 160
 161#endif