ST7735(パラレル)で遊ぶ12(成功?)(1か月から3か月の長期記事)ATM0177B5


x 過去ログをみよ

いろいろ
昨日深夜2時までがんばたったかいが、あった!!

ベースのホームページ

https://beiznotes.org/200911071257539777-2/


やや成功

なんか出た、書き込めた


![o_cop531.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/4298ed9d-e01d-e0a6-440f-fa93d4f9e4f0.jpeg)



----------------------------------------------


接続表(仮)
arduino側 - 液晶側

13 - 未接続
12 - CS(8)
11 - RD(25)
10 - WR(26)
9 - RS(27)
8 - REST(28)

7 - DB7(17)
6 - DB6(18)
5 - DB5(19)
4 - DB4(20)
3 - DB3(21)
2 - DB2(22)
1 - DB1(23)
0 - DB0(24)


----------------------------------------------


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



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

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

    LCD_Write_CMD(0x29);//display on
    delay(100);

delay(5000);


    LCD_Write_CMD(0x2C); //memory write

    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

    while(1){}
delay(5000);

    LCD_Write_CMD(0xFF);//VCOM4 level
    LCD_Write_Data(0x40);//TC2=4, TC1=0 clock delay
    LCD_Write_Data(0x03);//TC3=3 clock delay
    LCD_Write_Data(0x1A);

    LCD_Write_CMD(0xd9);//EEPROM control status?
    LCD_Write_Data(0x60);//30h?
    LCD_Write_CMD(0xc7);//Set VCOM offset control?
    LCD_Write_Data(0x90);// vmf = vmh (same as 10h)
    delay(200);

    LCD_Write_CMD(0xB1);//Frame Rate Control(In normal mode/ Full colors)
    //Frame rate= f_osc/((RTNA + 20)*(LINE+FPA+BPA))
    LCD_Write_Data(0x04);//RTNA = 4h
    LCD_Write_Data(0x25);//FPA=25h = 37
    LCD_Write_Data(0x18);//BPA=18h = 24

    LCD_Write_CMD(0xB2);//Frame Rate Control (In Idle mode/ 8-colors)
    LCD_Write_Data(0x04);
    LCD_Write_Data(0x25);
    LCD_Write_Data(0x18);

    LCD_Write_CMD(0xB3);//Frame Rate Control (In Partial mode/ full colors)
    //1st parameter to 3rd parameter are used in line inversion mode.
    LCD_Write_Data(0x04);
    LCD_Write_Data(0x25);
    LCD_Write_Data(0x18);
    //4th parameter to 6th parameter are used in frame inversion mode.
    LCD_Write_Data(0x04);
    LCD_Write_Data(0x25);
    LCD_Write_Data(0x18);

    LCD_Write_CMD(0xB4);//Display Inversion Control(0:line inversion, 1:frameinversion)
    //[3:0] in full colors normal mode, in idle mode, in full colors partial mode (Partial mode on / Idle mode off)
    LCD_Write_Data(0x03);// 011

    LCD_Write_CMD(0xB6);//Display Function set 5
    LCD_Write_Data(0x15);//NO=1,SDT=1,EQ=1 (default)
    LCD_Write_Data(0x02);//PTG=0,PT=2

    LCD_Write_CMD(0xC0);// POWER CONTROL 1 GVDD&AVDD
    LCD_Write_Data(0x02);//4.7V (default)
    LCD_Write_Data(0x70);//1.0uA (default)

    LCD_Write_CMD(0xC1);// POWER CONTROL 2 VGHH&VCLL
    LCD_Write_Data(0x07);// 14.7V, -12.25V

    LCD_Write_CMD(0xC2);// POWER CONTROL 3 (in Normal mode/ Full colors)
    LCD_Write_Data(0x01);// (default)
    LCD_Write_Data(0x01);// (default)

    LCD_Write_CMD(0xC3);// POWER CONTROL 4 (in Idle mode/ 8-colors)
    LCD_Write_Data(0x02);// (default)
    LCD_Write_Data(0x07);// (default)

    LCD_Write_CMD(0xC4);// POWER CONTROL 5 (in Partial mode/ full-colors)
    LCD_Write_Data(0x02);// (default)
    LCD_Write_Data(0x04);// (default)

    LCD_Write_CMD(0xFC);// POWER CONTROL 6 (in Partial mode + Idle mode)
    LCD_Write_Data(0x11);// (default)
    LCD_Write_Data(0x17);// 15h (default) -> 17h dcd

    LCD_Write_CMD(0xC5);// VCOMH&VCOML
    LCD_Write_Data(0x3c);// 4V (default)
    LCD_Write_Data(0x4f);// 3a:-1.050V(default) -> 4f:-0.525V

    LCD_Write_CMD(0x36);//Memory data access control
    LCD_Write_Data(0xC8);//MY-MX-MV-ML-RGB-MH-0-0 = 11001000 , (mirror xy, BGR)


    LCD_Write_CMD(0x3a);//Interface pixel format
    LCD_Write_Data(0x05);//16bit mode

    //GAMMA SET BY REGISTER
    //***********************GAMMA*************************
    LCD_Write_CMD(0xE0);// + polarity
    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);// - polarity
    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);//column address set
    LCD_Write_Data(0x00);//xs = 02h = 2
    LCD_Write_Data(0x02);
    LCD_Write_Data(0x00);//xe = 81h = 129
    LCD_Write_Data(0x81);

    LCD_Write_CMD(0x2B);//row address set
    LCD_Write_Data(0x00);//ys = 03h = 3
    LCD_Write_Data(0x03);
    LCD_Write_Data(0x00);//ye = 82h = 130
    LCD_Write_Data(0x82);

    LCD_Write_CMD(0x29);//display on
    delay(100);

    LCD_Write_CMD(0x2C); //memory write

    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(1);//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



```