ST7735(パラレル)で遊ぶ10(失敗2)(1か月から3か月の長期記事)ATM0177B5


! 失敗 !

イメージ

![o_cop530.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/d63e122b-1e1d-5216-a32f-c4cac1c3d0e8.jpeg)




```c++





//GPIO_st7735_writ_testT1_767_1

#define DW digitalWrite 



void GPIO_D13(int s)
{

  digitalWrite(13,s);
  delayMicroseconds(3);

} //GPIO_D13

void GPIO_D12(int s)
{

  digitalWrite(12,s);
  delayMicroseconds(3);


} //GPIO_D12


void GPIO_D11(int s)
{

  digitalWrite(11,s);
  delayMicroseconds(3);


} //GPIO_D11


void GPIO_D10(int s)
{

  digitalWrite(10,s);
  delayMicroseconds(3);


} //GPIO_D10


void GPIO_D9(int s)
{

  digitalWrite(9,s);
  delayMicroseconds(3);

} //GPIO_D9


void GPIO_D8(int s)
{

  digitalWrite(8,s);
  delayMicroseconds(3);

} //GPIO_D8




void GPIO_D0_D7(int s)
{

  digitalWrite(7, (s>>7) & 0x01);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(6, (s>>6) & 0x01);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(5, (s>>5) & 0x01);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(4, (s>>4) & 0x01);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(3, (s>>3) & 0x01);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(2, (s>>2) & 0x01);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(1, (s>>1) & 0x01);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(0, s & 0x01);       // turn the LED on (HIGH is the voltage level)
  
  delayMicroseconds(3);


} //GPIO_D0_D7


void GPIO_D8_D13_cls()
{

  digitalWrite(13,0);
  digitalWrite(12,0);
  digitalWrite(11,0);

  digitalWrite(10,0);
  digitalWrite(9,0);
  digitalWrite(8,0);

} //GPIO_D8_D13_cls()

//ライト

void WriteCOM(int a)
{
  GPIO_D12(0);//CS=0; 12
  GPIO_D9(0); //A0=0; 9
  GPIO_D0_D7(a);//P1=a; data
  GPIO_D10(0);//WRB=0; 10

  //delay(3000);//delay20us();
  delayMicroseconds(20);

  GPIO_D10(1);//WRB=1; 10
  GPIO_D12(1);//CS=1; 12
} //WriteCOM



void WriteDAT(int a)
{
  GPIO_D12(0);//CS=0; 12
  GPIO_D9(1);//A0=1; 9
  GPIO_D0_D7(a);//P1=a; data
  GPIO_D10(0);//WRB=0; 10

  //delay(3000);//delay20us();
  delayMicroseconds(20);

  GPIO_D10(1);//WRB=1; 10
  GPIO_D12(1);//CS=1;  12
} //WriteDAT



void LCD_Write_CMD(int s){

//startコマンドコマンドコマンドコマンドコマンドコマンド

  digitalWrite(PB7, HIGH);
  //delay(20);

  //データの書き込み
  //GPIO_D0_D7(0); //データの初期化
  //delay(1000);

  WriteCOM(s);
  //delay(1000);

  digitalWrite(PB7, LOW);
  //delay(20);

//endコマンドコマンドコマンドコマンドコマンドコマンド


} //LCD_Write_CMD



void LCD_Write_Data(int s) {

//startデータデータデータデータデータデータデータデータ

  digitalWrite(PB7, HIGH);
  //delay(20);

  //データの書き込み
  //GPIO_D0_D7(0); //データの初期化
  //delay(1000);

  WriteDAT(s);
  //delay(1000);

  digitalWrite(PB7, LOW);
  //delay(20);

//endデータデータデータデータデータデータデータデータ


} //LCD_Write_Data





void Delayms(int a) {

 delay(a);

}






void TXDT144TF_ST7735S_Init(void)

{

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

GPIO_D8(1);//LCD_RESET=1;

Delayms (1); //Delay 1ms

GPIO_D8(0);//LCD_RESET=0;

Delayms (1); //Delay 1ms

GPIO_D8(1);//LCD_RESET=1;

Delayms (120); //Delay 120ms


//jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj

//LCD_Write_CMD
//LCD_Write_Data

    LCD_Write_CMD(0x01);
    delay(50);

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

    LCD_Write_CMD(0xFF);
    LCD_Write_Data(0x40);
    LCD_Write_Data(0x03);
    LCD_Write_Data(0x1A);

    LCD_Write_CMD(0xd9);
    LCD_Write_Data(0x60);
    LCD_Write_CMD(0xc7);
    LCD_Write_Data(0x90);
    delay(200);

    LCD_Write_CMD(0xB1);
    LCD_Write_Data(0x04);
    LCD_Write_Data(0x25);
    LCD_Write_Data(0x18);

    LCD_Write_CMD(0xB2);
    LCD_Write_Data(0x04);
    LCD_Write_Data(0x25);
    LCD_Write_Data(0x18);

    LCD_Write_CMD(0xB3);
    LCD_Write_Data(0x04);
    LCD_Write_Data(0x25);
    LCD_Write_Data(0x18);
    LCD_Write_Data(0x04);
    LCD_Write_Data(0x25);
    LCD_Write_Data(0x18);

    LCD_Write_CMD(0xB4);
    LCD_Write_Data(0x03);

    LCD_Write_CMD(0xB6);
    LCD_Write_Data(0x15);
    LCD_Write_Data(0x02);

    LCD_Write_CMD(0xC0);// POWER CONTROL 1 GVDD&VCI1
    LCD_Write_Data(0x02);
    LCD_Write_Data(0x70);

    LCD_Write_CMD(0xC1);// POWER CONTROL 2 GVDD&VCI1
    LCD_Write_Data(0x07);

    LCD_Write_CMD(0xC2);// POWER CONTROL 3 GVDD&VCI1
    LCD_Write_Data(0x01);
    LCD_Write_Data(0x01);

    LCD_Write_CMD(0xC3);// POWER CONTROL 4 GVDD&VCI1
    LCD_Write_Data(0x02);
    LCD_Write_Data(0x07);

    LCD_Write_CMD(0xC4);// POWER CONTROL 5 GVDD&VCI1
    LCD_Write_Data(0x02);
    LCD_Write_Data(0x04);

    LCD_Write_CMD(0xFC);// POWER CONTROL 6 GVDD&VCI1
    LCD_Write_Data(0x11);
    LCD_Write_Data(0x17);

    LCD_Write_CMD(0xC5);//VCOMH&VCOML
    LCD_Write_Data(0x3c);
    LCD_Write_Data(0x4f);

    LCD_Write_CMD(0x36);//MV,MX,MY,RGB
    LCD_Write_Data(0xC8);


    LCD_Write_CMD(0x3a);//GAMMA SET BY REGISTER
    LCD_Write_Data(0x05);

//***********************GAMMA*************************
    LCD_Write_CMD(0xE0);
    LCD_Write_Data(0x06);
    LCD_Write_Data(0x0E);
    LCD_Write_Data(0x05);
    LCD_Write_Data(0x20);
    LCD_Write_Data(0x27);
    LCD_Write_Data(0x23);
    LCD_Write_Data(0x1C);
    LCD_Write_Data(0x21);
    LCD_Write_Data(0x20);
    LCD_Write_Data(0x1C);
    LCD_Write_Data(0x26);
    LCD_Write_Data(0x2F);
    LCD_Write_Data(0x00);
    LCD_Write_Data(0x03);
    LCD_Write_Data(0x00);
    LCD_Write_Data(0x24);

    LCD_Write_CMD(0xE1);
    LCD_Write_Data(0x06);
    LCD_Write_Data(0x10);
    LCD_Write_Data(0x05);
    LCD_Write_Data(0x21);
    LCD_Write_Data(0x27);
    LCD_Write_Data(0x22);
    LCD_Write_Data(0x1C);
    LCD_Write_Data(0x21);
    LCD_Write_Data(0x1F);
    LCD_Write_Data(0x1D);
    LCD_Write_Data(0x27);
    LCD_Write_Data(0x2F);
    LCD_Write_Data(0x05);
    LCD_Write_Data(0x03);
    LCD_Write_Data(0x00);
    LCD_Write_Data(0x3F);

//***************************RAM ADDRESS*******************
    LCD_Write_CMD(0x2A);
    LCD_Write_Data(0x00);
    LCD_Write_Data(0x02);
    LCD_Write_Data(0x00);
    LCD_Write_Data(0x81);

    LCD_Write_CMD(0x2B);
    LCD_Write_Data(0x00);
    LCD_Write_Data(0x03);
    LCD_Write_Data(0x00);
    LCD_Write_Data(0x82);

    LCD_Write_CMD(0x29);
    delay(100);

    LCD_Write_CMD(0x2C);


    for (int i=0;i<128;i++) {
        for (int j=0;j<128;j++) {
            LCD_Write_Data(0xf8);
            LCD_Write_Data(0x00);  //display red
        } //j
    }//i





//ffffffffffffffffffffffffffffffffffffffff
//fffffffffffffffffffffffffffffffffffffff
//ffffffffffffffffffffffffffffffffffffffffff


}



void ST7735S_Enter_Sleep(void)

{

LCD_Write_CMD(0x10); //Sleep in

Delayms (120); //Delay 120ms

}

void ST7735S_Exit_Sleep(void)

{

LCD_Write_CMD(0x11); //Sleep out

Delayms (120); //Delay 120ms

}




void setup() {


  // initialize digital pin LED_BUILTIN as an output.
  pinMode(PB7, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);


  // initialize digital pin LED_BUILTIN as an output.
  //pinMode(PB7, OUTPUT);
  pinMode(0, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);


//test

//  GPIO_D13(0);
//  GPIO_D12(0);
//  GPIO_D11(0);
//  GPIO_D10(0);
//  GPIO_D9(0);
//  GPIO_D8(0);

//  delay(1000);


//  GPIO_D13(1);
//  GPIO_D12(1);
//  GPIO_D11(1);
//  GPIO_D10(1);
//  GPIO_D9(1);
//  GPIO_D8(1);

//  delay(3000);

//  GPIO_D13(0);
//  GPIO_D12(0);
//  GPIO_D11(0);
//  GPIO_D10(0);
//  GPIO_D9(0);
//  GPIO_D8(0);

//  delay(1000);

//ポートの初期化

  GPIO_D13(1);//未接続1=1
  GPIO_D12(1);//CS=1
  GPIO_D11(0);//RD=0
  GPIO_D10(0);//WR=0
  GPIO_D9(0);//RS=0
  GPIO_D8(1);//RESET=1


  delay(500);


  TXDT144TF_ST7735S_Init();

} //setup


void loop(){

  digitalWrite(PB7, HIGH);
  delay(20);

  digitalWrite(PB7, LOW);
  delay(20);
  
} //loop


```