ST7789にSTM32G031で、せんたくばさみを表示


x STM32G031 STM32G031J6M6


ST7789にSTM32G031で、せんたくばさみを表示





目的
液晶のテスト


1 SPI CLK
2 VDD
3 GND
4 CS

8 SWD CLK
7 SWD DATA
6 SPI DATA(MOSI)
5 RS(DC)

x LCDのリセットは、10KΩぐらいを接続して3.3V電源へ
　起動不良の場合は、電源を入れ直すか、
　ちゃんとしたリセット回路をくんでね


![o_cop800.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/03c976c2-d9b0-237f-c046-761cde1c3d45.jpeg)


```c++



//ili9341_sentakubasami1_031

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

//定義
//GPIO
//GPIOの設定1　開始
//GPIO
#define DW    digitalWrite
//#define TFT_RST   A1
#define TFT_RS    PA11
#define TFT_CS    PA0
//#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 PA12
#define TFT_SCK  PB7
#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 ) {

          GPIO_CS(0);//REG_CS_OFF;
          GPIO_8BIT(0x00);
          GPIO_CS(1);//REG_CS_ON;

          GPIO_CS(0);//REG_CS_OFF;
          GPIO_8BIT(0x00);
          GPIO_CS(1);//REG_CS_ON;
          
          GPIO_CS(0);//REG_CS_OFF;
          GPIO_8BIT(0x00);
          GPIO_CS(1);//REG_CS_ON;
          
        } else { //        12345678

          GPIO_CS(0);//REG_CS_OFF;
          GPIO_8BIT(0xff);
          GPIO_CS(1);//REG_CS_ON;

          GPIO_CS(0);//REG_CS_OFF;
          GPIO_8BIT(0xff);
          GPIO_CS(1);//REG_CS_ON;

          GPIO_CS(0);//REG_CS_OFF;
          GPIO_8BIT(0xff);
          GPIO_CS(1);//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() {

  delay(3000); //don not delete

  //ポートのモード設定　アウトプットモード
  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



```

画像データ

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