StampS3とST7735S(Parallel)でテスト表示する。(ATM0177B5)


参考　ST7735(パラレル)で遊ぶ まとめ(リンク集)

↓クリック↓

https://qiita.com/caa45040/items/4a66c0a0c9e78b73d043

X 過去ログを見よ!!


目的
パラレル8ビットのカラー液晶で遊ぶ

結果

![o_cop588.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/0925a41f-5cc5-efe1-171a-a26c9d4e5b17.jpeg)

![o_coq056.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/e16852f3-9265-0fdc-1280-f15c21b596fc.jpeg)

![o_coq059.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/23026d7b-c69f-d869-8c43-db8609c12e10.jpeg)


-----------------------------------------


配線


1 
2 
3 
4 
5 
6 
7 
8 
9 GND   ->GND
10 LEDK1 ->GND

11 LEDA  ->330Ω->3.3V
12 LEDK2
13 VCC  ->3.3V
14 ID
15 IMO ->GND
16 CS ->GND
17 DB15
18 DB14
19 DB13
20 DB12

21 DB11
22 DB10
23 DB9
24 DB8
25 DB7 ->12
26 DB6 ->11
27 DB5 ->10
28 DB4 ->9
29 DB3 ->8
30 DB2 ->7

31 DB1 ->6
32 DB0 ->5
33 RD ->4
34 WR ->3
35 RS ->2
36 RESET ->1
37 IOVCC ->3.3v
38 NC
39 NC
40 NC

41 GND
42 
43 
44 
45 
46 
47 
48 
49 
50 



-----------------------------------------


プログラム

```c++


//GPIO_ST7735_TEST1_M5S3_1


//インクルド
#include <Arduino.h>


//定義
//GPIO
#define GPIO1(s) digitalWrite(1,s)  //RESET
#define GPIO2(s) digitalWrite(2,s)  //A0
#define GPIO3(s) digitalWrite(3,s)  //WR
#define GPIO4(s) digitalWrite(4,s)  //RD


//パラレルポートにデータをセットする。
void GPIO_8BIT(int s)
{
  digitalWrite(12, (s >> 7) & 0x01);
  digitalWrite(11, (s >> 6) & 0x01);
  digitalWrite(10, (s >> 5) & 0x01);
  digitalWrite( 9, (s >> 4) & 0x01);
  digitalWrite( 8, (s >> 3) & 0x01);
  digitalWrite( 7, (s >> 2) & 0x01);
  digitalWrite( 6, (s >> 1) & 0x01);
  digitalWrite( 5,  s       & 0x01);
} //GPIO_8BIT

//コマンドの書き込み
void LCD_Write_CMD(int a)
{
  GPIO2(0); //A0=0;
  GPIO_8BIT(a);//P1=a; data
  GPIO3(0);//WRB=0;
  GPIO3(1);//WRB=1;
} //LCD_Write_CMD


//データ書き込み
void LCD_Write_Data(int a)
{
  GPIO2(1);//A0=1;
  GPIO_8BIT(a);//P1=a; data
  GPIO3(0);//WRB=0;
  GPIO3(1);//WRB=1;
} //LCD_Write_Data

//液晶の初期化処理
void ATM0177B5_ST7735S_Init(void)
{

  //----------  ST7735S Reset Sequence  --------//

  GPIO1(1);//LCD_RESET=1;

  delay(1); //Delay 1ms

  GPIO1(0);//LCD_RESET=0;

  delay(1); //Delay 1ms

  GPIO1(1);//LCD_RESET=1;

  delay(120); //Delay 120ms

  //----------  ST7735S Reset Sequence  --------//


  LCD_Write_CMD(0x01);//SOFTWARE RESET
  delay(50);

  LCD_Write_CMD(0x11);//SLEEP OUT
  delay(200);

  LCD_Write_CMD(0x29);//display on
  delay(100);

  LCD_Write_CMD(0x3a);//Interface pixel format
  LCD_Write_Data(0x05);//16bit mode
  delay(100);

  LCD_Write_CMD(0x36);//RGB-RGR format
  LCD_Write_Data(0x08);//RGB mode
  delay(100);


  //画面の書き込み開始
  LCD_Write_CMD(0x2C); //memory write

  for (int i = 0; i < 128 * 10; i++) {
    LCD_Write_Data(0xff);
    LCD_Write_Data(0xff);
  }

  //RGB
  for (int i = 0; i < 128 * 10; i++) {
    LCD_Write_Data(0b11111000); //red
    LCD_Write_Data(0b00000000);
  }

} //ATM0177B5_ST7735S_Init


//初期化
void setup() {

  //ポートのモード設定
  //アウトプットモード
  pinMode(1, OUTPUT); //REST
  pinMode(2, OUTPUT); //RS
  pinMode(3, OUTPUT); //WR
  pinMode(4, OUTPUT); //RD

  pinMode(5, OUTPUT); //DB0
  pinMode(6, OUTPUT); //DB1
  pinMode(7, OUTPUT); //DB2
  pinMode(8, OUTPUT); //DB3

  pinMode( 9, OUTPUT); //DB4
  pinMode(10, OUTPUT); //DB5
  pinMode(11, OUTPUT); //DB6
  pinMode(12, OUTPUT); //DB7

  //ポートの初期化
  GPIO4(1);//RD=1
  GPIO3(0);//WR=0
  GPIO2(0);//RS=0
  GPIO1(1);//RESET=1

  delay(500); //0.5秒待つ

  //液晶の初期化処理
  ATM0177B5_ST7735S_Init();

} //setup


//メインループ
void loop() {

/*
  GPIO1(0);
  GPIO2(0);
  GPIO3(0);
  GPIO4(0);delay(1000);

  GPIO1(1);delay(1000);//RESET=1
  GPIO1(0);delay(1000);//RESET=1

  GPIO2(1);delay(1000);//RS=0
  GPIO2(0);delay(1000);//RS=0

  GPIO3(1);delay(1000);//WR=0
  GPIO3(0);delay(1000);//WR=0

  GPIO4(1);delay(1000);//RD=1
  GPIO4(0);delay(1000);//RD=1


  GPIO_8BIT(0x01); delay(1000);
  GPIO_8BIT(0x02); delay(1000);
  GPIO_8BIT(0x04); delay(1000);
  GPIO_8BIT(0x08); delay(1000);

  GPIO_8BIT(0x10); delay(1000);
  GPIO_8BIT(0x20); delay(1000);
  GPIO_8BIT(0x40); delay(1000);
  GPIO_8BIT(0x80); delay(1000);

*/

  while (1) {
    neopixelWrite(21, 0, 0, 0);
    delay(1000); //ダミー

    neopixelWrite(21, 64, 0, 0);
    delay(100); //ダミー
  }//while

} //loop


```