-
Notifications
You must be signed in to change notification settings - Fork 0
/
HD44780F.h
149 lines (111 loc) · 4.41 KB
/
HD44780F.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef HD44780F_H
#define HD44780F_H
#include "Arduino.h"
#include "avr/pgmspace.h"
//#include <inttypes.h>
// LCD Commands
// ---------------------------------------------------------------------------
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x20
#define LCD_SETCGRAMADDR 0x40
#define LCD_SETDDRAMADDR 0x80
// flags for display entry mode
// ---------------------------------------------------------------------------
#define LCD_ENTRYRIGHT 0x00 // I/D
#define LCD_ENTRYLEFT 0x02 // I/D
#define LCD_ENTRYSHIFTINCREMENT 0x01 // S
#define LCD_ENTRYSHIFTDECREMENT 0x00 // S
// flags for display on/off and cursor control
// ---------------------------------------------------------------------------
#define LCD_DISPLAYON 0x04 // D
#define LCD_DISPLAYOFF 0x00 // D
#define LCD_CURSORON 0x02 // C
#define LCD_CURSOROFF 0x00 // C
#define LCD_BLINKON 0x01 // B
#define LCD_BLINKOFF 0x00 // B
// flags for display/cursor shift
// ---------------------------------------------------------------------------
#define LCD_DISPLAYMOVE 0x08 // S/C
#define LCD_CURSORMOVE 0x00 // S/C
#define LCD_MOVERIGHT 0x04 // R/L
#define LCD_MOVELEFT 0x00 // R/L
// flags for function set
// ---------------------------------------------------------------------------
#define LCD_8BITMODE 0x10 //DL == 1: 8 bits
#define LCD_4BITMODE 0x00 //DL == 0: 4 bits
#define LCD_2LINE 0x08 //N == 1: 2 line
#define LCD_1LINE 0x00 //N == 0: 1 line
#define LCD_5x10DOTS 0x04 //F
#define LCD_5x8DOTS 0x00 //F
// Define COMMAND and DATA LCD Rs (used by send method).
// ---------------------------------------------------------------------------
#define COMMAND 0
#define LCD_DATA 1
#define FOUR_BITS 2
#define WAIT_HOME_CLEAR 2000 // home clear delay
#define WAIT_BUSY 37 // write operation delay
class HD44780F : public Print
{
public:
HD44780F();
//** LCD initialization
void begin(uint8_t cols, uint8_t lines);
//** clears the LCD screen and positions the cursor in the upper-left corner (time consuming).
void clear();
//** turns off the display
void noDisplay();
//** turns on the display
void display();
/*
//** display the blinking LCD cursor
void blink();
//** hides the LCD cursor
void noBlink();
//** Scrolls the contents of the display (text and cursor) one space to the left
void scrollDisplayLeft();
//** Scrolls the contents of the display (text and cursor) one space to the right
void scrollDisplayRight();
//** set the direction for text written to the LCD to left-to-right
void leftToRight();
//** set the direction for text written to the LCD to right-to-left
void rightToLeft();
//** moves the cursor one space to the left
void moveCursorLeft();
//** moves the cursor one space to the right
void moveCursorRight();
//** enable autoscroll will outputting each new character to the same location on the LCD.
void autoscroll();
//** disable autoscroll
void noAutoscroll();
*/
//** create special character
void createChar(uint8_t location, uint8_t charmap[]);
//** create special character, for AVR, progmem
#ifdef __AVR__
void createChar(uint8_t location, const char* charmap);
#endif // __AVR__
//** position the cursor
void setCursor(uint8_t col, uint8_t row);
//** virtual write method, implemented in the Print class
virtual size_t write(uint8_t value);
using Print::write;
private:
uint8_t displaycontrol = 0; // LCD base control command LCD on/off, blink, cursor
uint8_t displaymode = 0; // Text entry mode to the LCD
uint8_t _numlines = 0; // Number of lines of the LCD, initialized with begin()
uint8_t _cols = 0; // Number of columns in the LCD
uint32_t waitStart = 0; // start of busy period
void sendCommand(uint8_t value);
void sendData(uint8_t value);
void busyStart();
void busy();
void pulse_EN();
void write4bits_4bitMode(uint8_t value);
void write8bits_4bitMode(uint8_t val);
uint8_t read8bits_4bitMode();
};
#endif