Zumo32U4 library
Zumo32U4LCD.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 = 0, e = 1, db4 = 14, db5 = 17, db6 = 13, db7 = IO_D5;
37 
38 public:
39 
40  virtual void initPins()
41  {
42  FastGPIO::Pin<e>::setOutputLow();
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.
60  FastGPIO::Pin<rs>::setOutput(rsValue);
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 
76  FastGPIO::Pin<e>::setOutputHigh();
77  _delay_us(1); // Must be at least 450 ns.
78  FastGPIO::Pin<e>::setOutputLow();
79  _delay_us(1); // Must be at least 550 ns.
80  }
81 };
82 
Writes data to the LCD on the Zumo 32U4.
Definition: Zumo32U4LCD.h:34