User | Revision | Line number | New contents of line |
lynxeyed_atsu |
0:2c787ad08fad
|
1
|
// ALO-095BWNN-J9 test program
|
lynxeyed_atsu |
0:2c787ad08fad
|
2
|
// See also "http://www.aitendo.co.jp/product/2099"
|
lynxeyed_atsu |
0:2c787ad08fad
|
3
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
4
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
5
|
#ifndef __SPIOLED_H__
|
lynxeyed_atsu |
0:2c787ad08fad
|
6
|
#define __SPIOLED_H__
|
lynxeyed_atsu |
0:2c787ad08fad
|
7
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
8
|
#include "mbed.h"
|
lynxeyed_atsu |
0:2c787ad08fad
|
9
|
#include "small_font.h"
|
lynxeyed_atsu |
0:2c787ad08fad
|
10
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
11
|
class SPIOLED {
|
lynxeyed_atsu |
0:2c787ad08fad
|
12
|
private:
|
lynxeyed_atsu |
0:2c787ad08fad
|
13
|
DigitalOut CS, RES, DC;
|
lynxeyed_atsu |
0:2c787ad08fad
|
14
|
SPI spi; // mosi, miso, sclk
|
lynxeyed_atsu |
0:2c787ad08fad
|
15
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
16
|
#define Dis_X_MAX 96-1 // Max X axial direction in screen
|
lynxeyed_atsu |
0:2c787ad08fad
|
17
|
#define Dis_Y_MAX 64-1 // Max Y axial direction in screen
|
lynxeyed_atsu |
0:2c787ad08fad
|
18
|
#define X_Witch 8 // character's width
|
lynxeyed_atsu |
0:2c787ad08fad
|
19
|
#define Y_Witch 8 // character's height
|
lynxeyed_atsu |
0:2c787ad08fad
|
20
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
21
|
unsigned int Char_Color; //character's color
|
lynxeyed_atsu |
0:2c787ad08fad
|
22
|
unsigned int BGround_Color;
|
lynxeyed_atsu |
0:2c787ad08fad
|
23
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
24
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
25
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
26
|
void Init(void){
|
lynxeyed_atsu |
0:2c787ad08fad
|
27
|
spi.format(8,0); // nazo
|
lynxeyed_atsu |
0:2c787ad08fad
|
28
|
spi.frequency(25000000); // modify later
|
lynxeyed_atsu |
0:2c787ad08fad
|
29
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
30
|
// reset
|
lynxeyed_atsu |
0:2c787ad08fad
|
31
|
wait_ms(200);
|
lynxeyed_atsu |
0:2c787ad08fad
|
32
|
RES = 0; //Reset active
|
lynxeyed_atsu |
0:2c787ad08fad
|
33
|
wait_ms(200);
|
lynxeyed_atsu |
0:2c787ad08fad
|
34
|
RES = 1;
|
lynxeyed_atsu |
0:2c787ad08fad
|
35
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
36
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
37
|
// initialize sequence
|
lynxeyed_atsu |
0:2c787ad08fad
|
38
|
RegWrite(0xae); //OLED display OFF
|
lynxeyed_atsu |
0:2c787ad08fad
|
39
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
40
|
//Row Address
|
lynxeyed_atsu |
0:2c787ad08fad
|
41
|
RegWrite(0x75); /* Set Row Address */
|
lynxeyed_atsu |
0:2c787ad08fad
|
42
|
RegWrite(0x00); /* Start = 0 */
|
lynxeyed_atsu |
0:2c787ad08fad
|
43
|
RegWrite(0x3f); /* End = 63 */
|
lynxeyed_atsu |
0:2c787ad08fad
|
44
|
RegWrite(0x15); /* Set Column Address */
|
lynxeyed_atsu |
0:2c787ad08fad
|
45
|
RegWrite(0x00); /* Start = 0 */
|
lynxeyed_atsu |
0:2c787ad08fad
|
46
|
RegWrite(0x5F); /* End = 96 */
|
lynxeyed_atsu |
0:2c787ad08fad
|
47
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
48
|
//Contrast
|
lynxeyed_atsu |
0:2c787ad08fad
|
49
|
RegWrite(0xa0); //Set remap & data format 0111 0000
|
lynxeyed_atsu |
0:2c787ad08fad
|
50
|
RegWrite(0x74);
|
lynxeyed_atsu |
0:2c787ad08fad
|
51
|
RegWrite(0xa1); //set display star row RAM
|
lynxeyed_atsu |
0:2c787ad08fad
|
52
|
RegWrite(0x00);
|
lynxeyed_atsu |
0:2c787ad08fad
|
53
|
RegWrite(0xa2); //set dispaly offset
|
lynxeyed_atsu |
0:2c787ad08fad
|
54
|
RegWrite(0x00);
|
lynxeyed_atsu |
0:2c787ad08fad
|
55
|
RegWrite(0xa4); //Set Display Mode
|
lynxeyed_atsu |
0:2c787ad08fad
|
56
|
RegWrite(0xa8); //Set Multiplex Ratio
|
lynxeyed_atsu |
0:2c787ad08fad
|
57
|
RegWrite(0x3f);
|
lynxeyed_atsu |
0:2c787ad08fad
|
58
|
RegWrite(0xad); //Set Master Configuration
|
lynxeyed_atsu |
0:2c787ad08fad
|
59
|
RegWrite(0x8f); //(External VCC Supply Selected)
|
lynxeyed_atsu |
0:2c787ad08fad
|
60
|
RegWrite(0xB0); //Set Power Saving Mode
|
lynxeyed_atsu |
0:2c787ad08fad
|
61
|
RegWrite(0x1a);
|
lynxeyed_atsu |
0:2c787ad08fad
|
62
|
RegWrite(0xB1); //Set Phase 1 & 2 Period Adjustment
|
lynxeyed_atsu |
0:2c787ad08fad
|
63
|
RegWrite(0x74);
|
lynxeyed_atsu |
0:2c787ad08fad
|
64
|
RegWrite(0xb3); //Set Display Clock Divide Ratio / Oscillator Frequency
|
lynxeyed_atsu |
0:2c787ad08fad
|
65
|
RegWrite(0xd0);
|
lynxeyed_atsu |
0:2c787ad08fad
|
66
|
RegWrite(0x8A); //Set Second Pre-charge Speed of Color A
|
lynxeyed_atsu |
0:2c787ad08fad
|
67
|
RegWrite(0x81);
|
lynxeyed_atsu |
0:2c787ad08fad
|
68
|
RegWrite(0x8B); //Set Second Pre-charge Speed of Color B
|
lynxeyed_atsu |
0:2c787ad08fad
|
69
|
RegWrite(0x82);
|
lynxeyed_atsu |
0:2c787ad08fad
|
70
|
RegWrite(0x8C); //Set Second Pre-charge Speed of Color C
|
lynxeyed_atsu |
0:2c787ad08fad
|
71
|
RegWrite(0x83);
|
lynxeyed_atsu |
0:2c787ad08fad
|
72
|
RegWrite(0xBB); //Set Pre-charge Level
|
lynxeyed_atsu |
0:2c787ad08fad
|
73
|
RegWrite(0x3e);
|
lynxeyed_atsu |
0:2c787ad08fad
|
74
|
RegWrite(0xBE); //Set VCOMH
|
lynxeyed_atsu |
0:2c787ad08fad
|
75
|
RegWrite(0x3e);
|
lynxeyed_atsu |
0:2c787ad08fad
|
76
|
RegWrite(0x87); //Set Master Current Control
|
lynxeyed_atsu |
0:2c787ad08fad
|
77
|
RegWrite(0x0f);
|
lynxeyed_atsu |
0:2c787ad08fad
|
78
|
RegWrite(0x81); //Set Contrast Control for Color gAh
|
lynxeyed_atsu |
0:2c787ad08fad
|
79
|
RegWrite(0x80);
|
lynxeyed_atsu |
0:2c787ad08fad
|
80
|
RegWrite(0x82); //Set Contrast Control for Color gBh
|
lynxeyed_atsu |
0:2c787ad08fad
|
81
|
RegWrite(0x80);
|
lynxeyed_atsu |
0:2c787ad08fad
|
82
|
RegWrite(0x83); //Set Contrast Control for Color gCh
|
lynxeyed_atsu |
0:2c787ad08fad
|
83
|
RegWrite(0x80);
|
lynxeyed_atsu |
0:2c787ad08fad
|
84
|
RegWrite(0xaf); //display ON
|
lynxeyed_atsu |
0:2c787ad08fad
|
85
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
86
|
}
|
lynxeyed_atsu |
0:2c787ad08fad
|
87
|
public:
|
lynxeyed_atsu |
0:2c787ad08fad
|
88
|
// constructor
|
lynxeyed_atsu |
0:2c787ad08fad
|
89
|
SPIOLED(PinName cs_pin, PinName rst_pin, PinName a0_pin, PinName mosi_pin, PinName miso_pin, PinName sclk_pin)
|
lynxeyed_atsu |
0:2c787ad08fad
|
90
|
: CS(cs_pin), RES(rst_pin), DC(a0_pin), spi(mosi_pin, miso_pin, sclk_pin) {
|
lynxeyed_atsu |
0:2c787ad08fad
|
91
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
92
|
Init();
|
lynxeyed_atsu |
0:2c787ad08fad
|
93
|
}
|
lynxeyed_atsu |
0:2c787ad08fad
|
94
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
95
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
96
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
97
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
98
|
void RegWrite(unsigned char Command)
|
lynxeyed_atsu |
0:2c787ad08fad
|
99
|
{
|
lynxeyed_atsu |
0:2c787ad08fad
|
100
|
DC = 0; // Command
|
lynxeyed_atsu |
0:2c787ad08fad
|
101
|
CS = 0; // CS active(toggle OLED)
|
lynxeyed_atsu |
0:2c787ad08fad
|
102
|
spi.write(Command);
|
lynxeyed_atsu |
0:2c787ad08fad
|
103
|
CS = 1;
|
lynxeyed_atsu |
0:2c787ad08fad
|
104
|
}
|
lynxeyed_atsu |
0:2c787ad08fad
|
105
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
106
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
107
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
108
|
void DataWrite(unsigned char c){
|
lynxeyed_atsu |
0:2c787ad08fad
|
109
|
DC = 1; // DATA
|
lynxeyed_atsu |
0:2c787ad08fad
|
110
|
CS = 0; // CS active(toggle OLED)
|
lynxeyed_atsu |
0:2c787ad08fad
|
111
|
spi.write(c);
|
lynxeyed_atsu |
0:2c787ad08fad
|
112
|
CS = 1;
|
lynxeyed_atsu |
0:2c787ad08fad
|
113
|
}
|
lynxeyed_atsu |
0:2c787ad08fad
|
114
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
115
|
void DataWrite_to(unsigned int Dat)
|
lynxeyed_atsu |
0:2c787ad08fad
|
116
|
{
|
lynxeyed_atsu |
0:2c787ad08fad
|
117
|
DataWrite((unsigned char)((Dat >> 8)& 0x00ff));
|
lynxeyed_atsu |
0:2c787ad08fad
|
118
|
DataWrite((unsigned char)(Dat & 0x00ff));
|
lynxeyed_atsu |
0:2c787ad08fad
|
119
|
}
|
lynxeyed_atsu |
0:2c787ad08fad
|
120
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
121
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
122
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
123
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
124
|
void Draw_Dot(unsigned char x,unsigned char y,unsigned int Color)
|
lynxeyed_atsu |
0:2c787ad08fad
|
125
|
{
|
lynxeyed_atsu |
0:2c787ad08fad
|
126
|
RegWrite(0x15);
|
lynxeyed_atsu |
0:2c787ad08fad
|
127
|
RegWrite(x);
|
lynxeyed_atsu |
0:2c787ad08fad
|
128
|
RegWrite(x);
|
lynxeyed_atsu |
0:2c787ad08fad
|
129
|
RegWrite(0x75);
|
lynxeyed_atsu |
0:2c787ad08fad
|
130
|
RegWrite(y);
|
lynxeyed_atsu |
0:2c787ad08fad
|
131
|
RegWrite(y);
|
lynxeyed_atsu |
0:2c787ad08fad
|
132
|
DataWrite_to(Color);
|
lynxeyed_atsu |
0:2c787ad08fad
|
133
|
DataWrite_to(Color);
|
lynxeyed_atsu |
0:2c787ad08fad
|
134
|
}
|
lynxeyed_atsu |
0:2c787ad08fad
|
135
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
136
|
void Full_Screen(unsigned int Dot)
|
lynxeyed_atsu |
0:2c787ad08fad
|
137
|
{
|
lynxeyed_atsu |
0:2c787ad08fad
|
138
|
unsigned char i,j;
|
lynxeyed_atsu |
0:2c787ad08fad
|
139
|
BGround_Color = Dot;
|
lynxeyed_atsu |
0:2c787ad08fad
|
140
|
for(i=0;i<=64;i++)
|
lynxeyed_atsu |
0:2c787ad08fad
|
141
|
{
|
lynxeyed_atsu |
0:2c787ad08fad
|
142
|
for(j=0;j<96;j++)
|
lynxeyed_atsu |
0:2c787ad08fad
|
143
|
{
|
lynxeyed_atsu |
0:2c787ad08fad
|
144
|
Draw_Dot(j,i,Dot);
|
lynxeyed_atsu |
0:2c787ad08fad
|
145
|
// DataWrite_to(Dot);
|
lynxeyed_atsu |
0:2c787ad08fad
|
146
|
}
|
lynxeyed_atsu |
0:2c787ad08fad
|
147
|
}
|
lynxeyed_atsu |
0:2c787ad08fad
|
148
|
}
|
lynxeyed_atsu |
0:2c787ad08fad
|
149
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
150
|
void ChangeFontColor(unsigned int color)
|
lynxeyed_atsu |
0:2c787ad08fad
|
151
|
{
|
lynxeyed_atsu |
0:2c787ad08fad
|
152
|
Char_Color = color;
|
lynxeyed_atsu |
0:2c787ad08fad
|
153
|
}
|
lynxeyed_atsu |
0:2c787ad08fad
|
154
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
155
|
void PutChar(unsigned char x,unsigned char y,unsigned int a)
|
lynxeyed_atsu |
0:2c787ad08fad
|
156
|
{
|
lynxeyed_atsu |
0:2c787ad08fad
|
157
|
int i,j;
|
lynxeyed_atsu |
0:2c787ad08fad
|
158
|
unsigned char Temp=0;
|
lynxeyed_atsu |
0:2c787ad08fad
|
159
|
j = 0;
|
lynxeyed_atsu |
0:2c787ad08fad
|
160
|
i = 0;
|
lynxeyed_atsu |
0:2c787ad08fad
|
161
|
//if(a < 32)a=32;
|
lynxeyed_atsu |
0:2c787ad08fad
|
162
|
for(i=0; i<X_Witch; i++)
|
lynxeyed_atsu |
0:2c787ad08fad
|
163
|
{
|
lynxeyed_atsu |
0:2c787ad08fad
|
164
|
Temp = FontLookup[a][i];
|
lynxeyed_atsu |
0:2c787ad08fad
|
165
|
for(j=Y_Witch;j!=0;j--){
|
lynxeyed_atsu |
0:2c787ad08fad
|
166
|
if((Temp & 0x80)==0x80){
|
lynxeyed_atsu |
0:2c787ad08fad
|
167
|
Draw_Dot(x+i,y+j,Char_Color);
|
lynxeyed_atsu |
0:2c787ad08fad
|
168
|
}else{
|
lynxeyed_atsu |
0:2c787ad08fad
|
169
|
Draw_Dot(x+i,y+j,BGround_Color);
|
lynxeyed_atsu |
0:2c787ad08fad
|
170
|
}
|
lynxeyed_atsu |
0:2c787ad08fad
|
171
|
Temp = Temp << 1;
|
lynxeyed_atsu |
0:2c787ad08fad
|
172
|
}
|
lynxeyed_atsu |
0:2c787ad08fad
|
173
|
}
|
lynxeyed_atsu |
0:2c787ad08fad
|
174
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
175
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
176
|
}
|
lynxeyed_atsu |
0:2c787ad08fad
|
177
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
178
|
void PutChar_ABC(unsigned char x,unsigned char y,unsigned int a)
|
lynxeyed_atsu |
0:2c787ad08fad
|
179
|
{
|
lynxeyed_atsu |
0:2c787ad08fad
|
180
|
int i,j;
|
lynxeyed_atsu |
0:2c787ad08fad
|
181
|
unsigned char Temp=0;
|
lynxeyed_atsu |
0:2c787ad08fad
|
182
|
j = 0;
|
lynxeyed_atsu |
0:2c787ad08fad
|
183
|
i = 0;
|
lynxeyed_atsu |
0:2c787ad08fad
|
184
|
for(i=0; i<5; i++)
|
lynxeyed_atsu |
0:2c787ad08fad
|
185
|
{
|
lynxeyed_atsu |
0:2c787ad08fad
|
186
|
if(a < 32)a=32;
|
lynxeyed_atsu |
0:2c787ad08fad
|
187
|
Temp = FontLookup_ABC[a-32][i];
|
lynxeyed_atsu |
0:2c787ad08fad
|
188
|
for(j=Y_Witch;j!=0;j--){
|
lynxeyed_atsu |
0:2c787ad08fad
|
189
|
if((Temp & 0x80)==0x80){
|
lynxeyed_atsu |
0:2c787ad08fad
|
190
|
Draw_Dot(x+i,y+j,Char_Color);
|
lynxeyed_atsu |
0:2c787ad08fad
|
191
|
}else{
|
lynxeyed_atsu |
0:2c787ad08fad
|
192
|
Draw_Dot(x+i,y+j,BGround_Color);
|
lynxeyed_atsu |
0:2c787ad08fad
|
193
|
}
|
lynxeyed_atsu |
0:2c787ad08fad
|
194
|
Temp = Temp << 1;
|
lynxeyed_atsu |
0:2c787ad08fad
|
195
|
}
|
lynxeyed_atsu |
0:2c787ad08fad
|
196
|
}
|
lynxeyed_atsu |
0:2c787ad08fad
|
197
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
198
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
199
|
}
|
lynxeyed_atsu |
0:2c787ad08fad
|
200
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
201
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
202
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
203
|
};
|
lynxeyed_atsu |
0:2c787ad08fad
|
204
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
205
|
|
lynxeyed_atsu |
0:2c787ad08fad
|
206
|
#endif |