00001 /*! \file lcd.h \brief Character LCD driver for HD44780/SED1278 displays. */ 00002 //***************************************************************************** 00003 // 00004 // File Name : 'lcd.h' 00005 // Title : Character LCD driver for HD44780/SED1278 displays 00006 // (usable in mem-mapped, or I/O mode) 00007 // Author : Pascal Stang 00008 // Created : 11/22/2000 00009 // Revised : 4/30/2002 00010 // Version : 1.1 00011 // Target MCU : Atmel AVR series 00012 // Editor Tabs : 4 00013 // 00014 /// \ingroup driver_hw 00015 /// \defgroup lcd Character LCD Driver for HD44780/SED1278-based displays (lcd.c) 00016 /// \code #include "lcd.h" \endcode 00017 /// \par Overview 00018 /// This display driver provides an interface to the most common type of 00019 /// character LCD, those based on the HD44780 or SED1278 controller chip 00020 /// (about 90% of character LCDs use one of these chips). The display driver 00021 /// can interface to the display through the CPU memory bus, or directly via 00022 /// I/O port pins. When using the direct I/O port mode, no additional 00023 /// interface hardware is needed except for a contrast potentiometer. 00024 /// Supported functions include initialization, clearing, scrolling, cursor 00025 /// positioning, text writing, and loading of custom characters or icons 00026 /// (up to 8). Although these displays are simple, clever use of the custom 00027 /// characters can allow you to create animations or simple graphics. The 00028 /// "progress bar" function that is included in this driver is an example of 00029 /// graphics using limited custom-chars. 00030 /// 00031 /// \Note The driver now supports both 8-bit and 4-bit interface modes. 00032 /// 00033 /// \Note For full text output functionality, you may wish to use the rprintf 00034 /// functions along with this driver 00035 // 00036 // This code is distributed under the GNU Public License 00037 // which can be found at http://www.gnu.org/licenses/gpl.txt 00038 // 00039 //***************************************************************************** 00040 00041 #ifndef LCD_H 00042 #define LCD_H 00043 00044 #include "global.h" 00045 00046 // include project-dependent configurations 00047 #include "lcdconf.h" 00048 00049 // HD44780 LCD controller command set (do not modify these) 00050 // writing: 00051 #define LCD_CLR 0 // DB0: clear display 00052 #define LCD_HOME 1 // DB1: return to home position 00053 #define LCD_ENTRY_MODE 2 // DB2: set entry mode 00054 #define LCD_ENTRY_INC 1 // DB1: increment 00055 #define LCD_ENTRY_SHIFT 0 // DB2: shift 00056 #define LCD_ON_CTRL 3 // DB3: turn lcd/cursor on 00057 #define LCD_ON_DISPLAY 2 // DB2: turn display on 00058 #define LCD_ON_CURSOR 1 // DB1: turn cursor on 00059 #define LCD_ON_BLINK 0 // DB0: blinking cursor 00060 #define LCD_MOVE 4 // DB4: move cursor/display 00061 #define LCD_MOVE_DISP 3 // DB3: move display (0-> move cursor) 00062 #define LCD_MOVE_RIGHT 2 // DB2: move right (0-> left) 00063 #define LCD_FUNCTION 5 // DB5: function set 00064 #define LCD_FUNCTION_8BIT 4 // DB4: set 8BIT mode (0->4BIT mode) 00065 #define LCD_FUNCTION_2LINES 3 // DB3: two lines (0->one line) 00066 #define LCD_FUNCTION_10DOTS 2 // DB2: 5x10 font (0->5x7 font) 00067 #define LCD_CGRAM 6 // DB6: set CG RAM address 00068 #define LCD_DDRAM 7 // DB7: set DD RAM address 00069 // reading: 00070 #define LCD_BUSY 7 // DB7: LCD is busy 00071 00072 // Default LCD setup 00073 // this default setup is loaded on LCD initialization 00074 #ifdef LCD_DATA_4BIT 00075 #define LCD_FDEF_1 (0<<LCD_FUNCTION_8BIT) 00076 #else 00077 #define LCD_FDEF_1 (1<<LCD_FUNCTION_8BIT) 00078 #endif 00079 #define LCD_FDEF_2 (1<<LCD_FUNCTION_2LINES) 00080 #define LCD_FUNCTION_DEFAULT ((1<<LCD_FUNCTION) | LCD_FDEF_1 | LCD_FDEF_2) 00081 #define LCD_MODE_DEFAULT ((1<<LCD_ENTRY_MODE) | (1<<LCD_ENTRY_INC)) 00082 00083 // custom LCD characters 00084 extern unsigned char __attribute__ ((progmem)) LcdCustomChar[]; 00085 #define LCDCHAR_PROGRESS05 0 // 0/5 full progress block 00086 #define LCDCHAR_PROGRESS15 1 // 1/5 full progress block 00087 #define LCDCHAR_PROGRESS25 2 // 2/5 full progress block 00088 #define LCDCHAR_PROGRESS35 3 // 3/5 full progress block 00089 #define LCDCHAR_PROGRESS45 4 // 4/5 full progress block 00090 #define LCDCHAR_PROGRESS55 5 // 5/5 full progress block 00091 #define LCDCHAR_REWINDARROW 6 // rewind arrow 00092 #define LCDCHAR_STOPBLOCK 7 // stop block 00093 #define LCDCHAR_PAUSEBARS 8 // pause bars 00094 #define LCDCHAR_FORWARDARROW 9 // fast-forward arrow 00095 #define LCDCHAR_SCROLLUPARROW 10 // scroll up arrow 00096 #define LCDCHAR_SCROLLDNARROW 11 // scroll down arrow 00097 #define LCDCHAR_BLANK 12 // scroll down arrow 00098 #define LCDCHAR_ANIPLAYICON0 13 // animated play icon frame 0 00099 #define LCDCHAR_ANIPLAYICON1 14 // animated play icon frame 1 00100 #define LCDCHAR_ANIPLAYICON2 15 // animated play icon frame 2 00101 #define LCDCHAR_ANIPLAYICON3 16 // animated play icon frame 3 00102 00103 // progress bar defines 00104 #define PROGRESSPIXELS_PER_CHAR 6 00105 00106 00107 // ****** Low-level functions ****** 00108 // the following functions are the only ones which deal with the CPU 00109 // memory or port pins directly. If you decide to use a fundamentally 00110 // different hardware interface to your LCD, only these functions need 00111 // to be changed, after which all the high-level functions will 00112 // work again. 00113 00114 // initializes I/O pins connected to LCD 00115 void lcdInitHW(void); 00116 // waits until LCD is not busy 00117 void lcdBusyWait(void); 00118 // writes a control command to the LCD 00119 void lcdControlWrite(u08 data); 00120 // read the control status from the LCD 00121 u08 lcdControlRead(void); 00122 // writes a data byte to the LCD screen at the current position 00123 void lcdDataWrite(u08 data); 00124 // reads the data byte on the LCD screen at the current position 00125 u08 lcdDataRead(void); 00126 00127 00128 // ****** High-levlel functions ****** 00129 // these functions provide the high-level control of the LCD 00130 // such as clearing the display, setting cursor positions, 00131 // displaying text and special characters 00132 00133 // initializes the LCD display (gets it ready for use) 00134 void lcdInit(void); 00135 00136 // moves the cursor/position to Home (upper left corner) 00137 void lcdHome(void); 00138 00139 // clears the LCD display 00140 void lcdClear(void); 00141 00142 // moves the cursor/position to the row,col requested 00143 // ** this may not be accurate for all displays 00144 void lcdGotoXY(u08 row, u08 col); 00145 00146 // loads a special user-defined character into the LCD 00147 // <lcdCustomCharArray> is a pointer to a ROM array containing custom characters 00148 // <romCharNum> is the index of the character to load from lcdCustomCharArray 00149 // <lcdCharNum> is the RAM location in the LCD (legal value: 0-7) 00150 void lcdLoadCustomChar(u08* lcdCustomCharArray, u08 romCharNum, u08 lcdCharNum); 00151 00152 // prints a series of bytes/characters to the display 00153 void lcdPrintData(char* data, u08 nBytes); 00154 00155 // displays a horizontal progress bar at the current cursor location 00156 // <progress> is the value the bargraph should indicate 00157 // <maxprogress> is the value at the end of the bargraph 00158 // <length> is the number of LCD characters that the bargraph should cover 00159 void lcdProgressBar(u16 progress, u16 maxprogress, u08 length); 00160 00161 #endif