LoginSignup
0
0

「液晶128x160」ST7735S(Parallel)を使用して、絶滅メディアと表示して遊ぶ(「横」スクロール)(Arduino UNO)(ブロック)

Last updated at Posted at 2024-05-24

x 過去ログを見よ
x 16x200のデータである

● データの作成

o_coq128.jpg

● データの変換

o_coq129.jpg

o_coq130.jpg




//ssd1306_block_zetumetu_yoko1_UNO_1


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


//定義
//GPIO
#define GPIO_RESET_P  2 //RESET=1
#define GPIO_RS_P    A3 //RS=0
#define GPIO_WR_P     3 //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
  GPIO2(1);//A0=1;
  delay(2);

  for (int y = 0; y < 20; y++) {
    for (int k = 0; k < 7; k++) {
      for (int x = 0; x < 16; x++) {
        for (int i = 0; i < 7; i++) {
          color_vel = s_dot[y][x];
          if ( color_vel != 0) {//ドットがあり
            color_h = (color_vel >> 8) & 0xff;
            color_l =  color_vel       & 0xff;
            
            GPIO_8BIT( color_h );//P1=a; data
            GPIO3(0);//WRB=0;
            GPIO3(1);//WRB=1;

            GPIO_8BIT( color_l );//P1=a; data
            GPIO3(0);//WRB=0;
            GPIO3(1);//WRB=1;
          } else {//ドットがなし
            GPIO_8BIT(0x00);//P1=a; data
            GPIO3(0);//WRB=0;
            GPIO3(1);//WRB=1;

            GPIO3(0);//WRB=0;
            GPIO3(1);//WRB=1;
          }//end if
        }//for 8
        GPIO_8BIT(0x00);//P1=a; data

        GPIO3(0);//WRB=0;
        GPIO3(1);//WRB=1;

        GPIO3(0);//WRB=0;
        GPIO3(1);//WRB=1;
      }//for 16
    }//for 7
    for (int i = 0; i < 128; i++) {//空白を1ライン引く
      GPIO3(0);//WRB=0;
      GPIO3(1);//WRB=1;

      GPIO3(0);//WRB=0;
      GPIO3(1);//WRB=1;
    }//for i
  }//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();

} //setup


int zetumetu_tate1[200] = {
  0x0000, 0x0000, 0x07e0, 0x0ff0, 0x1ff8, 0x3ffc, 0x3ffc, 0x7ffe, 
  0x7ffe, 0x7ffe, 0x7ffe, 0x7ffe, 0x3ffc, 0x3ffc, 0x1ff8, 0x0ff0, 
  0x07e0, 0x0000, 0x07e0, 0x0ff0, 0x1ff8, 0x3ffc, 0x3ffc, 0x7ffe, 
  0x7ffe, 0x7ffe, 0x7ffe, 0x7ffe, 0x3ffc, 0x3ffc, 0x1ff8, 0x0ff0, 
  0x07e0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 
  0x6000, 0x1d18, 0x00e4, 0xffa2, 0x0099, 0x04c4, 0x3980, 0x0010, 
  0x7fe8, 0x8226, 0x8223, 0x83e2, 0x823a, 0x8216, 0x83f0, 0x0000, 
  0x0000, 0x0000, 0x4010, 0x3022, 0x0c46, 0x8000, 0x7000, 0x0ff8, 
  0x0048, 0x4648, 0x2048, 0x1fc8, 0x2248, 0x0808, 0x07ff, 0x0f08, 
  0x7108, 0xe0ee, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 
  0x2000, 0x2000, 0x3000, 0x1000, 0x18e0, 0x0480, 0x0300, 0x0200, 
  0x0500, 0x0880, 0x0840, 0x0020, 0x0010, 0x000e, 0x0000, 0x0000, 
  0x0100, 0x0110, 0x4110, 0x4110, 0x2110, 0x2108, 0x3f88, 0x0088, 
  0x0088, 0x0080, 0x0084, 0x0098, 0x0002, 0x000c, 0x0000, 0x0000, 
  0x0000, 0x0000, 0x0000, 0x0400, 0x0400, 0x7e00, 0x0100, 0x0080, 
  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0002, 0x0002, 
  0x0002, 0x0002, 0x7fe2, 0x0082, 0x0042, 0x0042, 0x0062, 0x003a, 
  0x0006, 0x0000, 0x0000, 0x07e0, 0x0ff0, 0x1ff8, 0x3ffc, 0x3ffc, 
  0x7ffe, 0x7ffe, 0x7ffe, 0x7ffe, 0x7ffe, 0x3ffc, 0x3ffc, 0x1ff8, 
  0x0ff0, 0x07e0, 0x0000, 0x07e0, 0x0ff0, 0x1ff8, 0x3ffc, 0x3ffc, 
  0x7ffe, 0x7ffe, 0x7ffe, 0x7ffe, 0x7ffe, 0x3ffc, 0x3ffc, 0x1ff8, 
  0x0ff0, 0x07e0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 
  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 
  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 
  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
};

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

  int hl;
  // y,x パターンRAMの初期化

  //int ii;
  //ii = 10; //開始位置
  for(int ii=0;ii<(200 - 20);ii++){
  for (int y = 0; y < 20; y++) {//行のループ
    hl = zetumetu_tate1[ii+y];
    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(500); //0.5秒待つ debug

  }//for ii

} //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