New LiquidCrystal library: /Users/fmalpartida/Documents/development/mercurial repos/SW/NewliquidCrystal/LiquidCrystal_SR2W.h Source File

New LiquidCrystal library 1.3.2 Generic LCD control library

- Main Page
- Related Pages
- Classes
- Files

- File List

/Users/fmalpartida/Documents/development/mercurial repos/SW/NewliquidCrystal/LiquidCrystal_SR2W.h
1 // ---------------------------------------------------------------------------
2 // Created/Adapted by Bill Perry 2012-03-16
3 // Copyright 2012 - 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 // @file LiquidCrystal_SR2W.h
10 // Connects a hd44780 LCD using 2 pins from the Arduino, via an 8-bit
11 // ShiftRegister (SR2W from now on).
12 //
13 // @brief
14 // This is the 2 wire shift register interface class for the LCD library
15 //
16 // The functionality provided by this class and its base class is a superset of
17 // the original functionality of the Arduino LiquidCrystal library and can
18 // be used as such.
19 // See the LCD class for a full description of the API functions available.
20 //
21 // It works with a 8-bit unlatched, no-tristate, unidirectional SIPO (Serial-In-Parallel-Out)
22 // shift register (IE a very simple SR), and an hd44780 LCD in 4-bit mode.
23 // Any such shift register should do (pref. 74LS family IC's for 2-wire).
24 // 74LS164 and 74HC595 have been exstensively tested.
25 //
26 //
27 // 2 Pins required from the Arduino:
28 // - Data/Enable
29 // - Clock
30 // The Data pin is also used to control the enable signal
31 // LCD RW-pin hardwired to LOW (only writing to LCD).
32 // Busy Flag (BF, data bit D7) is not read.
33 //
34 // Original project homepage: http://code.google.com/p/arduinoshiftreglcd/
35 //
36 // Shift register bits
37 // Bit #0 - (cannot be used on 74HC595)
38 // Bit #1 - optional backlight control
39 // Bit #2 - connects to RS (Register Select) on the LCD
40 // Bit #3 - connects to LCD data inputs D4
41 // Bit #4 - connects to LCD data inputs D5
42 // Bit #5 - connects to LCD data inputs D6
43 // Bit #6 - connects to LCD data inputs D7
44 // Bit #7 - enables the LCD enable-puls (via the diode-resistor AND "gate")
45 //
46 // Wiring for a 74LS164
47 // ---------------------
48 // 1k/4.7k
49 // +--------[ Resistor ]--------+---(LCD Enable)
50 // | |
51 // | 74LS164 (VCC) |
52 // | +----u----+ | _V_ diode
53 // (data pin)---+---+--1-|A VCC|-14-+ |
54 // | | | |
55 // +--2-|B Q7|-13------+
56 // 3-|Q0 Q6|-12--(LCD D7)
57 // (BL Circuit)--------4-|Q1 Q5|-11--(LCD D6)
58 // (LCD RS)------------5-|Q2 Q4|-10--(LCD D5)
59 // (LCD D4)------------6-|Q3 /MR|--9--(VCC)
60 // +-7-|GND CP|--8--(clock pin)
61 // | +---------+
62 // | 0.1uf
63 // (gnd)-----||----(vcc)
64 //
65 // Wiring for a 74HC595
66 // --------------------
67 // NOTE: the 74HC595 is a latching shift register. In order to get it to operate
68 // in a "non latching" mode, RCLK and SCLK are tied together. The side effect of this
69 // is that the latched output is one clock behind behind the internal shift register bits.
70 // To compensate for this the wiring is offset by one bit position lower.
71 // For example, while the backlight is hooked to Q0 it is still using bit 1 of
72 // of the shift register because the outputs are 1 clock behind the real internal shift
73 // register.
74 //
75 // 74HC595 (VCC)
76 // +----u----+ | +-----------------------(BL circuit)
77 // (LCD RS)------------1-|Q1 VCC|-16-+ | +--------------------(data pin)
78 // (LCD D4)------------2-|Q2 Q0|-15----+ | 1k/4.7k
79 // (LCD D5)------------3-|Q3 SER|-14-------+---[ Resistor ]--+--(LCD Enable)
80 // (LCD D6)------------4-|Q4 /OE|-13--(gnd) |
81 // (LCD D7)------------5-|Q5 RCLK|-12-------+ |
82 // | | | |
83 // +------6-|Q6 SCLK|-11-------+--(clock pin) |
84 // | 7-|Q7 /MR|-10--(VCC) |
85 // | +-8-|GND Q6'|--9 |
86 // | | +---------+ diode _V_
87 // | | 0.1uf |
88 // | (gnd)-----||----(vcc) |
89 // +-----------------------------------------------+
90 //
91 //
92 // Backlight Control circuit
93 // -------------------------
94 // Because the shift resiter is not latching the outputs, the backlight circuitry
95 // will "see" the output bits as they are shifted into the shift register which
96 // can cause the backlight to flicker rather than remain constantly on/off.
97 // The circuit below slows down the transitions to the transistor to remove
98 // the visible flicker. When the BL input is HIGH the LCD backlight will turn on.
99 //
100 // (value depends on LCD, 100ohm is usually safe)
101 // (LCD BL anode)---[ resistor ]---(vcc)
102 //
103 // (LCD BL cathode)-------------------------------+
104 // |
105 // D
106 // |
107 // (BL input)----[ 4.7k Resistor ]----+-------G-|-< (2N7000 FET)
108 // | |
109 // (0.1uf) = S
110 // | |
111 // (gnd) (gnd)
112 //
113 //
114 //
115 //
116 // History
117 // 2012.03.16 bperrybap - creation/adaption from SR header to create SR2W header.
118 // Fixed typo in SR2W mask define names
119 // @author B. Perry - bperrybap@opensource.billsworld.billandterrie.com
120 // --------------------------------------------------------------------------------
121 #ifndef _LIQUIDCRYSTAL_SR2W_
122 #define _LIQUIDCRYSTAL_SR2W_
123
124 #include <inttypes.h>
125 #include "LCD.h"
126 #include "FastIO.h"
127
128
129 // two-wire SR output bit constants
130 // ---------------------------------------------------------------------------
131
132 #define SR2W_BL_MASK 0x02
133 #define SR2W_RS_MASK 0x04
134 #define SR2W_DATA_MASK 0x78 // data bits are hard coded to be SR bits 6,5,4,3
135 #define SR2W_EN_MASK 0x80 // cannot ever be changed
136
137 class LiquidCrystal_SR2W : public LCD
138 {
139 public:
151 LiquidCrystal_SR2W (uint8_t srdata, uint8_t srclock, t_backlighPol blpol = POSITIVE);
152
165 virtual void send(uint8_t value, uint8_t mode);
166
167
177 void setBacklight ( uint8_t mode );
178
179 private:
180
186 void init ( uint8_t srdata, uint8_t srclock, t_backlighPol blpol, uint8_t lines, uint8_t font );
187
192 void loadSR (uint8_t val);
193
194 fio_register _srDataRegister; // Serial Data pin
195 fio_bit _srDataMask;
196 fio_register _srClockRegister; // Clock Pin
197 fio_bit _srClockMask;
198
199 uint8_t _blPolarity;
200 uint8_t _blMask;
201 };
202 #endif
LiquidCrystal_SR2W::setBacklight
void setBacklight(uint8_t mode)
Definition: LiquidCrystal_SR2W.cpp:117
LiquidCrystal_SR2W
Definition: LiquidCrystal_SR2W.h:137
LCD
Definition: LCD.h:187
LiquidCrystal_SR2W::LiquidCrystal_SR2W
LiquidCrystal_SR2W(uint8_t srdata, uint8_t srclock, t_backlighPol blpol=POSITIVE)
Definition: LiquidCrystal_SR2W.cpp:37
LiquidCrystal_SR2W::send
virtual void send(uint8_t value, uint8_t mode)
Definition: LiquidCrystal_SR2W.cpp:90