(高速)ILI9341で遊ぶ(洗濯ばさみの表示(改)


(1.5Mバイト秒)ILI9341で遊ぶ(洗濯ばさみの表示(改)

目的
カラー液晶のテスト



![o_cop799.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/4de5237a-5ab9-0de5-f4a8-886788acc9d0.jpeg)




反転


```

      vg=~(databytes[jjk]);


```

プログラム


```c++


//ili9341_sentakubasami1_071

//インクルド
#include "sentakubasami2.h"

//定義
//GPIO
//GPIOの設定1　開始
//GPIO
#define DW    digitalWrite
#define TFT_RST   A1
#define TFT_RS    3
#define TFT_CS    4
#define GPIO_RESET(s)  DW(TFT_RST,s)
#define GPIO_RS(s)     DW(TFT_RS,s)
#define GPIO_CS(s)     DW(TFT_CS,s)

#define TFT_MOSI 11
#define TFT_SCK  13
#define SPI_MOSI_HIGH() DW(TFT_MOSI,HIGH)
#define SPI_MOSI_LOW()  DW(TFT_MOSI,LOW)
#define SPI_SCK_HIGH()  DW(TFT_SCK,HIGH)
#define SPI_SCK_LOW()   DW(TFT_SCK,LOW)


void GPIO_8BIT(int x)
{
  for (int bit = 0; bit < 8; bit++) {
    if (x & 0x80) {
      SPI_MOSI_HIGH();
      SPI_SCK_HIGH();
      SPI_SCK_LOW();
    } else {
      SPI_MOSI_LOW();
      SPI_SCK_HIGH();
      SPI_SCK_LOW();
    }//end if
    x <<= 1;
  }//for
} //GPIO_D0_D7


//TFT_RST   A1 PA1
//TFT_RS    3  PB3
//TFT_CS    4  PB5
//                                                 m C   R
//                                         5432109876543210
#define REG_MOSI_ON           GPIOA->ODR=0b0000000010000010;
//                                                 m C   R
//                                         5432109876543210
#define REG_CLK_ON__MOSI_1    GPIOA->ODR=0b0000000010100010;
//                                                 m C   R
//                                         5432109876543210
#define REG_MOSI_OFF          GPIOA->ODR=0b0000000000000010;
//                                                 m C   R
//                                         5432109876543210
#define REG_CLK_ON__MOSI_0    GPIOA->ODR=0b0000000000100010;
//                                                 m C   R
//                                         5432109876543210
#define REG_CLK_OFF           GPIOA->ODR=0b0000000000000010;


void GPIO_8BIT_A(int s)
{
  //1
  if (s & 0x80) {
    REG_MOSI_ON;
    REG_CLK_ON__MOSI_1;
    REG_CLK_OFF;
  } else {
    REG_MOSI_OFF;
    REG_CLK_ON__MOSI_0;
    REG_CLK_OFF;
  }//end if
  //2
  if (s & 0x40) {
    REG_MOSI_ON;
    REG_CLK_ON__MOSI_1;
    REG_CLK_OFF;
  } else {
    REG_MOSI_OFF;
    REG_CLK_ON__MOSI_0;
    REG_CLK_OFF;
  }//end if
  //3
  if (s & 0x20) {
    REG_MOSI_ON;
    REG_CLK_ON__MOSI_1;
    REG_CLK_OFF;
  } else {
    REG_MOSI_OFF;
    REG_CLK_ON__MOSI_0;
    REG_CLK_OFF;
  }//end if
  //4
  if (s & 0x10) {
    REG_MOSI_ON;
    REG_CLK_ON__MOSI_1;
    REG_CLK_OFF;
  } else {
    REG_MOSI_OFF;
    REG_CLK_ON__MOSI_0;
    REG_CLK_OFF;
  }//end if
  //5
  if (s & 0x08) {
    REG_MOSI_ON;
    REG_CLK_ON__MOSI_1;
    REG_CLK_OFF;
  } else {
    REG_MOSI_OFF;
    REG_CLK_ON__MOSI_0;
    REG_CLK_OFF;
  }//end if
  //6
  if (s & 0x04) {
    REG_MOSI_ON;
    REG_CLK_ON__MOSI_1;
    REG_CLK_OFF;
  } else {
    REG_MOSI_OFF;
    REG_CLK_ON__MOSI_0;
    REG_CLK_OFF;
  }//end if
  //7
  if (s & 0x02) {
    REG_MOSI_ON;
    REG_CLK_ON__MOSI_1;
    REG_CLK_OFF;
  } else {
    REG_MOSI_OFF;
    REG_CLK_ON__MOSI_0;
    REG_CLK_OFF;
  }//end if
  //8
  if (s & 0x01) {
    REG_MOSI_ON;
    REG_CLK_ON__MOSI_1;
    REG_CLK_OFF;
  } else {
    REG_MOSI_OFF;
    REG_CLK_ON__MOSI_0;
    REG_CLK_OFF;
  }//end if

}//SPI_WRITE8


//ライト
void LCD_Write_CMD(int a)
{
  GPIO_CS(0);//CS=0; 12
  GPIO_RS(0); //A0=0; 9
  GPIO_8BIT(a);//P1=a; data SPI SPI
  GPIO_CS(1);//CS=1; 12
} //LCD_Write_CMD


void LCD_Write_Data(int a)
{
  GPIO_CS(0);//CS=0; 12
  GPIO_RS(1); //A0=1; 9
  GPIO_8BIT(a);//P1=a; data SPI SPI
  GPIO_CS(1);//CS=1; 12
} //LCD_Write_Data


//TFT_RST   A1 PA1
//TFT_RS    3  PB3
//TFT_CS    4  PB5
//                                         C R
//                               5432109876543210
#define REG_CS_ON   GPIOB->ODR=0b0000000000101000
//                                         C R
//                               5432109876543210
#define REG_CS_OFF  GPIOB->ODR=0b0000000000001000


//画面の書き込み
void P_display(void)
{
  //画面の書き込み開始
  LCD_Write_CMD(0x2C); //memory write
  GPIO_RS(1);//RS=0; 12
  delay(2);

  unsigned int jjk=0;
  unsigned char vg=0;
  unsigned char hp[8]={0x80,0x40,0x20,0x10,  0x08,0x04,0x02,0x01};
  for (int i = 0; i < 320; i++) {
    for (int j = 0; j < (240/8); j++) {
      vg=~(databytes[jjk]);
      for(int k=0;k < 8;k++){
        if ( ( vg & hp[k]) == 0 ) {

          REG_CS_OFF;
          GPIO_8BIT_A(0x00);
          REG_CS_ON;

          REG_CS_OFF;
          GPIO_8BIT_A(0x00);
          REG_CS_ON;
          
          REG_CS_OFF;
          GPIO_8BIT_A(0x00);
          REG_CS_ON;
          
        } else { //        12345678

          REG_CS_OFF;
          GPIO_8BIT_A(0xff);
          REG_CS_ON;

          REG_CS_OFF;
          GPIO_8BIT_A(0xff);
          REG_CS_ON;

          REG_CS_OFF;
          GPIO_8BIT_A(0xff);
          REG_CS_ON;

        }//enf if
      }//k
      jjk++;
    } //j
  }//i

} //P_display


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

  GPIO_RESET(1);//LCD_RESET=1;
  delay(1); //Delay 1ms

  GPIO_RESET(0);//LCD_RESET=0;
  delay(1); //Delay 1ms

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

} //TXDT144TF_ST7735S_Init


//初期化
void setup() {

  //ポートのモード設定　アウトプットモード
  pinMode(TFT_CS, OUTPUT);
  pinMode(TFT_RST, OUTPUT);
  pinMode(TFT_RS, OUTPUT);

  pinMode(TFT_MOSI, OUTPUT);
  pinMode(TFT_SCK , OUTPUT);

  //ポートの初期化
  GPIO_CS(1);//CS=1
  GPIO_RESET(1);//RESET=1
  GPIO_RS(0);//RS=0

  delay(500); //0.5秒待つ

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

  P_display();

} //setup


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


```

sentakubasami2.h


https://qiita.com/caa45040/items/a4199dd52cb4e84ae226