1// --------------------------------------------------------------------------- 2// Created by Francisco Malpartida on 7.3.2012. 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_SR3W.h 13// This file implements a basic liquid crystal library that comes as standard 14// in the Arduino SDK but using a generic SHIFT REGISTER extension board. 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 a 3 wire latching 21// shift register. While it has been tested with a 74HC595N shift register 22// it should also work with other latching shift registers such as the MC14094 23// and the HEF4094 24// 25// This particular driver has been created as generic as possible to enable 26// users to configure and connect their LCDs using just 3 digital IOs from the 27// AVR or Arduino, and connect the LCD to the outputs of the shiftregister 28// in any configuration. The library is configured by passing the IO pins 29// that control the strobe, data and clock of the shift register and a map 30// of how the shiftregister is connected to the LCD. 31// 32// 33// +--------------------------------------------+ 34// | MCU | 35// | IO1 IO2 IO3 | 36// +----+-------------+-------------+-----------+ 37// | | | 38// | | | 39// +----+-------------+-------------+-----------+ 40// | Strobe Data Clock | 41// | 8-bit shift/latch register | 74HC595N 42// | Qa0 Qb1 Qc2 Qd3 Qe4 Qf5 Qg6 Qh7 | 43// +----+----+----+----+----+----+----+----+----+ 44// | | | | | | | 45// |11 |12 |13 |14 |6 |5 |4 (LCD pins) 46// +----+----+----+----+----+----+----+----+----+ 47// | DB4 DB5 DB6 DB7 E Rw RS | 48// | LCD Module | 49// 50// NOTE: Rw is not used by the driver so it can be connected to GND. 51// 52// The functionality provided by this class and its base class is identical 53// to the original functionality of the Arduino LiquidCrystal library. 54// 55// 56// @author F. Malpartida - fmalpartida@gmail.com 57// --------------------------------------------------------------------------- 58#ifndef _LIQUIDCRYSTAL_SR3W_H_ 59#define _LIQUIDCRYSTAL_SR3W_H_ 60 61#include <inttypes.h> 62#include"Visuino_LCD.h" 63#include"Visuino_FastIO.h" 64 65 66class LiquidCrystal_SR3W :public LCD 67{ 68public: 69 70/*! 71 @method 72 @abstract Class constructor. 73 @discussion Initializes class variables and defines the IO driving the 74 shift register. The constructor does not initialize the LCD. 75 Default configuration: 76 Shift register LCD 77 QA - 0 DB4 78 QB - 1 DB5 79 QC - 2 DB6 80 QD - 3 DB7 81 QE - 4 E 82 QF - 5 83 QG - 6 Rs 84 GND Rw 85 86 @param strobe[in] digital IO connected to shiftregister strobe pin. 87 @param data[in] digital IO connected to the shiftregister data pin. 88 @param clk[in] digital IO connected to the shiftregister clock pin. 89 */ 90LiquidCrystal_SR3W(uint8_t data,uint8_t clk,uint8_t strobe); 91// Constructor with backlight control 92LiquidCrystal_SR3W(uint8_t data,uint8_t clk,uint8_t strobe, 93uint8_t backlighPin, t_backlighPol pol); 94 95/*! 96 @method 97 @abstract Class constructor. 98 @discussion Initializes class variables and defines the control lines of 99 the LCD and the shiftregister. The constructor does not initialize the LCD. 100 101 @param strobe[in] digital IO connected to shiftregister strobe pin. 102 @param data[in] digital IO connected to shiftregister data pin. 103 @param clk[in] digital IO connected to shiftregister clock pin. 104 @param En[in] LCD En (Enable) pin connected to SR output pin. 105 @param Rw[in] LCD Rw (Read/write) pin connected to SR output pin. 106 @param Rs[in] LCD Rs (Reg Select) pin connected to SR output pin. 107 @param d4[in] LCD data 4 pin map to the SR output pin. 108 @param d5[in] LCD data 5 pin map to the SR output pin. 109 @param d6[in] LCD data 6 pin map to the SR output pin. 110 @param d7[in] LCD data 7 pin map to the SR output pin. 111 */ 112LiquidCrystal_SR3W(uint8_t data,uint8_t clk,uint8_t strobe, 113uint8_t En,uint8_t Rw,uint8_t Rs, 114uint8_t d4,uint8_t d5,uint8_t d6,uint8_t d7 ); 115// Constructor with backlight control 116LiquidCrystal_SR3W(uint8_t data,uint8_t clk,uint8_t strobe, 117uint8_t En,uint8_t Rw,uint8_t Rs, 118uint8_t d4,uint8_t d5,uint8_t d6,uint8_t d7, 119uint8_t backlighPin, t_backlighPol pol); 120 121/*! 122 @function 123 @abstract Send a particular value to the LCD. 124 @discussion Sends a particular value to the LCD for writing to the LCD or 125 as an LCD command. 126 127 Users should never call this method. 128 129 @param value[in] Value to send to the LCD. 130 @param mode[in] DATA - write to the LCD CGRAM, COMMAND - write a 131 command to the LCD. 132 */ 133virtualvoidsend(uint8_t value,uint8_t mode); 134 135/*! 136 @function 137 @abstract Sets the pin to control the backlight. 138 @discussion Sets the pin in the device to control the backlight. This device 139 doesn't support dimming backlight capability. 140 141 @param 0: backlight off, 1..255: backlight on. 142 */ 143voidsetBacklightPin(uint8_t value, t_backlighPol pol ); 144 145/*! 146 @function 147 @abstract Switch-on/off the LCD backlight. 148 @discussion Switch-on/off the LCD backlight. 149 The setBacklightPin has to be called before setting the backlight for 150 this method to work. @see setBacklightPin. 151 152 @param value: backlight mode (HIGH|LOW) 153 */ 154voidsetBacklight(uint8_t value ); 155 156private: 157 158/*! 159 @method 160 @abstract Initializes the LCD class 161 @discussion Initializes the LCD class and IO expansion module. 162 */ 163intinit(uint8_t data,uint8_t clk,uint8_t strobe, 164uint8_t Rs,uint8_t Rw,uint8_t En, 165uint8_t d4,uint8_t d5,uint8_t d6,uint8_t d7); 166 167/*! 168 @method 169 @abstract Writes an 4 bit value to the LCD. 170 @discussion Writes 4 bits (the least significant) to the LCD control data lines. 171 @param value[in] Value to write to the LCD 172 @param more[in] Value to distinguish between command and data. 173 COMMAND == command, DATA == data. 174 */ 175voidwrite4bits(uint8_t value,uint8_t mode); 176 177/*! 178 @function 179 @abstract load into the shift register a byte 180 @discussion loads into the shift register a byte 181 @param value[in]: value to be loaded into the shiftregister. 182 */ 183voidloadSR(uint8_t value); 184 185 186 fio_bit _strobe;// shift register strobe pin 187 fio_register _strobe_reg;// SR strobe pin MCU register 188 fio_bit _data;// shift register data pin 189 fio_register _data_reg;// SR data pin MCU register 190 fio_bit _clk;// shift register clock pin 191 fio_register _clk_reg;// SR clock pin MCU register 192uint8_t _En;// LCD expander word for enable pin 193uint8_t _Rw;// LCD expander word for R/W pin 194uint8_t _Rs;// LCD expander word for Register Select pin 195uint8_t _data_pins[4];// LCD data lines 196uint8_t _backlightPinMask;// Backlight IO pin mask 197uint8_t _backlightStsMask;// Backlight status mask 198 199}; 200 201#endif 202