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


x 過去ログを見よ

イメージ

![o_cop529.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/97d2a640-bade-46cf-1751-f23f669752fc.jpeg)



プログラム　人間用　(だって人間だもの　みつお?)




```c++




//GPIO_st7735_writ_testG1_767_1

#define DW digitalWrite 



void GPIO_D13(int s)
{

  digitalWrite(13,s);

} //GPIO_D13

void GPIO_D12(int s)
{

  digitalWrite(12,s);

} //GPIO_D12


void GPIO_D11(int s)
{

  digitalWrite(11,s);

} //GPIO_D11


void GPIO_D10(int s)
{

  digitalWrite(10,s);

} //GPIO_D10


void GPIO_D9(int s)
{

  digitalWrite(9,s);

} //GPIO_D9


void GPIO_D8(int s)
{

  digitalWrite(8,s);

} //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)
  
} //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 WriteDAT(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();
  GPIO_D10(1);//WRB=1; 10
  GPIO_D12(1);//CS=1;  12
} //WriteDAT


void WriteCOM(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();
  GPIO_D10(1);//WRB=1; 10
  GPIO_D12(1);//CS=1; 12
} //WriteDAT





void LCD_Write_Data(int s) {

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

  digitalWrite(PB7, HIGH);

  delay(1000);

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

  WriteDAT(s);
  delay(1000);

  digitalWrite(PB7, LOW);
  delay(4000);

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


} //LCD_Write_Data


void LCD_Write_CMD(int s){

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

  digitalWrite(PB7, HIGH);

  delay(1000);

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

  WriteCOM(s);
  delay(1000);

  digitalWrite(PB7, LOW);
  delay(4000);

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


} //LCD_Write_CMD



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

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

LCD_Write_CMD(0x11); //Sleep out

Delayms (120); //Delay 120ms

//----------    ST7735S Frame rate    --------//

LCD_Write_CMD(0xB1); //Frame rate 80Hz

LCD_Write_Data(0x02);

LCD_Write_Data(0x35);

LCD_Write_Data(0x36);

LCD_Write_CMD(0xB2); //Frame rate 80Hz

LCD_Write_Data(0x02);

LCD_Write_Data(0x35);

LCD_Write_Data(0x36);

LCD_Write_CMD(0xB3); //Frame rate 80Hz

LCD_Write_Data(0x02);

LCD_Write_Data(0x35);

LCD_Write_Data(0x36);

LCD_Write_Data(0x02);

LCD_Write_Data(0x35);

LCD_Write_Data(0x36);

//----------End ST7735S Frame rate--------//

LCD_Write_CMD(0xB4); //Dot inversion

LCD_Write_Data(0x03);

//----------ST7735S Power Sequence--------//

LCD_Write_CMD(0xC0);

LCD_Write_Data(0xA2);

LCD_Write_Data(0x02);

LCD_Write_Data(0x84);

LCD_Write_CMD(0xC1);

LCD_Write_Data(0xC5);

LCD_Write_CMD(0xC2);

LCD_Write_Data(0x0D);

LCD_Write_Data(0x00);

LCD_Write_CMD(0xC3);

LCD_Write_Data(0x8D);

LCD_Write_Data(0xEA);

LCD_Write_CMD(0xC4);

LCD_Write_Data(0x8D);

LCD_Write_Data(0xEE);

//----------End ST7735S Power Sequence--------//

LCD_Write_CMD(0xC5); //VCOM

LCD_Write_Data(0x05);

LCD_Write_CMD(0x36); //MX, MY, RGB mode

LCD_Write_Data(0xC8);

//----------ST7735S Gamma Sequence--------//

LCD_Write_CMD(0xE0);

LCD_Write_Data(0x03);

LCD_Write_Data(0x1B);

LCD_Write_Data(0x09);

LCD_Write_Data(0x0E);

LCD_Write_Data(0x32);

LCD_Write_Data(0x2D);

LCD_Write_Data(0x28);

LCD_Write_Data(0x2C);

LCD_Write_Data(0x2B);

LCD_Write_Data(0x29);

LCD_Write_Data(0x30);

LCD_Write_Data(0x3B);

LCD_Write_Data(0x00);

LCD_Write_Data(0x01);

LCD_Write_Data(0x02);

LCD_Write_Data(0x10);

LCD_Write_CMD(0xE1);

LCD_Write_Data(0x03);

LCD_Write_Data(0x1B);

LCD_Write_Data(0x09);

LCD_Write_Data(0x0E);

LCD_Write_Data(0x32);

LCD_Write_Data(0x2E);

LCD_Write_Data(0x28);

LCD_Write_Data(0x2C);

LCD_Write_Data(0x2B);

LCD_Write_Data(0x28);

LCD_Write_Data(0x31);

LCD_Write_Data(0x3C);

LCD_Write_Data(0x00);

LCD_Write_Data(0x00);

LCD_Write_Data(0x02);

LCD_Write_Data(0x10);

//----------End ST7735S Gamma Sequence--------//

LCD_Write_CMD(0x3A); //65k mode

LCD_Write_Data(0x05);

LCD_Write_CMD(0x29); //Display on

}



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


  TXDT144TF_ST7735S_Init();

} //setup


void loop(){
} //loop




```