using System;
using System.Threading; // 追加
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware; // 追加、参照設定にも追加
using GHI.OSHW.Hardware; // 追加、参照設定にも追加
using GHI.Hardware.FEZCerb; // 追加、参照設定にも追加
using BoeBotLib;
using Pin = Microsoft.SPOT.Hardware.Cpu.Pin;
class AQM1248A
{
DigitalOut _cs, _rs;
SPI spi;
byte[] buffer = new byte[1];
public AQM1248A(Pin cs, Pin rs) // SPI1固定
{
SPI.Configuration Config =
new SPI.Configuration(Cpu.Pin.GPIO_Pin1,
false, 0, 0, false, true, 1000, SPI.SPI_module.SPI1);
spi = new SPI(Config);
_rs = new DigitalOut(rs);
_cs = new DigitalOut(cs);
init();
}
void init()
{
writeCommand(0xAE); // Display Off
writeCommand(0xA0); // ADC normal
writeCommand(0xC8); // Common output = reverse/normal 0xC0
writeCommand(0xA3); // bias = 1/7
// 内部レギュレータを順番にONする
writeCommand(0x2C); // power control 1
CPU.wait_ms(2);
writeCommand(0x2E); // power control 2
CPU.wait_ms(2);
writeCommand(0x2F); // power control 3
// コントラスト設定
writeCommand(0x23); // Vo voltage resistor retio set
writeCommand(0x81); // Electric volume mode set
writeCommand(0x1C); // Electric volume value set
// 表示設定
writeCommand(0xA4); // display all point = normal(全点灯しない)
writeCommand(0x40); // display start line = 0
writeCommand(0xA6); // Display normal/reverse = normal(白黒反転しない)
writeCommand(0xAF); // Display ON
}
void writeCommand(byte cmd)
{
buffer[0] = cmd;
_cs <<= 0;
_rs <<= 0;
spi.Write(buffer);
_cs <<== 1;
}
public void diplayOn(bool onoff)
{// on:1 off:0
writeCommand((byte)(onoff ? 0xAF : 0xAE));
}
// Set the display RAM display start line
public void startLineSet(byte address)
{
writeCommand((byte)(0x40 | address));
}
// Set the display RAM page address
public void pageAddressSet(byte address)
{
writeCommand((byte)(0xB0 | address&7));
}
public void colAddressSet(byte address)
{
byte upper = (byte)(address >> 4);
byte lower = (byte)(address & 0x0f);
writeCommand((byte)(0x10 | upper));
writeCommand((byte)(0x00 | lower));
}
public void writeData(byte data)
{
buffer[0] = data;
_cs <<== 0;
_rs <<== 1;
spi.Write(buffer);
_cs <<== 1;
}
public void clear()
{
for(int i=0; i<=8; i++)
{
pageAddressSet((byte)i);
//writeCommand(0xB0 | i);
colAddressSet(0);
//writeCommand(0x10);
//writeCommand(0x00);
for(int j=0; j<=128; j++)
writeData(0);
}
}
}
|
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
|