Arduino-LCD
LCD library for Arduino
SR4W.h
Go to the documentation of this file.
1 
18 #ifndef LCD_ADAPTER_SR4W_H
19 #define LCD_ADAPTER_SR4W_H
20 
21 #include "LCD.h"
22 #include "Driver/HD44780.h"
23 #include "GPIO.h"
24 
88 namespace LCD {
89 template<BOARD::pin_t SDA_PIN,
90  BOARD::pin_t SCL_PIN,
91  BOARD::pin_t EN_PIN,
92  BOARD::pin_t BT_PIN>
93 class SR4W : public HD44780::Adapter {
94 public:
99  SR4W() :
100  HD44780::Adapter(),
101  m_rs(0)
102  {
103  m_sda.output();
104  m_scl.output();
105  m_en.output();
106  m_bt.output();
107  }
108 
114  virtual bool setup()
115  {
116  return (true);
117  }
118 
124  virtual void write4b(uint8_t data)
125  {
126  write8b(data);
127  }
128 
134  virtual void write8b(uint8_t data)
135  {
136  uint8_t mask = 0x80;
137  do {
138  m_sda = data & mask;
139  m_scl.toggle();
140  mask >>= 1;
141  m_scl.toggle();
142  } while (mask);
143  m_sda = m_rs;
144  m_en.toggle();
145  m_en.toggle();
146  delayMicroseconds(SHORT_EXEC_TIME);
147  }
148 
155  virtual void set_mode(uint8_t flag)
156  {
157  m_rs = flag;
158  }
159 
165  virtual void set_backlight(uint8_t flag)
166  {
167  m_bt.write(flag);
168  }
169 
170 protected:
172  static const uint16_t SHORT_EXEC_TIME = 30;
173 
174  GPIO<SDA_PIN> m_sda;
175  GPIO<SCL_PIN> m_scl;
176  GPIO<EN_PIN> m_en;
177  GPIO<BT_PIN> m_bt;
178  uint8_t m_rs;
179 };
180 
181 };
182 #endif
Definition: SR4W.h:93
GPIO< EN_PIN > m_en
Starts data read/write.
Definition: SR4W.h:176
static const uint16_t SHORT_EXEC_TIME
Definition: SR4W.h:172
uint8_t m_rs
Command/Data select.
Definition: SR4W.h:178
Definition: Debug.h:28
SR4W()
Definition: SR4W.h:99
GPIO< SDA_PIN > m_sda
Serial data output.
Definition: SR4W.h:174
virtual void write8b(uint8_t data)
Definition: SR4W.h:134
virtual void write4b(uint8_t data)
Definition: SR4W.h:124
GPIO< SCL_PIN > m_scl
Serial clock.
Definition: SR4W.h:175
virtual bool setup()
Definition: SR4W.h:114
virtual void set_mode(uint8_t flag)
Definition: SR4W.h:155
virtual void set_backlight(uint8_t flag)
Definition: SR4W.h:165
GPIO< BT_PIN > m_bt
Backlight control.
Definition: SR4W.h:177