-
Notifications
You must be signed in to change notification settings - Fork 0
/
libhd44780.h
128 lines (125 loc) · 3.98 KB
/
libhd44780.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
//=================================================================
// AVR library for hd44780 compatible LCD display
// ryba.lodz@gmail.com
// works in 4-bit or 8-bit mode with busy flag read
//=================================================================
#ifndef HD44780_H
#define HD44780_H
#include <avr/io.h>
#include <util/delay.h>
//=================================================================
// Uncomment below needed lines for Your display
//=================================================================
//#define CHARS_PER_LINE_8
#define CHARS_PER_LINE_16
//#define CHARS_PER_LINE_20
//#define ONE_LINE
#define TWO_LINES
//#define FOUR_LINES
#define CURSOR_DECREMENT
//#define CURSOR_INCREMENT
#define MODE_4_BIT
//#define MODE_8_BIT
//==================================================================
// In this part You can configure Your pins and ports used with LCD.
// Data port in 4-bit mode must be lower or higher nibble of used
// port. LCD_DATA_MASK must be set as the used nibble for data port
// (for 8 bit mode it doesn't matter).
// Pins for LCD control lines must be on one port and You must
// define this lines.
//==================================================================
#define LCD_CONTROL_PORT D
#define LCD_RS (1<<PD5)
#define LCD_RW (1<<PD6)
#define LCD_E (1<<PD7)
#define LCD_DATA_PORT B
#define LCD_DATA_MASK 0xf0
//=================================================================
// other needed definitions for working defined macros
//=================================================================
#define PORT_(port) PORT ## port
#define DDR_(port) DDR ## port
#define PIN_(port) PIN ## port
#define PORT(port) PORT_(port)
#define DDR(port) DDR_(port)
#define PIN(port) PIN_(port)
//=================================================================
// LCD commands
//=================================================================
#define clearDisplay 0x01
#define returnHome 0x02
#define entryModeSet 0x04
#define cursorIncrement 0x02
#define cursorDecrement 0x00
#define shiftDisplay 0x01
#define displayOnOff 0x08
#define displayOn 0x04
#define cursorOn 0x02
#define cursorBlink 0x01
#define displayShift 0x10
#define shiftCursorRight 0x04
#define shiftDisplayLeft 0x08
#define shiftDisplayRight 0x0c
#define functionSet 0x20
#define interface8bit 0x10
#define display1line 0x00
#define display2lines 0x08
#define font5x11 0x04
#define setDdramAddress 0x80
#define firstLine 0x00
#ifdef CHARS_PER_LINE_8
#define endFirstLine 0x07
#endif
#ifdef CHARS_PER_LINE_16
#define endFirstLine 0x0f
#endif
#ifdef CHARS_PER_LINE_20
#define endFirstLine 0x13
#endif
#define secondLine 0x40
#ifdef CHARS_PER_LINE_8
#define endSecondLine 0x47
#endif
#ifdef CHARS_PER_LINE_16
#define endSecondLine 0x4f
#endif
#ifdef CHARS_PER_LINE_20
#define endSecondLine 0x53
#endif
#ifdef FOUR_LINES
#define thirdLine 0x14
#define fourthLine 0x54
#ifdef CHARS_PER_LINE_8
#define endThirdLine 0x1b
#define endFourthLine 0x5b
#endif
#ifdef CHARS_PER_LINE_16
#define endThirdLine 0x23
#define endFourthLine 0x63
#endif
#ifdef CHARS_PER_LINE_20
#define endThirdLine 0x27
#define endFourthLine 0x67
#endif
#endif
#define lcdBusyFlag 0x80
//=================================================================
// functions definitions
//=================================================================
unsigned char lcdIsBusy(void);
unsigned char lcdReadData();
unsigned char lcdRead();
#ifdef MODE_4_BIT
unsigned char lcdReadNibble();
#endif
void lcdSendCommand(unsigned char data);
void lcdSendChar(unsigned char charToSend);
void lcdSend(unsigned char dataToSend);
#ifdef MODE_4_BIT
void lcdSendNibble(unsigned char data);
#endif
void lcdInit(void);
#endif /* HD44780_H */
//=================================================================
// EOF
//=================================================================