DIGILIGHT
lcd.h
1 #ifndef LCD_H_
2 #define LCD_H_
3 /*************************************************************************
4  Title : C include file for the HD44780U LCD library (lcd.c)
5  Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury
6  File: $Id: lcd.h,v 1.13.2.2 2006/01/30 19:51:33 peter Exp $
7  Software: AVR-GCC 3.3
8  Hardware: any AVR device, memory mapped mode only for AT90S4414/8515/Mega
9 ***************************************************************************/
10 
36 #if (__GNUC__ * 100 + __GNUC_MINOR__) < 303
37 #error "This library requires AVR-GCC 3.3 or later, update to newer AVR-GCC compiler !"
38 #endif
39 
40 #include <inttypes.h>
41 #include <avr/pgmspace.h>
42 
47 #ifdef F_CPU
48 #define XTAL F_CPU
49 #else
50 #define XTAL 4000000
51 #endif
52 
53 
58 #define LCD_CONTROLLER_KS0073 0
64 #define LCD_LINES 2
65 #define LCD_DISP_LENGTH 16
66 #define LCD_LINE_LENGTH 0x40
67 #define LCD_START_LINE1 0x00
68 #define LCD_START_LINE2 0x40
69 #define LCD_START_LINE3 0x14
70 #define LCD_START_LINE4 0x54
71 #define LCD_WRAP_LINES 0
74 #define LCD_IO_MODE 1
75 #if LCD_IO_MODE
76 
90 #include "hardware.h"
91 
92 #elif defined(__AVR_AT90S4414__) || defined(__AVR_AT90S8515__) || defined(__AVR_ATmega64__) || \
93  defined(__AVR_ATmega8515__)|| defined(__AVR_ATmega103__) || defined(__AVR_ATmega128__) || \
94  defined(__AVR_ATmega161__) || defined(__AVR_ATmega162__)
95 /*
96  * memory mapped mode is only supported when the device has an external data memory interface
97  */
98 #define LCD_IO_DATA 0xC000 /* A15=E=1, A14=RS=1 */
99 #define LCD_IO_FUNCTION 0x8000 /* A15=E=1, A14=RS=0 */
100 #define LCD_IO_READ 0x0100 /* A8 =R/W=1 (R/W: 1=Read, 0=Write */
101 #else
102 #error "external data memory interface not available for this device, use 4-bit IO port mode"
103 
104 #endif
105 
106 
113 /* instruction register bit positions, see HD44780U data sheet */
114 #define LCD_CLR 0 /* DB0: clear display */
115 #define LCD_HOME 1 /* DB1: return to home position */
116 #define LCD_ENTRY_MODE 2 /* DB2: set entry mode */
117 #define LCD_ENTRY_INC 1 /* DB1: 1=increment, 0=decrement */
118 #define LCD_ENTRY_SHIFT 0 /* DB2: 1=display shift on */
119 #define LCD_ON 3 /* DB3: turn lcd/cursor on */
120 #define LCD_ON_DISPLAY 2 /* DB2: turn display on */
121 #define LCD_ON_CURSOR 1 /* DB1: turn cursor on */
122 #define LCD_ON_BLINK 0 /* DB0: blinking cursor ? */
123 #define LCD_MOVE 4 /* DB4: move cursor/display */
124 #define LCD_MOVE_DISP 3 /* DB3: move display (0-> cursor) ? */
125 #define LCD_MOVE_RIGHT 2 /* DB2: move right (0-> left) ? */
126 #define LCD_FUNCTION 5 /* DB5: function set */
127 #define LCD_FUNCTION_8BIT 4 /* DB4: set 8BIT mode (0->4BIT mode) */
128 #define LCD_FUNCTION_2LINES 3 /* DB3: two lines (0->one line) */
129 #define LCD_FUNCTION_10DOTS 2 /* DB2: 5x10 font (0->5x7 font) */
130 #define LCD_CGRAM 6 /* DB6: set CG RAM address */
131 #define LCD_DDRAM 7 /* DB7: set DD RAM address */
132 #define LCD_BUSY 7 /* DB7: LCD is busy */
133 
134 /* set entry mode: display shift on/off, dec/inc cursor move direction */
135 #define LCD_ENTRY_DEC 0x04 /* display shift off, dec cursor move dir */
136 #define LCD_ENTRY_DEC_SHIFT 0x05 /* display shift on, dec cursor move dir */
137 #define LCD_ENTRY_INC_ 0x06 /* display shift off, inc cursor move dir */
138 #define LCD_ENTRY_INC_SHIFT 0x07 /* display shift on, inc cursor move dir */
139 
140 /* display on/off, cursor on/off, blinking char at cursor position */
141 #define LCD_DISP_OFF 0x08 /* display off */
142 #define LCD_DISP_ON 0x0C /* display on, cursor off */
143 #define LCD_DISP_ON_BLINK 0x0D /* display on, cursor off, blink char */
144 #define LCD_DISP_ON_CURSOR 0x0E /* display on, cursor on */
145 #define LCD_DISP_ON_CURSOR_BLINK 0x0F /* display on, cursor on, blink char */
146 
147 /* move cursor/shift display */
148 #define LCD_MOVE_CURSOR_LEFT 0x10 /* move cursor left (decrement) */
149 #define LCD_MOVE_CURSOR_RIGHT 0x14 /* move cursor right (increment) */
150 #define LCD_MOVE_DISP_LEFT 0x18 /* shift display left */
151 #define LCD_MOVE_DISP_RIGHT 0x1C /* shift display right */
152 
153 /* function set: set interface data length and number of display lines */
154 #define LCD_FUNCTION_4BIT_1LINE 0x20 /* 4-bit interface, single line, 5x7 dots */
155 #define LCD_FUNCTION_4BIT_2LINES 0x28 /* 4-bit interface, dual line, 5x7 dots */
156 #define LCD_FUNCTION_8BIT_1LINE 0x30 /* 8-bit interface, single line, 5x7 dots */
157 #define LCD_FUNCTION_8BIT_2LINES 0x38 /* 8-bit interface, dual line, 5x7 dots */
158 
159 
160 #define LCD_MODE_DEFAULT ((1<<LCD_ENTRY_MODE) | (1<<LCD_ENTRY_INC) )
161 
162 
163 
172 extern void lcd_init(void);
173 
174 
178 extern void lcd_clrscr(void);
179 
180 
184 extern void lcd_home(void);
185 
186 
194 extern void lcd_gotoxy(uint8_t x, uint8_t y);
195 
196 
202 extern void lcd_putc(char c);
203 
204 
210 extern void lcd_puts(const char *s);
211 
212 
219 extern void lcd_puts_p(const char *progmem_s);
220 
221 
227 extern void lcd_command(uint8_t cmd);
228 
229 
237 extern void lcd_data(uint8_t data);
238 
239 
243 #define lcd_puts_P(__s) lcd_puts_p(PSTR(__s))
244 
245 uint8_t lcd_getxy(void);
246 uint8_t lcd_read(uint8_t rs);
247 
249 #endif //LCD_H
void lcd_puts_p(const char *progmem_s)
Display string from program memory without auto linefeed.
Definition: lcd.c:500
void lcd_gotoxy(uint8_t x, uint8_t y)
Set cursor to specified position.
Definition: lcd.c:380
void lcd_clrscr(void)
Clear display and set cursor to home position.
Definition: lcd.c:416
void lcd_home(void)
Set cursor to home position.
Definition: lcd.c:425
void lcd_command(uint8_t cmd)
Send LCD controller instruction command.
Definition: lcd.c:354
Аппаратно-зависимые определения
void lcd_data(uint8_t data)
Send data byte to LCD controller.
Definition: lcd.c:366
void lcd_puts(const char *s)
Display string without auto linefeed.
Definition: lcd.c:483
void lcd_init(void)
Initialize display and select type of cursor.
Definition: lcd.c:520
void lcd_putc(char c)
Display character at current cursor position.
Definition: lcd.c:436