Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# lcd.h

Go to the documentation of this file.

    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 // if LCD_DELAY is not defined, this definition sequence
    00050 // attempts to find a suitable LCD_DELAY given the F_CPU
    00051 #ifndef LCD_DELAY
    00052 #if F_CPU >= 16000000
    00053 #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");
    00054 #else
    00055 #if F_CPU >= 12000000
    00056 #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");
    00057 #else
    00058 #if F_CPU >= 8000000
    00059 #define LCD_DELAY   asm volatile ("nop\n nop\n nop\n nop\n nop\n nop\n nop\n");
    00060 #else
    00061 #if F_CPU >= 4000000
    00062 #define LCD_DELAY   asm volatile ("nop\n nop\n nop\n nop\n nop\n");
    00063 #else
    00064 #define LCD_DELAY   asm volatile ("nop\n nop\n nop\n");
    00065 #endif
    00066 #endif
    00067 #endif
    00068 #endif
    00069 #endif
    00070
    00071 // HD44780 LCD controller command set (do not modify these)
    00072 // writing:
    00073 #define LCD_CLR             0      // DB0: clear display
    00074 #define LCD_HOME            1      // DB1: return to home position
    00075 #define LCD_ENTRY_MODE      2      // DB2: set entry mode
    00076 #define LCD_ENTRY_INC       1      //   DB1: increment
    00077 #define LCD_ENTRY_SHIFT     0      //   DB2: shift
    00078 #define LCD_ON_CTRL         3      // DB3: turn lcd/cursor on
    00079 #define LCD_ON_DISPLAY      2      //   DB2: turn display on
    00080 #define LCD_ON_CURSOR       1      //   DB1: turn cursor on
    00081 #define LCD_ON_BLINK        0      //   DB0: blinking cursor
    00082 #define LCD_MOVE            4      // DB4: move cursor/display
    00083 #define LCD_MOVE_DISP       3      //   DB3: move display (0-> move cursor)
    00084 #define LCD_MOVE_RIGHT      2      //   DB2: move right (0-> left)
    00085 #define LCD_FUNCTION        5      // DB5: function set
    00086 #define LCD_FUNCTION_8BIT   4      //   DB4: set 8BIT mode (0->4BIT mode)
    00087 #define LCD_FUNCTION_2LINES 3      //   DB3: two lines (0->one line)
    00088 #define LCD_FUNCTION_10DOTS 2      //   DB2: 5x10 font (0->5x7 font)
    00089 #define LCD_CGRAM           6      // DB6: set CG RAM address
    00090 #define LCD_DDRAM           7      // DB7: set DD RAM address
    00091 // reading:
    00092 #define LCD_BUSY            7      // DB7: LCD is busy
    00093
    00094 // Default LCD setup
    00095 // this default setup is loaded on LCD initialization
    00096 #ifdef LCD_DATA_4BIT
    00097     #define LCD_FDEF_1          (0<<LCD_FUNCTION_8BIT)
    00098 #else
    00099     #define LCD_FDEF_1          (1<<LCD_FUNCTION_8BIT)
    00100 #endif
    00101 #define LCD_FDEF_2              (1<<LCD_FUNCTION_2LINES)
    00102 #define LCD_FUNCTION_DEFAULT    ((1<<LCD_FUNCTION) | LCD_FDEF_1 | LCD_FDEF_2)
    00103 #define LCD_MODE_DEFAULT        ((1<<LCD_ENTRY_MODE) | (1<<LCD_ENTRY_INC))
    00104
    00105 // custom LCD characters
    00106 extern unsigned char __attribute__ ((progmem)) LcdCustomChar[];
    00107 #define LCDCHAR_PROGRESS05      0   // 0/5 full progress block
    00108 #define LCDCHAR_PROGRESS15      1   // 1/5 full progress block
    00109 #define LCDCHAR_PROGRESS25      2   // 2/5 full progress block
    00110 #define LCDCHAR_PROGRESS35      3   // 3/5 full progress block
    00111 #define LCDCHAR_PROGRESS45      4   // 4/5 full progress block
    00112 #define LCDCHAR_PROGRESS55      5   // 5/5 full progress block
    00113 #define LCDCHAR_REWINDARROW     6   // rewind arrow
    00114 #define LCDCHAR_STOPBLOCK       7   // stop block
    00115 #define LCDCHAR_PAUSEBARS       8   // pause bars
    00116 #define LCDCHAR_FORWARDARROW    9   // fast-forward arrow
    00117 #define LCDCHAR_SCROLLUPARROW   10  // scroll up arrow
    00118 #define LCDCHAR_SCROLLDNARROW   11  // scroll down arrow
    00119 #define LCDCHAR_BLANK           12  // scroll down arrow
    00120 #define LCDCHAR_ANIPLAYICON0    13  // animated play icon frame 0
    00121 #define LCDCHAR_ANIPLAYICON1    14  // animated play icon frame 1
    00122 #define LCDCHAR_ANIPLAYICON2    15  // animated play icon frame 2
    00123 #define LCDCHAR_ANIPLAYICON3    16  // animated play icon frame 3
    00124
    00125 // progress bar defines
    00126 #define PROGRESSPIXELS_PER_CHAR 6
    00127
    00128
    00129 // ****** Low-level functions ******
    00130 // the following functions are the only ones which deal with the CPU
    00131 // memory or port pins directly.  If you decide to use a fundamentally
    00132 // different hardware interface to your LCD, only these functions need
    00133 // to be changed, after which all the high-level functions will
    00134 // work again.
    00135
    00136 // initializes I/O pins connected to LCD
    00137 void lcdInitHW(void);
    00138 // waits until LCD is not busy
    00139 void lcdBusyWait(void);
    00140 // writes a control command to the LCD
    00141 void lcdControlWrite(u08 data);
    00142 // read the control status from the LCD
    00143 u08 lcdControlRead(void);
    00144 // writes a data byte to the LCD screen at the current position
    00145 void lcdDataWrite(u08 data);
    00146 // reads the data byte on the LCD screen at the current position
    00147 u08 lcdDataRead(void);
    00148
    00149
    00150 // ****** High-levlel functions ******
    00151 // these functions provide the high-level control of the LCD
    00152 // such as clearing the display, setting cursor positions,
    00153 // displaying text and special characters
    00154
    00155 // initializes the LCD display (gets it ready for use)
    00156 void lcdInit(void);
    00157
    00158 // moves the cursor/position to Home (upper left corner)
    00159 void lcdHome(void);
    00160
    00161 // clears the LCD display
    00162 void lcdClear(void);
    00163
    00164 // moves the cursor/position to the row,col requested
    00165 // ** this may not be accurate for all displays
    00166 void lcdGotoXY(u08 row, u08 col);
    00167
    00168 // loads a special user-defined character into the LCD
    00169 // <lcdCustomCharArray> is a pointer to a ROM array containing custom characters
    00170 // <romCharNum> is the index of the character to load from lcdCustomCharArray
    00171 // <lcdCharNum> is the RAM location in the LCD (legal value: 0-7)
    00172 void lcdLoadCustomChar(u08* lcdCustomCharArray, u08 romCharNum, u08 lcdCharNum);
    00173
    00174 // prints a series of bytes/characters to the display
    00175 void lcdPrintData(char* data, u08 nBytes);
    00176
    00177 // displays a horizontal progress bar at the current cursor location
    00178 // <progress> is the value the bargraph should indicate
    00179 // <maxprogress> is the value at the end of the bargraph
    00180 // <length> is the number of LCD characters that the bargraph should cover
    00181 void lcdProgressBar(u16 progress, u16 maxprogress, u08 length);
    00182
    00183 #endif