aitendoのst7735(spi)で遊ぶ1(なんか出た


aitendoのst7735(spi)で遊ぶ(なんか出た


目的
特に必要じゃないけど
SPIの方も高速化して遊ぶ
将来てきには、ATM0130B3　(ST7789V2) の
ドライバーを作る

●装置



https://www.aitendo.com/product/3858




●接続

液晶モジュール側/びんぼうでいいの側
CS/10
RST/9
A0/8
SCK/13
SDA/11
GND/GND
VCC/3.3V
VLED→10Ω/5V


●結果

![o_cop695.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/ee71ac53-3f6e-1857-3416-f23ed1312baa.jpeg)

![o_cop696.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/820de524-099f-9311-fbbb-e536a86d3aff.jpeg)


●プログラム





```c++



//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





```