1 /* vim: set sw=8 ts=8 si : */
2 /****************************************************************************
3 * Title : HD44780 LCD library
5 * Based on Volker Oth's lcd library (http://members.xoom.com/volkeroth)
6 * modified by Peter Fleury's (http://jump.to/fleury). Flexible pin
7 * configuration by Markus Ermert. Adapted for the tuxgraphics LCD display
11 * Target: any AVR device
14 *****************************************************************************/
17 #include <avr/pgmspace.h>
19 /* you shouldn't need to change anything below this line */
21 /* instruction register bit positions */
22 #define LCD_CLR 0 /* DB0: clear display */
23 #define LCD_HOME 1 /* DB1: return to home position */
24 #define LCD_ENTRY_MODE 2 /* DB2: set entry mode */
25 #define LCD_ENTRY_INC 1 /* DB1: 1=increment, 0=decrement */
26 #define LCD_ENTRY_SHIFT 0 /* DB2: 1=display shift on */
27 #define LCD_ON 3 /* DB3: turn lcd/cursor on */
28 #define LCD_ON_DISPLAY 2 /* DB2: turn display on */
29 #define LCD_ON_CURSOR 1 /* DB1: turn cursor on */
30 #define LCD_ON_BLINK 0 /* DB0: blinking cursor ? */
31 #define LCD_MOVE 4 /* DB4: move cursor/display */
32 #define LCD_MOVE_DISP 3 /* DB3: move display (0-> cursor) ? */
33 #define LCD_MOVE_RIGHT 2 /* DB2: move right (0-> left) ? */
34 #define LCD_FUNCTION 5 /* DB5: function set */
35 #define LCD_FUNCTION_8BIT 4 /* DB4: set 8BIT mode (0->4BIT mode) */
36 #define LCD_FUNCTION_2LINES 3 /* DB3: two lines (0->one line) */
37 #define LCD_FUNCTION_10DOTS 2 /* DB2: 5x10 font (0->5x7 font) */
38 #define LCD_CGRAM 6 /* DB6: set CG RAM address */
39 #define LCD_DDRAM 7 /* DB7: set DD RAM address */
40 #define LCD_BUSY 7 /* DB7: LCD is busy */
42 /* set entry mode: display shift on/off, dec/inc cursor move direction */
43 #define LCD_ENTRY_DEC 0x04 /* display shift off, dec cursor move dir */
44 #define LCD_ENTRY_DEC_SHIFT 0x05 /* display shift on, dec cursor move dir */
45 #define LCD_ENTRY_INC_ 0x06 /* display shift off, inc cursor move dir */
46 #define LCD_ENTRY_INC_SHIFT 0x07 /* display shift on, inc cursor move dir */
48 /* display on/off, cursor on/off, blinking char at cursor position */
49 #define LCD_DISP_OFF 0x08 /* display off */
50 #define LCD_DISP_ON 0x0C /* display on, cursor off */
51 #define LCD_DISP_ON_BLINK 0x0D /* display on, cursor off, blink char */
52 #define LCD_DISP_ON_CURSOR 0x0E /* display on, cursor on */
53 #define LCD_DISP_ON_CURSOR_BLINK 0x0F /* display on, cursor on, blink char */
55 /* move cursor/shift display */
56 #define LCD_MOVE_CURSOR_LEFT 0x10 /* move cursor left (decrement) */
57 #define LCD_MOVE_CURSOR_RIGHT 0x14 /* move cursor right (increment) */
58 #define LCD_MOVE_DISP_LEFT 0x18 /* shift display left */
59 #define LCD_MOVE_DISP_RIGHT 0x1C /* shift display right */
61 /* function set: set interface data length and number of display lines */
62 #define LCD_FUNCTION_4BIT_1LINE 0x20 /* 4-bit interface, single line, 5x7 dots */
63 #define LCD_FUNCTION_4BIT_2LINES 0x28 /* 4-bit interface, dual line, 5x7 dots */
64 #define LCD_FUNCTION_8BIT_1LINE 0x30 /* 8-bit interface, single line, 5x7 dots */
65 #define LCD_FUNCTION_8BIT_2LINES 0x38 /* 8-bit interface, dual line, 5x7 dots */
67 #define LCD_MODE_DEFAULT ((1<<LCD_ENTRY_MODE) | (1<<LCD_ENTRY_INC) )
70 /* defines which can be used like functions */
72 /* clear lcd and set cursor to home position */
73 #define lcd_clrscr() lcd_command(1 << LCD_CLR)
75 /* set cursor to home position */
76 #define lcd_home() lcd_command(1 << LCD_HOME)
79 ** function prototypes
81 extern void lcd_command(uint8_t cmd);
82 extern void lcd_gotoxy(uint8_t x, uint8_t y); /* line 1 y=0, line 2 y=1 */
83 extern void lcd_putc(char c); /* print character at current cursor position */
84 extern void lcd_puts(const char *s); /* print string on lcd (no auto linefeed) */
86 /* if you hard code a string in the program then you need to decalare
87 * it like: char *str =PSTR("hello world");
88 * and then use lcd_puts_p(str);*/
89 extern void lcd_puts_p(const char *progmem_s ); /* print string from program memory on lcd (no auto linefeed) */
90 // lcd_puts_p can be used like this: lcd_puts_p(PSTR("hello"))
91 extern void lcd_init(void); /* initialize the LCD. Call this once*/
92 extern void lcd_reset(void);