質問編集履歴
1
OLEDディスプレイに表示される文字がeと出ます
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,232 @@
|
|
1
|
+
```#include <Wire.h>
|
2
|
+
|
3
|
+
#define OLED_ADRS 0x3C //SA0=L(SA0=H の場合は 0x3D)
|
4
|
+
|
5
|
+
int DisplayON = 0x0F,
|
6
|
+
|
7
|
+
ClearDisplay = 0x01,
|
8
|
+
|
9
|
+
ReturnHome = 0x02;
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
int DS1307_ADDRESS=0x68;
|
14
|
+
|
15
|
+
int val=0;
|
16
|
+
|
17
|
+
byte command;
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
void setup() {
|
24
|
+
|
25
|
+
Wire.begin(); //Wire ライブラリを初期化し、I2C マスタとしてバスに接続
|
26
|
+
|
27
|
+
init_oled();
|
28
|
+
|
29
|
+
printTime();
|
30
|
+
|
31
|
+
setDay();
|
32
|
+
|
33
|
+
setTime();
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
void loop() {
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
writeData(r_sec);
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
writeCommand(0x20+0x80); //2 行目の先頭
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
contrast_max(); //輝度を最大に設定
|
56
|
+
|
57
|
+
while(1){}
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
//----main end----
|
62
|
+
|
63
|
+
void writeData(byte t_data)
|
64
|
+
|
65
|
+
{
|
66
|
+
|
67
|
+
Wire.beginTransmission(OLED_ADRS);
|
68
|
+
|
69
|
+
Wire.write(0x40);
|
70
|
+
|
71
|
+
Wire.write(t_data);
|
72
|
+
|
73
|
+
Wire.endTransmission();
|
74
|
+
|
75
|
+
delay(1);
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
void writeCommand(byte t_command)
|
80
|
+
|
81
|
+
{
|
82
|
+
|
83
|
+
Wire.beginTransmission(OLED_ADRS);
|
84
|
+
|
85
|
+
Wire.write(0x00);
|
86
|
+
|
87
|
+
Wire.write(t_command);
|
88
|
+
|
89
|
+
Wire.endTransmission();
|
90
|
+
|
91
|
+
delay(10);
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
void contrast_max(){
|
96
|
+
|
97
|
+
writeCommand(0x2a);//RE=1
|
98
|
+
|
99
|
+
writeCommand(0x79);//SD=1
|
100
|
+
|
101
|
+
writeCommand(0x81);//コントラストセット
|
102
|
+
|
103
|
+
writeCommand(0xFF);//輝度MAX
|
104
|
+
|
105
|
+
writeCommand(0x78);//SD を0にもどす
|
106
|
+
|
107
|
+
writeCommand(0x28); //2C=高文字 28=ノーマル
|
108
|
+
|
109
|
+
delay(100);
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
void setTime(){
|
114
|
+
|
115
|
+
byte hour=(Serial.read()<<4);
|
116
|
+
|
117
|
+
hour=hour+(Serial.read()&0x0F);
|
118
|
+
|
119
|
+
byte minute=(Serial.read()<<4);
|
120
|
+
|
121
|
+
minute=minute+(Serial.read()&0x0F);
|
122
|
+
|
123
|
+
byte sec=(Serial.read()<<4);
|
124
|
+
|
125
|
+
sec=sec+(Serial.read()&0x0F);
|
126
|
+
|
127
|
+
Wire.beginTransmission(DS1307_ADDRESS);
|
128
|
+
|
129
|
+
Wire.write(val);
|
130
|
+
|
131
|
+
Wire.write(sec);
|
132
|
+
|
133
|
+
Wire.write(minute);
|
134
|
+
|
135
|
+
Wire.write(hour);
|
136
|
+
|
137
|
+
Wire.endTransmission();
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
void setDay(){
|
144
|
+
|
145
|
+
byte year=(Serial.read()<<4);
|
146
|
+
|
147
|
+
year=year+(Serial.read()&0x0F);
|
148
|
+
|
149
|
+
byte month=(Serial.read()<<4);
|
150
|
+
|
151
|
+
month=month+(Serial.read()&0x0F);
|
152
|
+
|
153
|
+
byte day=(Serial.read()<<4);
|
154
|
+
|
155
|
+
day=day+(Serial.read()&0x0F);
|
156
|
+
|
157
|
+
byte day_of_week=(Serial.read()&0x0F);
|
158
|
+
|
159
|
+
Wire.beginTransmission(DS1307_ADDRESS);
|
160
|
+
|
161
|
+
Wire.write(0x03);
|
162
|
+
|
163
|
+
Wire.write(day_of_week);
|
164
|
+
|
165
|
+
Wire.write(day);
|
166
|
+
|
167
|
+
Wire.write(month);
|
168
|
+
|
169
|
+
Wire.write(year);
|
170
|
+
|
171
|
+
Wire.endTransmission();
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
void printTime(){
|
176
|
+
|
177
|
+
Wire.beginTransmission(DS1307_ADDRESS);
|
178
|
+
|
179
|
+
Wire.write(val);
|
180
|
+
|
181
|
+
Wire.endTransmission();
|
182
|
+
|
183
|
+
Wire.requestFrom(DS1307_ADDRESS,7);
|
184
|
+
|
185
|
+
byte r_sec=Wire.read();
|
186
|
+
|
187
|
+
byte r_minute=Wire.read();
|
188
|
+
|
189
|
+
byte r_hour=Wire.read();
|
190
|
+
|
191
|
+
byte r_day_of_week=Wire.read();
|
192
|
+
|
193
|
+
byte r_date=Wire.read();
|
194
|
+
|
195
|
+
byte r_month=Wire.read();
|
196
|
+
|
197
|
+
byte r_year=Wire.read();
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
void init_oled()
|
204
|
+
|
205
|
+
{
|
206
|
+
|
207
|
+
delay(100);
|
208
|
+
|
209
|
+
writeCommand(ClearDisplay); // Clear Display
|
210
|
+
|
211
|
+
delay(20);
|
212
|
+
|
213
|
+
writeCommand(ReturnHome); // ReturnHome
|
214
|
+
|
215
|
+
delay(2);
|
216
|
+
|
217
|
+
writeCommand(DisplayON); // Send Display on command
|
218
|
+
|
219
|
+
delay(2);
|
220
|
+
|
221
|
+
writeCommand(ClearDisplay); // Clear Display
|
222
|
+
|
223
|
+
delay(20);
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
コード
|
228
|
+
|
1
|
-
RTC(DS1307)とOLEDディスプレイ(so1602aw)のコードを参考にしてr_secを表示するコードを作ってみたのですがうまくいきません。
|
229
|
+
```RTC(DS1307)とOLEDディスプレイ(so1602aw)のコードを参考にしてr_secを表示するコードを作ってみたのですがうまくいきません。
|
2
230
|
|
3
231
|
何が間違っていますか?
|
4
232
|
|