LCD  1.0
HD44780 compatible lcd driver for Xmega devices
 All Files Functions Variables Macros
lcd.h
Go to the documentation of this file.
1 
45 #ifndef F_CPU
46 #define F_CPU 2000000UL
47 #endif
48 
52 #define LCD_4BIT_MODE 1
53 
56 #define LCD_BUSY_FLAG 0
57 
61 #define LCD_DATA_PORT PORTA
62 #define LCD_D0_PORT LCD_DATA_PORT
63 #define LCD_D1_PORT LCD_DATA_PORT
64 #define LCD_D2_PORT LCD_DATA_PORT
65 #define LCD_D3_PORT LCD_DATA_PORT
66 #define LCD_D4_PORT LCD_DATA_PORT
67 #define LCD_D5_PORT LCD_DATA_PORT
68 #define LCD_D6_PORT LCD_DATA_PORT
69 #define LCD_D7_PORT LCD_DATA_PORT
70 #define LCD_D0_bp PIN0_bp
71 #define LCD_D1_bp PIN1_bp
72 #define LCD_D2_bp PIN2_bp
73 #define LCD_D3_bp PIN3_bp
74 #define LCD_D4_bp PIN4_bp
75 #define LCD_D5_bp PIN5_bp
76 #define LCD_D6_bp PIN6_bp
77 #define LCD_D7_bp PIN7_bp
78 
79 
82 #define LCD_COMM_PORT PORTD
83 #define LCD_RS_PORT LCD_COMM_PORT
84 #define LCD_RW_PORT LCD_COMM_PORT
85 #define LCD_E_PORT LCD_COMM_PORT
86 #define LCD_RS_bp PIN4_bp
87 #define LCD_RW_bp PIN3_bp
88 #define LCD_E_bp PIN5_bp
89 
90 #define TDELAY1_ms 50
91 #define TDELAY2_ms 5
92 #define TDELAY3_us 100
93 #define TPWE_us 0.5
94 #define TDELAY_us 50
95 #define T_CLEARDISPLAY_us 1600
96 
97 #define LCD_LINES 2
98 #define LCD_DISP_LENGTH 16
99 
100 #if LCD_DISP_LENGTH==16
101 #define LCD_START_LINE1 0x00
102 #define LCD_START_LINE2 0x40
103 #define LCD_START_LINE3 0x10
104 #define LCD_START_LINE4 0x50
105 #else
106 #define LCD_START_LINE1 0x00
107 #define LCD_START_LINE2 0x40
108 #define LCD_START_LINE3 0x14
109 #define LCD_START_LINE4 0x54
110 #endif
111 
112 #define LCD_CLR_bp 0
113 #define LCD_HOME_bp 1
114 #define LCD_ENTRY_MODE_bp 2
115 #define LCD_ENTRY_INC_bp 1
116 #define LCD_ENTRY_SHIFT_bp 0
117 #define LCD_ON_bp 3
118 #define LCD_ON_DISPLAY_bp 2
119 #define LCD_ON_CURSOR_bp 1
120 #define LCD_ON_BLINK_bp 0
121 #define LCD_MOVE_bp 4
122 #define LCD_MOVE_DISP_bp 3
123 #define LCD_MOVE_RIGHT_bp 2
124 #define LCD_FUNCTION_bp 5
125 #define LCD_FUNCTION_8BIT_bp 4
126 #define LCD_FUNCTION_2LINES_bp 3
127 #define LCD_FUNCTION_10DOTS_bp 2
128 #define LCD_CGRAM_bp 6
129 #define LCD_DDRAM_bp 7
130 #define LCD_BUSY_bp 7
131 
132 #define LCD_ENTRY_DEC 0x04
133 #define LCD_ENTRY_DEC_SHIFT 0x05
134 #define LCD_ENTRY_INC 0x06
135 #define LCD_ENTRY_INC_SHIFT 0x07
136 
137 #define LCD_DISP_OFF 0x08
138 #define LCD_DISP_ON 0x0C
139 #define LCD_DISP_ON_BLINK 0x0D
140 #define LCD_DISP_ON_CURSOR 0x0E
141 #define LCD_DISP_ON_CURSOR_BLINK 0x0F
142 
143 #define LCD_MOVE_CURSOR_LEFT 0x10
144 #define LCD_MOVE_CURSOR_RIGHT 0x14
145 #define LCD_MOVE_DISP_LEFT 0x18
146 #define LCD_MOVE_DISP_RIGHT 0x1C
147 
148 #define LCD_FUNCTION_4BIT 0x20
149 #define LCD_FUNCTION_4BIT_1LINE 0x20
150 #define LCD_FUNCTION_4BIT_2LINES 0x28
151 #define LCD_FUNCTION_8BIT 0x30
152 #define LCD_FUNCTION_8BIT_1LINE 0x30
153 #define LCD_FUNCTION_8BIT_2LINES 0x38
154 
155 void lcd_init(void);
156 void lcd_clear(void);
157 void lcd_home(void);
158 void lcd_gotoxy(uint8_t x, uint8_t y);
159 void lcd_putc(char c);
160 void lcd_puts(char *s);
161 void lcd_cmd(uint8_t cmd);
162 void lcd_data(uint8_t b);
163 
164 #define LCD_D0_bm (1 << (LCD_D0_bp))
165 #define LCD_D1_bm (1 << (LCD_D1_bp))
166 #define LCD_D2_bm (1 << (LCD_D2_bp))
167 #define LCD_D3_bm (1 << (LCD_D3_bp))
168 #define LCD_D4_bm (1 << (LCD_D4_bp))
169 #define LCD_D5_bm (1 << (LCD_D5_bp))
170 #define LCD_D6_bm (1 << (LCD_D6_bp))
171 #define LCD_D7_bm (1 << (LCD_D7_bp))
172 #define LCD_RS_bm (1 << (LCD_RS_bp))
173 #define LCD_RW_bm (1 << (LCD_RW_bp))
174 #define LCD_E_bm (1 << (LCD_E_bp))
175 
176 
192 #if LCD_BUSY_FLAG==1
193 #if LCD_4BIT_MODE==1
194 #define LCD_DATA_PORT_gm ((LCD_D7_bm)|(LCD_D6_bm)|(LCD_D5_bm)|(LCD_D4_bm))
195 #define LCD_WRITE_BYTE(b,rs) (lcd4bf_write_byte((b),(rs)))
196 #define LCD_INIT lcd4bf_init
197 #else
198 #define LCD_DATA_PORT_gm (0xFF)
199 #define LCD_WRITE_BYTE(b,rs) (lcd8bf_write_byte((b),(rs)))
200 #define LCD_INIT lcd8bf_init
201 #endif
202 #else
203 #if LCD_4BIT_MODE==1
204 #define LCD_DATA_PORT_gm ((LCD_D7_bm)|(LCD_D6_bm)|(LCD_D5_bm)|(LCD_D4_bm))
205 #define LCD_WRITE_BYTE(b,rs) (lcd4_write_byte((b),(rs)))
206 #define LCD_INIT lcd4_init
207 #else
208 #define LCD_DATA_PORT_gm (0xFF)
209 #define LCD_WRITE_BYTE(b,rs) (lcd8_write_byte((b),(rs)))
210 #define LCD_INIT lcd8_init
211 #endif
212 #endif
213 
void lcd_puts(char *s)
Writes a string to the LCD.
Definition: lcd.c:316
void lcd_clear(void)
Clear lcd.
Definition: lcd.c:367
void lcd_home(void)
Cursor to home position.
Definition: lcd.c:380
void lcd_data(uint8_t b)
Writes a data byte to the LCD.
Definition: lcd.c:303
void lcd_gotoxy(uint8_t x, uint8_t y)
Set cursor to specified position.
Definition: lcd.c:334
void lcd_init(void)
Initialize the lcd.
Definition: lcd.c:249
void lcd_putc(char c)
Writes a character to the LCD.
Definition: lcd.c:265
void lcd_cmd(uint8_t cmd)
Writes a command char to the LCD.
Definition: lcd.c:290