Romi32U4 library
Romi32U4LCD.h
Go to the documentation of this file.
1 // Copyright Pololu Corporation. For more information, see http://www.pololu.com/
2 
5 #pragma once
6 
7 #include <PololuHD44780.h>
8 #include <FastGPIO.h>
9 #include <USBPause.h>
10 
34 {
35  // Pin assignments
36  static const uint8_t rs = 4, e = 11, db4 = 14, db5 = 17, db6 = 13, db7 = IO_D5;
37 
38 public:
39 
40  virtual void initPins()
41  {
43  }
44 
45  virtual void send(uint8_t data, bool rsValue, bool only4bits)
46  {
47  // Temporarily disable USB interrupts because they write some pins
48  // we are using as LCD pins.
49  USBPause usbPause;
50 
51  // Save the state of the RS and data pins. The state automatically
52  // gets restored before this function returns.
53  FastGPIO::PinLoan<rs> loanRS;
54  FastGPIO::PinLoan<db4> loanDB4;
55  FastGPIO::PinLoan<db5> loanDB5;
56  FastGPIO::PinLoan<db6> loanDB6;
57  FastGPIO::PinLoan<db7> loanDB7;
58 
59  // Drive the RS pin high or low.
61 
62  // Send the data.
63  if (!only4bits) { sendNibble(data >> 4); }
64  sendNibble(data & 0x0F);
65  }
66 
67 private:
68 
69  void sendNibble(uint8_t data)
70  {
71  FastGPIO::Pin<db4>::setOutput(data >> 0 & 1);
72  FastGPIO::Pin<db5>::setOutput(data >> 1 & 1);
73  FastGPIO::Pin<db6>::setOutput(data >> 2 & 1);
74  FastGPIO::Pin<db7>::setOutput(data >> 3 & 1);
75 
77  _delay_us(1); // Must be at least 450 ns.
79  _delay_us(1); // Must be at least 550 ns.
80  }
81 };
82 
Writes data to the LCD on the Romi 32U4.
Definition: Romi32U4LCD.h:33
static void setOutput(bool value) __attribute__((always_inline))
Sets the pin as an output.
Definition: FastGPIO.h:260
virtual void initPins()
Definition: Romi32U4LCD.h:40
General class for handling the HD44780 protocol.
Definition: PololuHD44780.h:56
static void setOutputHigh() __attribute__((always_inline))
Configures the pin to be an output driving high.
Definition: FastGPIO.h:238
virtual void send(uint8_t data, bool rsValue, bool only4bits)
Definition: Romi32U4LCD.h:45
static void setOutputLow() __attribute__((always_inline))
Configures the pin to be an output driving low.
Definition: FastGPIO.h:226