Line No. | Rev | Author | Line |
---|---|---|---|
1 | 6 | kaklik | /*! \file lcd.h \brief Character LCD driver for HD44780/SED1278 displays. */ |
2 | //***************************************************************************** |
||
3 | // |
||
4 | // File Name : 'lcd.h' |
||
5 | // Title : Character LCD driver for HD44780/SED1278 displays |
||
6 | // (usable in mem-mapped, or I/O mode) |
||
7 | // Author : Pascal Stang |
||
8 | // Created : 11/22/2000 |
||
9 | // Revised : 4/30/2002 |
||
10 | // Version : 1.1 |
||
11 | // Target MCU : Atmel AVR series |
||
12 | // Editor Tabs : 4 |
||
13 | // |
||
14 | /// \ingroup driver_hw |
||
15 | /// \defgroup lcd Character LCD Driver for HD44780/SED1278-based displays (lcd.c) |
||
16 | /// \code #include "lcd.h" \endcode |
||
17 | /// \par Overview |
||
18 | /// This display driver provides an interface to the most common type of |
||
19 | /// character LCD, those based on the HD44780 or SED1278 controller chip |
||
20 | /// (about 90% of character LCDs use one of these chips). The display driver |
||
21 | /// can interface to the display through the CPU memory bus, or directly via |
||
22 | /// I/O port pins. When using the direct I/O port mode, no additional |
||
23 | /// interface hardware is needed except for a contrast potentiometer. |
||
24 | /// Supported functions include initialization, clearing, scrolling, cursor |
||
25 | /// positioning, text writing, and loading of custom characters or icons |
||
26 | /// (up to 8). Although these displays are simple, clever use of the custom |
||
27 | /// characters can allow you to create animations or simple graphics. The |
||
28 | /// "progress bar" function that is included in this driver is an example of |
||
29 | /// graphics using limited custom-chars. |
||
30 | /// |
||
31 | /// \Note The driver now supports both 8-bit and 4-bit interface modes. |
||
32 | /// |
||
33 | /// \Note For full text output functionality, you may wish to use the rprintf |
||
34 | /// functions along with this driver |
||
35 | // |
||
36 | // This code is distributed under the GNU Public License |
||
37 | // which can be found at http://www.gnu.org/licenses/gpl.txt |
||
38 | // |
||
39 | //***************************************************************************** |
||
40 | |||
41 | #ifndef LCD_H |
||
42 | #define LCD_H |
||
43 | |||
44 | #include "global.h" |
||
45 | |||
46 | // include project-dependent configurations |
||
47 | #include "lcdconf.h" |
||
48 | |||
49 | // if LCD_DELAY is not defined, this definition sequence |
||
50 | // attempts to find a suitable LCD_DELAY given the F_CPU |
||
51 | #ifndef LCD_DELAY |
||
52 | #if F_CPU >= 16000000 |
||
53 | #define LCD_DELAY asm volatile ("nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n"); |
||
54 | #else |
||
55 | #if F_CPU >= 12000000 |
||
56 | #define LCD_DELAY asm volatile ("nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n"); |
||
57 | #else |
||
58 | #if F_CPU >= 8000000 |
||
59 | #define LCD_DELAY asm volatile ("nop\n nop\n nop\n nop\n nop\n nop\n nop\n"); |
||
60 | #else |
||
61 | #if F_CPU >= 4000000 |
||
62 | #define LCD_DELAY asm volatile ("nop\n nop\n nop\n nop\n nop\n"); |
||
63 | #else |
||
64 | #define LCD_DELAY asm volatile ("nop\n nop\n nop\n"); |
||
65 | #endif |
||
66 | #endif |
||
67 | #endif |
||
68 | #endif |
||
69 | #endif |
||
70 | |||
71 | // HD44780 LCD controller command set (do not modify these) |
||
72 | // writing: |
||
73 | #define LCD_CLR 0 // DB0: clear display |
||
74 | #define LCD_HOME 1 // DB1: return to home position |
||
75 | #define LCD_ENTRY_MODE 2 // DB2: set entry mode |
||
76 | #define LCD_ENTRY_INC 1 // DB1: increment |
||
77 | #define LCD_ENTRY_SHIFT 0 // DB2: shift |
||
78 | #define LCD_ON_CTRL 3 // DB3: turn lcd/cursor on |
||
79 | #define LCD_ON_DISPLAY 2 // DB2: turn display on |
||
80 | #define LCD_ON_CURSOR 1 // DB1: turn cursor on |
||
81 | #define LCD_ON_BLINK 0 // DB0: blinking cursor |
||
82 | #define LCD_MOVE 4 // DB4: move cursor/display |
||
83 | #define LCD_MOVE_DISP 3 // DB3: move display (0-> move cursor) |
||
84 | #define LCD_MOVE_RIGHT 2 // DB2: move right (0-> left) |
||
85 | #define LCD_FUNCTION 5 // DB5: function set |
||
86 | #define LCD_FUNCTION_8BIT 4 // DB4: set 8BIT mode (0->4BIT mode) |
||
87 | #define LCD_FUNCTION_2LINES 3 // DB3: two lines (0->one line) |
||
88 | #define LCD_FUNCTION_10DOTS 2 // DB2: 5x10 font (0->5x7 font) |
||
89 | #define LCD_CGRAM 6 // DB6: set CG RAM address |
||
90 | #define LCD_DDRAM 7 // DB7: set DD RAM address |
||
91 | // reading: |
||
92 | #define LCD_BUSY 7 // DB7: LCD is busy |
||
93 | |||
94 | // Default LCD setup |
||
95 | // this default setup is loaded on LCD initialization |
||
96 | #ifdef LCD_DATA_4BIT |
||
97 | #define LCD_FDEF_1 (0<<LCD_FUNCTION_8BIT) |
||
98 | #else |
||
99 | #define LCD_FDEF_1 (1<<LCD_FUNCTION_8BIT) |
||
100 | #endif |
||
101 | #define LCD_FDEF_2 (1<<LCD_FUNCTION_2LINES) |
||
102 | #define LCD_FUNCTION_DEFAULT ((1<<LCD_FUNCTION) | LCD_FDEF_1 | LCD_FDEF_2) |
||
103 | #define LCD_MODE_DEFAULT ((1<<LCD_ENTRY_MODE) | (1<<LCD_ENTRY_INC)) |
||
104 | |||
105 | // custom LCD characters |
||
106 | extern unsigned char __attribute__ ((progmem)) LcdCustomChar[]; |
||
107 | #define LCDCHAR_PROGRESS05 0 // 0/5 full progress block |
||
108 | #define LCDCHAR_PROGRESS15 1 // 1/5 full progress block |
||
109 | #define LCDCHAR_PROGRESS25 2 // 2/5 full progress block |
||
110 | #define LCDCHAR_PROGRESS35 3 // 3/5 full progress block |
||
111 | #define LCDCHAR_PROGRESS45 4 // 4/5 full progress block |
||
112 | #define LCDCHAR_PROGRESS55 5 // 5/5 full progress block |
||
113 | #define LCDCHAR_REWINDARROW 6 // rewind arrow |
||
114 | #define LCDCHAR_STOPBLOCK 7 // stop block |
||
115 | #define LCDCHAR_PAUSEBARS 8 // pause bars |
||
116 | #define LCDCHAR_FORWARDARROW 9 // fast-forward arrow |
||
117 | #define LCDCHAR_SCROLLUPARROW 10 // scroll up arrow |
||
118 | #define LCDCHAR_SCROLLDNARROW 11 // scroll down arrow |
||
119 | #define LCDCHAR_BLANK 12 // scroll down arrow |
||
120 | #define LCDCHAR_ANIPLAYICON0 13 // animated play icon frame 0 |
||
121 | #define LCDCHAR_ANIPLAYICON1 14 // animated play icon frame 1 |
||
122 | #define LCDCHAR_ANIPLAYICON2 15 // animated play icon frame 2 |
||
123 | #define LCDCHAR_ANIPLAYICON3 16 // animated play icon frame 3 |
||
124 | |||
125 | // progress bar defines |
||
126 | #define PROGRESSPIXELS_PER_CHAR 6 |
||
127 | |||
128 | |||
129 | // ****** Low-level functions ****** |
||
130 | // the following functions are the only ones which deal with the CPU |
||
131 | // memory or port pins directly. If you decide to use a fundamentally |
||
132 | // different hardware interface to your LCD, only these functions need |
||
133 | // to be changed, after which all the high-level functions will |
||
134 | // work again. |
||
135 | |||
136 | // initializes I/O pins connected to LCD |
||
137 | void lcdInitHW(void); |
||
138 | // waits until LCD is not busy |
||
139 | void lcdBusyWait(void); |
||
140 | // writes a control command to the LCD |
||
141 | void lcdControlWrite(u08 data); |
||
142 | // read the control status from the LCD |
||
143 | u08 lcdControlRead(void); |
||
144 | // writes a data byte to the LCD screen at the current position |
||
145 | void lcdDataWrite(u08 data); |
||
146 | // reads the data byte on the LCD screen at the current position |
||
147 | u08 lcdDataRead(void); |
||
148 | |||
149 | |||
150 | // ****** High-levlel functions ****** |
||
151 | // these functions provide the high-level control of the LCD |
||
152 | // such as clearing the display, setting cursor positions, |
||
153 | // displaying text and special characters |
||
154 | |||
155 | // initializes the LCD display (gets it ready for use) |
||
156 | void lcdInit(void); |
||
157 | |||
158 | // moves the cursor/position to Home (upper left corner) |
||
159 | void lcdHome(void); |
||
160 | |||
161 | // clears the LCD display |
||
162 | void lcdClear(void); |
||
163 | |||
164 | // moves the cursor/position to the row,col requested |
||
165 | // ** this may not be accurate for all displays |
||
166 | void lcdGotoXY(u08 row, u08 col); |
||
167 | |||
168 | // loads a special user-defined character into the LCD |
||
169 | // <lcdCustomCharArray> is a pointer to a ROM array containing custom characters |
||
170 | // <romCharNum> is the index of the character to load from lcdCustomCharArray |
||
171 | // <lcdCharNum> is the RAM location in the LCD (legal value: 0-7) |
||
172 | void lcdLoadCustomChar(u08* lcdCustomCharArray, u08 romCharNum, u08 lcdCharNum); |
||
173 | |||
174 | // prints a series of bytes/characters to the display |
||
175 | void lcdPrintData(char* data, u08 nBytes); |
||
176 | |||
177 | // displays a horizontal progress bar at the current cursor location |
||
178 | // <progress> is the value the bargraph should indicate |
||
179 | // <maxprogress> is the value at the end of the bargraph |
||
180 | // <length> is the number of LCD characters that the bargraph should cover |
||
181 | void lcdProgressBar(u16 progress, u16 maxprogress, u08 length); |
||
182 | |||
183 | #endif |
Powered by WebSVN v2.8.3