-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path8-2.cpp
More file actions
157 lines (130 loc) · 4.65 KB
/
8-2.cpp
File metadata and controls
157 lines (130 loc) · 4.65 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "I2CDevice.h"
#include <unistd.h>
#include <iostream>
#define I2C_BUS "/dev/i2c-3" // I2C bus device
#define I2C_ADDR 0x27 // I2C slave address for the LCD module
using namespace std ;
using namespace exploringBB ;
class LCD : public I2CDevice {
private :
unsigned int I2CBus, I2CAddress ;
int status ;
public :
LCD(int I2CBus, int I2CAddress) ;
int writeHex(char value) ;
~LCD() ;
};
LCD::LCD(int I2CBus, int I2CAddress = 0x27) : I2CDevice(I2CBus, I2CAddress) {
this->I2CAddress = I2CAddress ;
this->I2CBus = I2CBus ;
}
int LCD::writeHex(char value) {
status = this->write(value) ;
usleep(1000) ;
if (status != 1) {
return 1 ;
}
return status ;
}
LCD::~LCD() {
}
int main(int argc, char* [])
{
int led_num = 76 ;
char buffer[10] = "" ;
char buffer2[10] = "" ;
int status ;
int value ;
LCD lcd = LCD(3, I2C_ADDR) ;
usleep(15000) ; // 전원 공급 대기시간
lcd.writeHex(0x34) ; // D7=0, D6=0, D5=1, D4=1, RS,RW=0 EN=1
lcd.writeHex(0x30) ; // D7=0, D6=0, D5=1, D4=1, RS,RW=0 EN=0
usleep(4100) ;
lcd.writeHex(0x34) ;
lcd.writeHex(0x30) ;
usleep(100) ;
lcd.writeHex(0x34) ;
lcd.writeHex(0x30) ;
usleep(4100) ;
lcd.writeHex(0x24) ; // 4-bit mode
lcd.writeHex(0x20) ;
/* -------------------------------------------------------------------- *
* 4-bit mode initialization complete. Now configuring the function set *
* -------------------------------------------------------------------- */
usleep(40); // wait 40usec
lcd.writeHex(0x24) ; // keep 4-bit mode
lcd.writeHex(0x20) ;
lcd.writeHex(0x84) ;
lcd.writeHex(0x80) ; // D3=2lines, D2=char5x8, function set
/* -------------------------------------------------------------------- *
* Next turn display off *
* -------------------------------------------------------------------- */
usleep(40); // wait 40usec
lcd.writeHex(0x04) ;
lcd.writeHex(0x00) ; // D7-D4=0
lcd.writeHex(0x84) ;
lcd.writeHex(0x80) ; // D3=1 D2=display_off, D1=cursor_off, D0=cursor_blink
/* -------------------------------------------------------------------- *
* Display clear, cursor home *
* -------------------------------------------------------------------- */
usleep(40); // wait 40usec
lcd.writeHex(0x04) ;
lcd.writeHex(0x00) ; // D7-D4=0
lcd.writeHex(0x14) ;
lcd.writeHex(0x80) ; // D0=display_clear
/* -------------------------------------------------------------------- *
* Set cursor direction *
* -------------------------------------------------------------------- */
usleep(40); // wait 40usec
lcd.writeHex(0x04) ;
lcd.writeHex(0x00) ; // D7-D4=0
lcd.writeHex(0x64) ;
lcd.writeHex(0x60) ; // print left to right
/* -------------------------------------------------------------------- *
* Turn on the display *
* -------------------------------------------------------------------- */
usleep(40); // wait 40usec
lcd.writeHex(0x04) ;
lcd.writeHex(0x00) ; // D7-D4=0
lcd.writeHex(0xE4) ;
lcd.writeHex(0xE0) ; // D3=1 D2=display_on, D1=cursor_on, D0=cursor_blink
sleep(1) ;
cout << "display on" << endl ;
lcd.writeHex(0x4D) ;
lcd.writeHex(0x49) ; // send 0100=4
lcd.writeHex(0x8D) ;
lcd.writeHex(0x89) ; // send 1000=8 = 0x48 ='H'
lcd.writeHex(0x4D) ;
lcd.writeHex(0x49) ; // send 0100=4
lcd.writeHex(0x5D) ;
lcd.writeHex(0x59) ; // send 0101=1 = 0x41 ='E'
lcd.writeHex(0x4D) ;
lcd.writeHex(0x49) ; // send 0100=4
lcd.writeHex(0xCD) ;
lcd.writeHex(0xC9) ; // send 1100=12 = 0x4D ='L'
lcd.writeHex(0x4D) ;
lcd.writeHex(0x49) ; // send 0100=4
lcd.writeHex(0xCD) ;
lcd.writeHex(0xC9) ; // send 1100=12 = 0x4D ='L'
lcd.writeHex(0x4D) ;
lcd.writeHex(0x49) ; // send 0100=4
lcd.writeHex(0xFD) ;
lcd.writeHex(0xF9) ; // send 1111=15 = 0x4F ='O'
// 공백
lcd.writeHex(0x1D) ;
lcd.writeHex(0x19) ; // 0001
lcd.writeHex(0x8D) ;
lcd.writeHex(0x89) ; // 1000
// X
// 0101 1101
// 0101 1001
// 1000 1101
// 1000 1001
lcd.writeHex(0x5D) ;
lcd.writeHex(0x59) ; // 0101
lcd.writeHex(0x8D) ;
lcd.writeHex(0x89) ; // 1000
usleep(1000) ;
lcd.close() ;
return 0 ;
}