📄 lcd_gcc.h
字号:
lcd.h
Go to the documentation of this file.00001
00002 //*****************************************************************************
00003 //
00004 // File Name : 'lcd.c'
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 : 3
00013 //
00014 // This code is distributed under the GNU Public License
00015 // which can be found at http://www.gnu.org/licenses/gpl.txt
00016 //
00017 //*****************************************************************************
00018
00019 // ********Changes by MG
00020 //
00021 // lines 90-91 changed lines to 2, line length to 24
00022
00023
00024 #ifndef LCD_H
00025 #define LCD_H
00026
00027 #include "global.h"
00028
00029 // Define type of interface used to access the LCD
00030 // LCD_MEMORY_INTERFACE:
00031 // To use this mode you must supply the necessary hardware to connect the
00032 // LCD to the CPU's memory bus. The CONTROL and DATA registers of the LCD
00033 // (HD44780 chip) must appear in the CPU's memory map. This mode is faster
00034 // than the port interface but requires a little extra hardware to make it
00035 // work. It is especially useful when your CPU is already configured to
00036 // use an external memory bus for other purposes (like accessing memory).
00037 //
00038 // LCD_PORT_INTERFACE:
00039 // This mode allows you to connect the control and data lines of the LCD
00040 // directly to the I/O port pins (no interfacing hardware is needed),
00041 // but it generally runs slower than the LCD_MEMORY_INTERFACE.
00042 // Depending on your needs, when using the LCD_PORT_INTERFACE, the LCD may
00043 // be accessed in 8-bit or 4-bit mode. In 8-bit mode, one whole I/O port
00044 // (pins 0-7) is required for the LCD data lines, but transfers are faster.
00045 // In 4-bit mode, only I/O port pins 4-7 are needed for data lines, but LCD
00046 // access is slower. In either mode, three additional port pins are
00047 // required for the LCD interface control lines (RS, R/W, and E).
00048
00049 // Enable one of the following interfaces to your LCD
00050 //#define LCD_MEMORY_INTERFACE
00051 #define LCD_PORT_INTERFACE
00052
00053 // Enter the parameters for your chosen interface'
00054 // if you chose the LCD_PORT_INTERFACE:
00055 #ifdef LCD_PORT_INTERFACE
00056 #ifndef LCD_CTRL_PORT
00057 // port and pins you will use for control lines
00058 #define LCD_CTRL_PORT PORTC
00059 #define LCD_CTRL_DDR DDRC
00060
00061 #define LCD_CTRL_RS PC2
00062 #define LCD_CTRL_RW PC3
00063 #define LCD_CTRL_E PC4
00064 #endif
00065 #ifndef LCD_DATA_POUT
00066 // port you will use for data lines
00067 #define LCD_DATA_POUT PORTA
00068 #define LCD_DATA_PIN PINA
00069 #define LCD_DATA_DDR DDRA
00070 // access mode you will use (defaults to 8bit unless 4bit is selected)
00071 #define LCD_DATA_4BIT
00072 #endif
00073 #endif
00074
00075 // if you chose the LCD_MEMORY_INTERFACE:
00076 #ifdef LCD_MEMORY_INTERFACE
00077 #ifndef LCD_CTRL_ADDR
00078 // CPU memory address of the LCD control register
00079 #define LCD_CTRL_ADDR 0x1000
00080 #endif
00081 #ifndef LCD_DATA_ADDR
00082 // CPU memory address of the LCD data register
00083 #define LCD_DATA_ADDR 0x1001
00084 #endif
00085 #endif
00086
00087
00088 // LCD display geometry
00089 // change these definitions to adapt setting
00090 #define LCD_LINES 2 // visible lines
00091 #define LCD_LINE_LENGTH 24 // line length (in characters)
00092
00093 // HD44780 LCD controller command set (do not modify these)
00094 // writing:
00095 #define LCD_CLR 0 // DB0: clear display
00096 #define LCD_HOME 1 // DB1: return to home position
00097 #define LCD_ENTRY_MODE 2 // DB2: set entry mode
00098 #define LCD_ENTRY_INC 1 // DB1: increment
00099 #define LCD_ENTRY_SHIFT 0 // DB2: shift
00100 #define LCD_ON_CTRL 3 // DB3: turn lcd/cursor on
00101 #define LCD_ON_DISPLAY 2 // DB2: turn display on
00102 #define LCD_ON_CURSOR 1 // DB1: turn cursor on
00103 #define LCD_ON_BLINK 0 // DB0: blinking cursor
00104 #define LCD_MOVE 4 // DB4: move cursor/display
00105 #define LCD_MOVE_DISP 3 // DB3: move display (0-> move cursor)
00106 #define LCD_MOVE_RIGHT 2 // DB2: move right (0-> left)
00107 #define LCD_FUNCTION 5 // DB5: function set
00108 #define LCD_FUNCTION_8BIT 4 // DB4: set 8BIT mode (0->4BIT mode)
00109 #define LCD_FUNCTION_2LINES 3 // DB3: two lines (0->one line)
00110 #define LCD_FUNCTION_10DOTS 2 // DB2: 5x10 font (0->5x7 font)
00111 #define LCD_CGRAM 6 // DB6: set CG RAM address
00112 #define LCD_DDRAM 7 // DB7: set DD RAM address
00113 // reading:
00114 #define LCD_BUSY 7 // DB7: LCD is busy
00115
00116 // Default LCD setup
00117 // this default setup is loaded on LCD initialization
00118 #ifdef LCD_DATA_4BIT
00119 #define LCD_FDEF_1 (0<<LCD_FUNCTION_8BIT)
00120 #else
00121 #define LCD_FDEF_1 (1<<LCD_FUNCTION_8BIT)
00122 #endif
00123 #define LCD_FDEF_2 (1<<LCD_FUNCTION_2LINES)
00124 #define LCD_FUNCTION_DEFAULT ((1<<LCD_FUNCTION) | LCD_FDEF_1 | LCD_FDEF_2)
00125 #define LCD_MODE_DEFAULT ((1<<LCD_ENTRY_MODE) | (1<<LCD_ENTRY_INC))
00126
00127 // custom LCD characters
00128 #define LCDCHAR_PROGRESS05 0 // 0/5 full progress block
00129 #define LCDCHAR_PROGRESS15 1 // 1/5 full progress block
00130 #define LCDCHAR_PROGRESS25 2 // 2/5 full progress block
00131 #define LCDCHAR_PROGRESS35 3 // 3/5 full progress block
00132 #define LCDCHAR_PROGRESS45 4 // 4/5 full progress block
00133 #define LCDCHAR_PROGRESS55 5 // 5/5 full progress block
00134 #define LCDCHAR_REWINDARROW 6 // rewind arrow
00135 #define LCDCHAR_STOPBLOCK 7 // stop block
00136 #define LCDCHAR_PAUSEBARS 8 // pause bars
00137 #define LCDCHAR_FORWARDARROW 9 // fast-forward arrow
00138 #define LCDCHAR_SCROLLUPARROW 10 // scroll up arrow
00139 #define LCDCHAR_SCROLLDNARROW 11 // scroll down arrow
00140 #define LCDCHAR_BLANK 12 // scroll down arrow
00141 #define LCDCHAR_ANIPLAYICON0 13 // animated play icon frame 0
00142 #define LCDCHAR_ANIPLAYICON1 14 // animated play icon frame 1
00143 #define LCDCHAR_ANIPLAYICON2 15 // animated play icon frame 2
00144 #define LCDCHAR_ANIPLAYICON3 16 // animated play icon frame 3
00145
00146 // progress bar defines
00147 #define PROGRESSPIXELS_PER_CHAR 6
00148
00149
00150 // ****** Low-level functions ******
00151 // the following functions are the only ones which deal with the CPU
00152 // memory or port pins directly. If you decide to use a fundamentally
00153 // different hardware interface to your LCD, only these functions need
00154 // to be changed, after which all the high-level functions will
00155 // work again.
00156
00157 // initializes I/O pins connected to LCD
00158 void lcdInitHW(void);
00159 // waits until LCD is not busy
00160 void lcdBusyWait(void);
00161 // writes a control command to the LCD
00162 void lcdControlWrite(u08 data);
00163 // read the control status from the LCD
00164 u08 lcdControlRead(void);
00165 // writes a data byte to the LCD screen at the current position
00166 void lcdDataWrite(u08 data);
00167 // reads the data byte on the LCD screen at the current position
00168 u08 lcdDataRead(void);
00169
00170
00171 // ****** High-levlel functions ******
00172 // these functions provide the high-level control of the LCD
00173 // such as clearing the display, setting cursor positions,
00174 // displaying text and special characters
00175
00176 // initializes the LCD display (gets it ready for use)
00177 void lcdInit(void);
00178
00179 // moves the cursor/position to Home (upper left corner)
00180 void lcdHome(void);
00181
00182 // clears the LCD display
00183 void lcdClear(void);
00184
00185 // moves the cursor/position to the row,col requested
00186 // ** this may not be accurate for all displays
00187 void lcdGotoXY(u08 row, u08 col);
00188
00189 // loads a special user-defined character into the LCD
00190 // <lcdCharNum> is the RAM location in the LCD (legal value: 0-7)
00191 // <romCharNum> is the ROM character number of the
00192 void lcdLoadCustomChar(u08 lcdCharNum, u08 romCharNum);
00193
00194 // prints a series of bytes/characters to the display
00195 void lcdPrintData(char* data, u08 nBytes);
00196
00197 // displays a horizontal progress bar at the current cursor location
00198 // <progress> is the value the bargraph should indicate
00199 // <maxprogress> is the value at the end of the bargraph
00200 // <length> is the number of LCD characters that the bargraph should cover
00201 void lcdProgressBar(u16 progress, u16 maxprogress, u08 length);
00202
00203 #endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -