-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlcd2004_i2c.h
61 lines (57 loc) · 1.97 KB
/
lcd2004_i2c.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef LCD2004_I2C_H
#define LCD2004_I2C_H
#include <stdint.h> /* uint8_t */
/* general commands */
#define LCD_CLEARDISPLAY 0x01
#define LCD_CURSORSHIFT 0x10
#define LCD_DISPLAYCONTROL 0x08
#define LCD_ENTRYMODESET 0x04
#define LCD_FUNCTIONSET 0x20
#define LCD_RETURNHOME 0x02
#define LCD_SETCGRAMADDR 0x40
#define LCD_SETDDRAMADDR 0x80
/* entrymode flags */
#define LCD_ENTRYRIGHT 0x00
#define LCD_ENTRYLEFT 0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00
/* displaycontrol flags */
#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF 0x00
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00
#define LCD_BACKLIGHT 0x08
#define LCD_NOBACKLIGHT 0x00
/* cursorshift flags */
#define LCD_DISPLAYMOVE 0x08
#define LCD_CURSORMOVE 0x00
#define LCD_MOVERIGHT 0x04
#define LCD_MOVELEFT 0x00
/* functionset flags */
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_2LINE 0x08
#define LCD_1LINE 0x00
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00
/* write modes for lcd_write_byte */
#define LCD_CMD 0
#define LCD_CHR 1
typedef struct lcd LCD;
LCD *lcd_init(int bus, int addr);
void lcd_delete(LCD *lcd);
void lcd_send_byte(LCD *lcd, uint8_t val, uint8_t mode); /* <- not meant for direct calling */
void lcd_backlight(LCD *lcd, uint8_t on);
void lcd_move(LCD *lcd, int x, int y);
void lcd_write(LCD *lcd, char *data);
/* convenient wrapper macros */
#define lcd_mvwrite(lcd, x, y, data) do { lcd_move(lcd, x, y); lcd_write(lcd, data); } while (0)
#define lcd_send_cmd(lcd, cmd) lcd_send_byte(lcd, cmd, LCD_CMD)
#define lcd_send_chr(lcd, chr) lcd_send_byte(lcd, chr, LCD_CHR)
#define lcd_off(lcd) lcd_send_cmd(lcd, LCD_DISPLAYCONTROL | LCD_DISPLAYOFF)
#define lcd_on(lcd) lcd_send_cmd(lcd, LCD_DISPLAYCONTROL | LCD_DISPLAYON)
#define lcd_clear(lcd) do { lcd_send_cmd(lcd, LCD_CLEARDISPLAY); lcd_send_cmd(lcd, LCD_RETURNHOME); } while (0)
#define lcd_cgramset(lcd, addr) lcd_send_cmd(lcd, LCD_SETCGRAMADDR|((addr)<<3))
#endif