秋月のst7789(spi)で遊ぶ1(なんか出た


x カラー液晶は、 ST7789 ST7789V2 ATM0130B3 の事


目的
秋月で売っているATM0130B3で遊ぶ
m5stickc plus に st7789 は、使われているらしい?

●結果

![o_cop701.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/b7a56ada-d2b9-eb38-b6c2-352c8c7185e6.jpeg)

![o_cop702.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/8ae73c37-b4b6-f187-be7d-93b111b99c95.jpeg)

●秋月にあるプログラムの初期化シーケンス

![o_cop703.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/8818697f-5230-57b2-68c6-43ceb3c8801a.jpeg)


![o_cop704.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/d8f27d7d-c6af-0c23-6cbb-e7b574a45741.jpeg)

![o_cop706.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/cf450589-1ac2-dfb0-711d-7714fcf3c1dc.jpeg)

![o_cop713.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/35476a52-6747-542f-88df-9aaff57498c0.jpeg)


●プログラム


```c++:main.cpp



//GPIO_st7735_SPI_TEST1_UNO_1

// 'sentakubasami', 128x160px
//static const unsigned char PROGMEM databytes[(128/8)*160];


//GPIO
#define GPIO_D13(s) digitalWrite(13,s)
#define GPIO_D12(s) digitalWrite(12,s) //未使用
#define GPIO_D11(s) digitalWrite(11,s)
#define GPIO_D10(s) digitalWrite(10,s)
#define GPIO_D9(s)  digitalWrite(9,s)
#define GPIO_D8(s)  digitalWrite(8,s)


void GPIO_D0_D7(int s)
{
      digitalWrite(13,0);
  digitalWrite(11, (s >> 7) & 0x01);
      digitalWrite(13,0);
      digitalWrite(13,1);
      digitalWrite(13,0);
  digitalWrite(11, (s >> 6) & 0x01);
      digitalWrite(13,0);
      digitalWrite(13,1);
      digitalWrite(13,0);
  digitalWrite(11, (s >> 5) & 0x01);
      digitalWrite(13,0);
      digitalWrite(13,1);
      digitalWrite(13,0);
  digitalWrite(11, (s >> 4) & 0x01);
      digitalWrite(13,0);
      digitalWrite(13,1);
      digitalWrite(13,0);
  digitalWrite(11, (s >> 3) & 0x01);
      digitalWrite(13,0);
      digitalWrite(13,1);
      digitalWrite(13,0);
  digitalWrite(11, (s >> 2) & 0x01);
      digitalWrite(13,0);
      digitalWrite(13,1);
      digitalWrite(13,0);
  digitalWrite(11, (s >> 1) & 0x01);
      digitalWrite(13,0);
      digitalWrite(13,1);
      digitalWrite(13,0);
  digitalWrite(11, s & 0x01);
      digitalWrite(13,0);
      digitalWrite(13,1);
      digitalWrite(13,0);
} //GPIO_D0_D7


//ライト

void LCD_Write_CMD(int a)
{

  GPIO_D10(0);//CS=0; 12
  GPIO_D8(0); //A0=0; 9
      GPIO_D0_D7(a);//P1=a; data SPI SPI
  GPIO_D10(1);//CS=1; 12

} //LCD_Write_CMD

void LCD_Write_Data(int a)
{

  GPIO_D10(0);//CS=0; 12
  GPIO_D8(1); //A0=1; 9
      GPIO_D0_D7(a);//P1=a; data SPI SPI
  GPIO_D10(1);//CS=1; 12


} //LCD_Write_Data


//画面の書き込み
///void output_pict(unsigned char * pi)
///{
///  //画面の書き込み開始
///  LCD_Write_CMD(0x2C); //memory write
///
///  GPIO_D12(0);//CS=0; 12
///  GPIO_D9(1);//A0=1; 9
///  GPIO_D0_D7(0xff);//P1=a; data
///
///  int jjk=0,vg=0;
///  int hp[8]={0x80,0x40,0x20,0x10,  0x08,0x04,0x02,0x01};
///  for (int i = 0; i < 160; i++) {
///    for (int j = 0; j < (128/8); j++) {
///
///      vg=pi[jjk];
///      for(int k=0;k < 8;k++){
///        if ( ( vg & hp[k]) == 0 ) {GPIO_D0_D7(0x00);} else {GPIO_D0_D7(0xff);}
///
///        GPIO_D10(0);//WRB=0; 10
///        GPIO_D10(1);//WRB=1; 10
///
///        GPIO_D10(0);//WRB=0; 10
///        GPIO_D10(1);//WRB=1; 10
///      }//k
///      jjk++;
///
///    } //j
///  }//i
///
///  GPIO_D12(1);//CS=1;  12
///
///} //output_pict


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

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

  GPIO_D8(1);//LCD_RESET=1;

  delay(1); //Delay 1ms

  GPIO_D8(0);//LCD_RESET=0;

  delay(1); //Delay 1ms

  GPIO_D8(1);//LCD_RESET=1;

  delay(120); //Delay 120ms

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

  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);

} //TXDT144TF_ST7735S_Init


//初期化
void setup() {

  //ポートのモード設定　アウトプットモード
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT); //未使用
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);


  //ポートの初期化
  GPIO_D13(1);//SPI_DATA=1
  GPIO_D11(0);//SPI_CLK=1

  GPIO_D10(1);//CS=1
  GPIO_D9(1);//RESET=1
  GPIO_D8(0);//RS=0



  delay(500); //0.5秒待つ

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

  //画面の書き込み開始
  LCD_Write_CMD(0x2C); //memory write
    delay(1);
  for(int ii=0;ii<(128*8*2);ii++){
     LCD_Write_Data(0xff);
  }

  //洗濯ばさみの絵の表示
  //output_pict( (unsigned char *)databytes );

} //setup


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

//  digitalWrite(PB7, HIGH);
//  delay(200); //0.2秒待つ

//  digitalWrite(PB7, LOW);
//  delay(200); //0.2秒待つ

} //loop



```