1 | #include "lcd.h" |
---|
2 | |
---|
3 | lcd::lcd(void){ |
---|
4 | bcm2835_init(); |
---|
5 | this->LCD_RS = 4; |
---|
6 | this->LCD_E = 15; |
---|
7 | this->LCD_D4 = 24; |
---|
8 | this->LCD_D5 = 23; |
---|
9 | this->LCD_D6 = 14; |
---|
10 | this->LCD_D7 = 22; |
---|
11 | bcm2835_gpio_fsel(LCD_RS, BCM2835_GPIO_FSEL_OUTP); |
---|
12 | bcm2835_gpio_fsel(LCD_E, BCM2835_GPIO_FSEL_OUTP); |
---|
13 | bcm2835_gpio_fsel(LCD_D4, BCM2835_GPIO_FSEL_OUTP); |
---|
14 | bcm2835_gpio_fsel(LCD_D5, BCM2835_GPIO_FSEL_OUTP); |
---|
15 | bcm2835_gpio_fsel(LCD_D6, BCM2835_GPIO_FSEL_OUTP); |
---|
16 | bcm2835_gpio_fsel(LCD_D7, BCM2835_GPIO_FSEL_OUTP); |
---|
17 | |
---|
18 | this->lcd_byte(0x33,0); |
---|
19 | this->lcd_byte(0x32,0); |
---|
20 | this->lcd_byte(0x28,0); |
---|
21 | this->lcd_byte(0x0C,0); |
---|
22 | this->lcd_byte(0x06,0); |
---|
23 | this->lcd_byte(0x01,0); |
---|
24 | |
---|
25 | } |
---|
26 | |
---|
27 | lcd::~lcd(void){ |
---|
28 | bcm2835_close(); |
---|
29 | } |
---|
30 | void lcd::lcd_byte(uint8_t bits, bool mode) |
---|
31 | { |
---|
32 | int E_DELAY = 100; |
---|
33 | mode?bcm2835_gpio_set(LCD_RS):bcm2835_gpio_clr(LCD_RS); |
---|
34 | |
---|
35 | bcm2835_gpio_clr(LCD_D4); |
---|
36 | bcm2835_gpio_clr(LCD_D5); |
---|
37 | bcm2835_gpio_clr(LCD_D6); |
---|
38 | bcm2835_gpio_clr(LCD_D7); |
---|
39 | |
---|
40 | |
---|
41 | if ((bits&0x10)==0x10) bcm2835_gpio_set(LCD_D4); |
---|
42 | if ((bits&0x20)==0x20) bcm2835_gpio_set(LCD_D5); |
---|
43 | if ((bits&0x40)==0x40) bcm2835_gpio_set(LCD_D6); |
---|
44 | if ((bits&0x80)==0x80) bcm2835_gpio_set(LCD_D7); |
---|
45 | |
---|
46 | usleep(E_DELAY); |
---|
47 | bcm2835_gpio_set(LCD_E); |
---|
48 | usleep(E_DELAY); |
---|
49 | bcm2835_gpio_clr(LCD_E); |
---|
50 | usleep(E_DELAY); |
---|
51 | |
---|
52 | bcm2835_gpio_clr(LCD_D4); |
---|
53 | bcm2835_gpio_clr(LCD_D5); |
---|
54 | bcm2835_gpio_clr(LCD_D6); |
---|
55 | bcm2835_gpio_clr(LCD_D7); |
---|
56 | |
---|
57 | if ((bits&0x01)==0x01) bcm2835_gpio_set(LCD_D4); |
---|
58 | if ((bits&0x02)==0x02) bcm2835_gpio_set(LCD_D5); |
---|
59 | if ((bits&0x04)==0x04) bcm2835_gpio_set(LCD_D6); |
---|
60 | if ((bits&0x08)==0x08) bcm2835_gpio_set(LCD_D7); |
---|
61 | |
---|
62 | usleep(E_DELAY); |
---|
63 | bcm2835_gpio_set(LCD_E); |
---|
64 | usleep(E_DELAY); |
---|
65 | bcm2835_gpio_clr(LCD_E); |
---|
66 | usleep(E_DELAY); |
---|
67 | |
---|
68 | } |
---|
69 | |
---|
70 | void lcd::write(string message, uint8_t row) |
---|
71 | {if (row==1) this->lcd_byte(0x80, 0); |
---|
72 | if (row==2) this->lcd_byte(0xC0, 0); |
---|
73 | message.append(" ",16-message.length()); |
---|
74 | for (int i=0;i<16;i++) {this->lcd_byte(message[i],1);} |
---|
75 | } |
---|