0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

(高速化)(8bitパラレル8MHz)「液晶128x160」ST7735S(Parallel)を使用して、ランダム表示して遊ぶ改(Arduino UNO)(ブロック)

Last updated at Posted at 2024-05-31

x 過去ログを見よ!!
x GPIO_WR_Pは、13
x 白黒のみ

o_coq151.jpg



//ssd1306_block_random2_UNO_1


//インクルド
#include <Arduino.h>
#include <SPI.h>      //SPI

//定義
//GPIO
#define GPIO_RESET_P  2 //RESET=1
#define GPIO_RS_P    A3 //RS=0
#define GPIO_WR_P    13 //WR=1
#define GPIO_RD_P    A2 //RD=1

#define GPIO_DB7      8
#define GPIO_DB6      7
#define GPIO_DB5      9
#define GPIO_DB4      6
#define GPIO_DB3     A0
#define GPIO_DB2      5
#define GPIO_DB1     A1
#define GPIO_DB0      4

// GPIO A4 I2Cで使用済み
// GPIO A5 I2Cで使用済み

#define GPIO1(s) digitalWrite(GPIO_RESET_P , s)  //RESET
#define GPIO2(s) digitalWrite(GPIO_RS_P    , s)  //A0
#define GPIO3(s) digitalWrite(GPIO_WR_P    , s)  //WR
#define GPIO4(s) digitalWrite(GPIO_RD_P    , s)  //RD

//全体のカラー
int s_color = 0xFFFF; //ハイホワイト

//パターンRAM 16x20ドット
int s_dot[20][16];


//パラレルポートにデータをセットする。
void GPIO_8BIT(int s)
{
  digitalWrite(GPIO_DB7, (s >> 7) & 0x01); //DB7
  digitalWrite(GPIO_DB6, (s >> 6) & 0x01); //DB6
  digitalWrite(GPIO_DB5, (s >> 5) & 0x01); //DB5
  digitalWrite(GPIO_DB4, (s >> 4) & 0x01); //DB4
  digitalWrite(GPIO_DB3, (s >> 3) & 0x01); //DB3
  digitalWrite(GPIO_DB2, (s >> 2) & 0x01); //DB2
  digitalWrite(GPIO_DB1, (s >> 1) & 0x01); //DB1
  digitalWrite(GPIO_DB0,  s       & 0x01); //DB0
} //GPIO_8BIT

//コマンドの書き込み
void LCD_Write_CMD(int a)
{
  GPIO2(0); //A0=0;
  GPIO_8BIT(a);//P1=a; data
  GPIO3(0);//WRB=0;
  GPIO3(1);//WRB=1;
} //LCD_Write_CMD


//データ書き込み
void LCD_Write_Data(int a)
{
  GPIO2(1);//A0=1;
  GPIO_8BIT(a);//P1=a; data
  GPIO3(0);//WRB=0;
  GPIO3(1);//WRB=1;
} //LCD_Write_Data


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

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

  GPIO1(1);//LCD_RESET=1;

  delay(1); //Delay 1ms

  GPIO1(0);//LCD_RESET=0;

  delay(1); //Delay 1ms

  GPIO1(1);//LCD_RESET=1;

  delay(120); //Delay 120ms

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


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

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

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

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

  LCD_Write_CMD(0x36);//RGB-RGR format
  LCD_Write_Data(0x08);//RGB mode
  delay(100);

  // y,x パターンRAMの初期化
  for (int y = 0; y < 20; y++) {
    for (int x = 0; x < 16; x++) {
      s_dot[y][x] = 0;
    }//for x
  }//for y

} //ATM0177B5_ST7735S_Init


//全体のカラーの変更
void set_color(int color) {

  s_color = color;

}//set_color


//パターンRAMの内容を液晶に転送
void p_ram_refresh() {

  //カラーの上位と下位と一時
  int color_h;
  int color_l;
  int color_vel;

  //画面の書き込み開始
  //LCD_Write_CMD(0x2C); //memory write

  GPIO_8BIT(0x2C);
  GPIO2(0);//A0=1;
  SPI.transfer(0x00);

  delay(2);
  GPIO2(1);//A0=1;

  for (int y = 0; y < 20; y++) {
    for (int k = 0; k < 8; k++) {
      for (int x = 0; x < 16; x++) {
        color_vel = s_dot[y][x];
        if ( color_vel == 0 ) {GPIO_8BIT(0x00);} else {GPIO_8BIT(0xFF);}

        SPI.transfer(0x00);
        SPI.transfer(0x00);

        //for (int i = 0; i < 8; i++) {
        //    GPIO3(0);//WRB=0;
        //    GPIO3(1);//WRB=1;
        //    GPIO3(0);//WRB=0;
        //    GPIO3(1);//WRB=1;
        //    GPIO3(0);//WRB=0;
        //}//for 8
      }//for 16
    }//for 7

  }//for tt

}//p_ram_refresh


//リフレッシュ(画像の再表示)
void refresh() {

  p_ram_refresh();//パターンRAMの反映

}//refresh


//初期化
void setup() {

  //ポートのモード設定
  //アウトプットモード
  pinMode(GPIO_RESET_P, OUTPUT); //REST
  pinMode(GPIO_RS_P,    OUTPUT); //RS
  pinMode(GPIO_WR_P,    OUTPUT); //WR
  pinMode(GPIO_RD_P,    OUTPUT); //RD

  pinMode(GPIO_DB0, OUTPUT); //DB0
  pinMode(GPIO_DB1, OUTPUT); //DB1
  pinMode(GPIO_DB2, OUTPUT); //DB2
  pinMode(GPIO_DB3, OUTPUT); //DB3

  pinMode(GPIO_DB4, OUTPUT); //DB4
  pinMode(GPIO_DB5, OUTPUT); //DB5
  pinMode(GPIO_DB6, OUTPUT); //DB6
  pinMode(GPIO_DB7, OUTPUT); //DB7

  //ポートの初期化
  GPIO4(1);//RD=1
  GPIO3(0);//WR=0
  GPIO2(0);//RS=0
  GPIO1(1);//RESET=1

  delay(500); //0.5秒待つ

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

  // SPIの初期化
  SPI.begin(); // CLK-18 MOSI-23
  //SPI.begin(sck,miso,mosi,ss);
  //SPI.begin(39, 40, 41, -1);
  //SPI.begin(7, -1, 9, -1);
  //SPI.begin(9, -1, 7, -1);


  //DW(SS, LOW); //
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV2);  // 8Mhz
  //SPI.setClockDivider(SPI_CLOCK_DIV4);  // 4Mhz
  //SPI.setClockDivider(SPI_CLOCK_DIV8);  // 2Mhz

} //setup


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

  int hl;
  // y,x パターンRAMの初期化
  for (int y = 0; y < 20; y++) {
    hl = random(65536);
    for (int x = 0; x < 16; x++) {
      if ( (hl & 0x8000) == 0 ) {

        s_dot[y][x] = 0;

      } else {

        s_dot[y][x] = s_color;

      } //end if
      hl = hl << 1;
    }//for x
  }//for y

  refresh(); //画面の再表示

  //delay(3000); //3秒待つ debug

} //loop



0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?