source: ETALON/DAQ/Sensors/lcd/lcd.cpp @ 709

Last change on this file since 709 was 709, checked in by hodnevuc, 7 years ago
File size: 1.8 KB
Line 
1#include "lcd.h"
2
3lcd::lcd(void){
4        bcm2835_init();
5this->LCD_RS = 4;
6this->LCD_E  = 15;
7this->LCD_D4 = 24;
8this->LCD_D5 = 23;
9this->LCD_D6 = 14;
10this->LCD_D7 = 22;
11bcm2835_gpio_fsel(LCD_RS, BCM2835_GPIO_FSEL_OUTP);
12bcm2835_gpio_fsel(LCD_E, BCM2835_GPIO_FSEL_OUTP);
13bcm2835_gpio_fsel(LCD_D4, BCM2835_GPIO_FSEL_OUTP);
14bcm2835_gpio_fsel(LCD_D5, BCM2835_GPIO_FSEL_OUTP);
15bcm2835_gpio_fsel(LCD_D6, BCM2835_GPIO_FSEL_OUTP);
16bcm2835_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
27lcd::~lcd(void){
28        bcm2835_close();
29}
30void lcd::lcd_byte(uint8_t bits, bool mode)
31{
32int E_DELAY = 100;
33mode?bcm2835_gpio_set(LCD_RS):bcm2835_gpio_clr(LCD_RS);
34
35bcm2835_gpio_clr(LCD_D4);
36bcm2835_gpio_clr(LCD_D5);
37bcm2835_gpio_clr(LCD_D6);
38bcm2835_gpio_clr(LCD_D7);
39
40
41if ((bits&0x10)==0x10) bcm2835_gpio_set(LCD_D4);
42if ((bits&0x20)==0x20) bcm2835_gpio_set(LCD_D5);
43if ((bits&0x40)==0x40) bcm2835_gpio_set(LCD_D6);
44if ((bits&0x80)==0x80) bcm2835_gpio_set(LCD_D7);
45
46usleep(E_DELAY);
47bcm2835_gpio_set(LCD_E);
48usleep(E_DELAY);
49bcm2835_gpio_clr(LCD_E);
50usleep(E_DELAY);
51
52bcm2835_gpio_clr(LCD_D4);
53bcm2835_gpio_clr(LCD_D5);
54bcm2835_gpio_clr(LCD_D6);
55bcm2835_gpio_clr(LCD_D7);
56   
57if ((bits&0x01)==0x01) bcm2835_gpio_set(LCD_D4);
58if ((bits&0x02)==0x02) bcm2835_gpio_set(LCD_D5);
59if ((bits&0x04)==0x04) bcm2835_gpio_set(LCD_D6);
60if ((bits&0x08)==0x08) bcm2835_gpio_set(LCD_D7);
61
62usleep(E_DELAY);
63bcm2835_gpio_set(LCD_E);
64usleep(E_DELAY);
65bcm2835_gpio_clr(LCD_E);
66usleep(E_DELAY);
67
68}
69
70void lcd::write(string message, uint8_t row)
71{if (row==1) this->lcd_byte(0x80, 0);
72if (row==2) this->lcd_byte(0xC0, 0);
73 message.append("                ",16-message.length());
74for (int i=0;i<16;i++) {this->lcd_byte(message[i],1);}
75}
Note: See TracBrowser for help on using the repository browser.