-
-
Save moribudenhome/48e87d0b90e39e5698bde1d5b5f9267d to your computer and use it in GitHub Desktop.
秋月LCD表示テスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <wiringPi.h> | |
#include <string.h> | |
#include <stdlib.h> | |
// データ線以外のポート定義 | |
// データ線はdigitalWriteByteコマンドを使いたいので | |
// GPIOの0~7番に接続する。 | |
// ※ R/WはL時書き込みモードなので接続しない。 | |
// もし万一読み込みモードに設定してしまった場合 | |
// パイが焼けてしまうので絶対に繋がない。 | |
#define LCD_RS 13 // データ・コマンド切り替え信号 | |
#define LCD_EN 12 // イネーブル信号 | |
#define LCD_C1 10 // コントローラ切り替え信号(右半分) | |
#define LCD_C2 11 // コントローラ切り替え信号(左半分) | |
#define LCD_RE 14 // リセット信号 | |
#define WIDTH 5 | |
#define HEIGHT 16 | |
int g_frameCnt = 0; | |
// LCD制御命令 | |
// CntSel=コントローラセレクト | |
// 1 =CS1 2 =CS2 | |
// rs=データ・コマンド切り替え | |
// 0 =コマンド 1 =データ | |
// Data = 8bit制御データ | |
int LCD_SET(int CntSel, int rs, int Data) { | |
int chip_sel[2] = { LCD_C1,LCD_C2 }; | |
digitalWrite(chip_sel[0], 0); digitalWrite(chip_sel[1], 0); | |
digitalWriteByte(0); | |
digitalWrite(LCD_EN, 0); delayMicroseconds(0.45); | |
digitalWrite(LCD_RS, rs); delayMicroseconds(4); | |
digitalWrite(chip_sel[CntSel - 1], 1); | |
digitalWrite(LCD_EN, 1); delayMicroseconds(0.45); | |
digitalWriteByte(Data); | |
delayMicroseconds(4); | |
digitalWrite(LCD_EN, 0); | |
digitalWrite(LCD_RS, 0); | |
digitalWriteByte(0); | |
digitalWrite(chip_sel[0], 0); digitalWrite(chip_sel[1], 0); | |
} | |
unsigned char GetData(int x, int y, unsigned char* buf) | |
{ | |
static const int blinkTable[8][7] = | |
{ | |
{ 0, 0, 0, 0, 0, 0, 0, }, | |
{ 1, 0, 0, 0, 0, 0, 0, }, | |
{ 1, 0, 0, 1, 0, 0, 0, }, | |
{ 1, 0, 0, 1, 0, 1, 0, }, | |
{ 1, 1, 0, 1, 0, 1, 0, }, | |
{ 1, 1, 0, 1, 1, 1, 0, }, | |
{ 1, 1, 1, 1, 1, 1, 0, }, | |
{ 1, 1, 1, 1, 1, 1, 1, }, | |
}; | |
if (WIDTH <= x) { return 0x00; } | |
if (HEIGHT <= y) { return 0x00; } | |
return blinkTable[buf[(y * WIDTH) + x]][g_frameCnt % 7]; | |
} | |
int main() { | |
if (wiringPiSetup() < 0) printf("GPIO Err..."); | |
int i = 0; | |
//データbit用ポートを出力に設定 | |
for (i = 0; i<8; i++) { pinMode(i, OUTPUT); delay(2); } | |
// データ以外のポートを出力に設定 | |
pinMode(LCD_RS, OUTPUT); | |
pinMode(LCD_EN, OUTPUT); | |
pinMode(LCD_C1, OUTPUT); | |
pinMode(LCD_C2, OUTPUT); | |
pinMode(LCD_RE, OUTPUT); | |
digitalWrite(LCD_RE, 1); | |
delay(50); | |
digitalWrite(LCD_RE, 0); | |
delay(50); | |
digitalWrite(LCD_RE, 1); | |
// 液晶初期化 | |
LCD_SET(1, 0, 0xC0); LCD_SET(1, 0, 0x3F); | |
LCD_SET(2, 0, 0xC0); LCD_SET(2, 0, 0x3F); | |
g_frameCnt = 0; | |
unsigned char buf[WIDTH * HEIGHT] = | |
{ | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, | |
2, 2, 2, 2, 2, | |
2, 2, 2, 2, 2, | |
3, 3, 3, 3, 3, | |
3, 3, 3, 3, 3, | |
4, 4, 4, 4, 4, | |
4, 4, 4, 4, 4, | |
5, 5, 5, 5, 5, | |
5, 5, 5, 5, 5, | |
6, 6, 6, 6, 6, | |
6, 6, 6, 6, 6, | |
7, 7, 7, 7, 7, | |
7, 7, 7, 7, 7, | |
}; | |
while (1) { | |
for (int i = 0; i < 128; i++) { | |
for (int j = 0; j <8; j++) { | |
LCD_SET(1 + (i >= 64), 0, 0x40 + (i % 64)); | |
LCD_SET(1 + (i >= 64), 0, 0xB8 + j); | |
unsigned char d = | |
GetData(i, j * 8 + 7, buf) << 7 | | |
GetData(i, j * 8 + 6, buf) << 6 | | |
GetData(i, j * 8 + 5, buf) << 5 | | |
GetData(i, j * 8 + 4, buf) << 4 | | |
GetData(i, j * 8 + 3, buf) << 3 | | |
GetData(i, j * 8 + 2, buf) << 2 | | |
GetData(i, j * 8 + 1, buf) << 1 | | |
GetData(i, j * 8 + 0, buf) << 0; | |
LCD_SET(1 + (i >= 64), 1, d); | |
} | |
} | |
g_frameCnt++; | |
} | |
delay(50); | |
digitalWrite(LCD_RE, 1); | |
delay(50); | |
digitalWrite(LCD_RE, 0); | |
delay(50); | |
digitalWrite(LCD_RE, 1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment