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?

More than 1 year has passed since last update.

StampS3、カラー液晶ATM0177B3A(ILI9163V)を使い表示する。(仮想VRAM)(SRAM40K以上)

Last updated at Posted at 2024-04-16

参考1

↓クリック↓

参考

↓クリック↓

目的
カラー液晶で遊ぶ。

o_coq040.jpg

o_coq037.jpg

o_cop821.jpg

1 LED A <- 330Ω <- 3.3V
2 NC
3 GND
4 VCC
5 SDA (SPI MOSI)
6 SCK (SPI CLK)
7 A0 (RS or DC)
8 REST
9 LED K <- GND
10 CS



//ILI9163_VRAM_M5S3_1


//ヘッダーファイル
#include <Adafruit_GFX.h>
#include "hh.h"

 
//定義
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 160 // OLED display height, in pixels
NA_ILI9163 display(SCREEN_WIDTH, SCREEN_HEIGHT);


// ビットマップデータ
uint8_t databytes[8] =
{
  0b01100110,
  0b10101111,
  0b10111111,
  0b11011111,

  0b01111110,
  0b01111110,
  0b00111100,
  0b00011000
};


//初期化
void setup() {

  //ディスプレイの初期化
  display.begin();


  //表示方向
  display.setRotation(0);


  // 画面表示をクリア
  display.clearDisplay();


  //ビットマップの表示
  display.drawBitmap(3, 3, databytes, 8, 8,  NA_ILI9163_RED);


  // テキストサイズを設定
  display.setTextSize(3);
  // テキスト色を設定
  display.setTextColor(NA_ILI9163_RED);
  // テキストの開始位置を設定
  display.setCursor(20, 20);

  // 1行目に46を表示
  display.println("9163");


  // 画面の左側に長方形(塗りつぶしなし)を描画
  // display.drawRect(左上x, 左上y, 幅, 高さ, 線の色)
  display.drawRect(0, 0, 127, 159, NA_ILI9163_WHITE);

  // 描画バッファの内容を画面に表示
  display.display();

}//setup


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



hh.cpp

hh.cpp


//インクルド
#include "hh.h"
#include <Adafruit_GFX.h>
#include <SPI.h>


//定義
///< No-temp-var swap operation
#define NA_ILI9163_swap(a, b)        \
  (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b)))


//GPIOの設定2 開始
#define TFT_CS    1
#define TFT_RST   3
#define TFT_RS    5
#define TFT_MOSI  7
#define TFT_SCLK  9
#define GPIO_CS(y)     digitalWrite(TFT_CS,y)
#define GPIO_RESET(y)  digitalWrite(TFT_RST,y)
#define GPIO_RS(y)     digitalWrite(TFT_RS,y)


//データの出力
void NA_ILI9163::GPIO_8BIT(uint8_t s)
{

  SPI.transfer(s);

} //GPIO_8BIT


//コマンドの書き込み
void NA_ILI9163::LCD_Write_CMD(uint8_t a)
{

  GPIO_CS(0);   //CS=0; 12
  GPIO_RS(0);   //A0=0; 9
  GPIO_8BIT(a); //P1=a; data SPI SPI
  GPIO_CS(1);   //CS=1; 12

} //LCD_Write_CMD


//データ書き込み
void NA_ILI9163::LCD_Write_Data(uint8_t a)
{

  GPIO_CS(0);   //CS=0; 12
  GPIO_RS(1);   //A0=1; 9
  GPIO_8BIT(a); //P1=a; data SPI SPI
  GPIO_CS(1);   //CS=1; 12

} //LCD_Write_Data


//液晶の初期化処理
void NA_ILI9163::ILI9163_Init(void)
{

  //----------  ILI9163 Reset Sequence  --------//

  GPIO_RESET(1);//LCD_RESET=1;
  delay(1); //Delay 1ms

  GPIO_RESET(0);//LCD_RESET=0;
  delay(1); //Delay 1ms

  GPIO_RESET(1);//LCD_RESET=1;
  delay(120); //Delay 120ms

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

  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(0x36);//RGB-RGR format
  LCD_Write_Data(0x00);//RGB mode
  delay(100);

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

} //ILI9163_Init


NA_ILI9163::NA_ILI9163(uint8_t w, uint8_t h)
  : Adafruit_GFX(w, h), buffer(NULL)

{
}


//バッファのクリア
NA_ILI9163::~NA_ILI9163(void) {
  if (buffer) {
    free(buffer);
    buffer = NULL;
  }
}//~NA_ILI9163


//初期処理
bool NA_ILI9163::begin(void) {

  if ((!buffer) && !(buffer = (uint16_t *)malloc(WIDTH * HEIGHT * 2)))
    return false;

  //バッファーのクリア
  clearDisplay();

  //ポートのモード設定
  //アウトプットモード
  pinMode(TFT_CS, OUTPUT);
  pinMode(TFT_RST, OUTPUT);
  pinMode(TFT_RS, OUTPUT);

  //ポートの初期化
  GPIO_CS(1);    //CS=1
  GPIO_RESET(1); //RESET=1
  GPIO_RS(0);    //RS=0

  // SPIの初期化
  //SPI.beginTransaction( SPISettings(16000000, MSBFIRST, SPI_MODE0) );
  SPI.beginTransaction( SPISettings( 8000000, MSBFIRST, SPI_MODE0) );
  //SPI.beginTransaction( SPISettings( 4000000, MSBFIRST, SPI_MODE0) );
  //SPI.beginTransaction( SPISettings( 2000000, MSBFIRST, SPI_MODE0) );
  //SPI.beginTransaction( SPISettings( 1000000, MSBFIRST, SPI_MODE0) );
  //SPI.begin(); // 11 12 13
  //SPI.begin(9, -1, 7, -1);
  SPI.begin(TFT_SCLK, -1, TFT_MOSI, -1);

  delay(500); //0.5秒待つ

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

  return true; // Success
}//begin


//点の表示
void NA_ILI9163::drawPixel(int16_t x, int16_t y, uint16_t color) {
  if ((x >= 0) && (x < width()) && (y >= 0) && (y < height())) {
    // Pixel is in-bounds. Rotate coordinates if needed.
    switch (getRotation()) {
      case 1:
        NA_ILI9163_swap(x, y);
        x = WIDTH - x - 1;
        break;
      case 2:
        x = WIDTH - x - 1;
        y = HEIGHT - y - 1;
        break;
      case 3:
        NA_ILI9163_swap(x, y);
        y = HEIGHT - y - 1;
        break;
    }//end switch

    //ドットのカラーの設定
    buffer[ (y << 7) | x ] = color;

  }//if
}//drawPixel


//バッファのクリア
void NA_ILI9163::clearDisplay(void) {
  memset(buffer, 0, WIDTH * HEIGHT * 2 );
}


bool NA_ILI9163::getPixel(int16_t x, int16_t y) {
  if ((x >= 0) && (x < width()) && (y >= 0) && (y < height())) {
    // Pixel is in-bounds. Rotate coordinates if needed.
    switch (getRotation()) {
      case 1:
        NA_ILI9163_swap(x, y);
        x = WIDTH - x - 1;
        break;
      case 2:
        x = WIDTH - x - 1;
        y = HEIGHT - y - 1;
        break;
      case 3:
        NA_ILI9163_swap(x, y);
        y = HEIGHT - y - 1;
        break;
    }
    return (buffer[ (y << 7) | x ] );
  }
  return false; // Pixel out of bounds
}


uint16_t *NA_ILI9163::getBuffer(void) {
  return buffer;
}


//画面のリフレッシュ
void NA_ILI9163::display(void) {

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

  int vg;
  for (int i = 0; i < (HEIGHT * WIDTH); i++) {
    vg = buffer[i];
    //---------------- 1バイト目
    LCD_Write_Data((vg >> 7) & 0xff);
    //---------------- 2バイト目
    LCD_Write_Data(       vg & 0xff);
  }//for i

}//display



hh.h

hh.h



#ifndef _NA_ILI9163_H_
#define _NA_ILI9163_H_

#include <Adafruit_GFX.h>

#ifndef NO_ADAFRUIT_NA_ILI9163_COLOR_COMPATIBILITY
#define BLACK NA_ILI9163_BLACK     ///< Draw 'off' pixels
#define WHITE NA_ILI9163_WHITE     ///< Draw 'on' pixels
#define RED   NA_ILI9163_RED       ///< Draw red
#endif
/// fit into the ILI9163_ naming scheme
#define NA_ILI9163_BLACK 0x0000           ///< Draw 'off' pixels
#define NA_ILI9163_WHITE 0xffff           ///< Draw 'on' pixels
#define NA_ILI9163_RED 0b1111100000000000 // < Draw red

///< Draw 'on' pixels
//#define NA_ILI9163_INVERSE 2 ///< Invert pixels


class NA_ILI9163 : public Adafruit_GFX {
  public:

    NA_ILI9163(uint8_t w, uint8_t h);

    ~NA_ILI9163(void);

    bool begin(void);
    void display(void);
    void clearDisplay(void);
    void drawPixel(int16_t x, int16_t y, uint16_t color);
    bool getPixel(int16_t x, int16_t y);
    uint16_t *getBuffer(void);

    void GPIO_8BIT(uint8_t s);
    void LCD_Write_CMD(uint8_t ww);
    void LCD_Write_Data(uint8_t ii);
    void ILI9163_Init(void);


  protected:

    uint16_t *buffer; ///< Buffer data used for display buffer. Allocated when
                      ///< begin method is called.
 
};

#endif // _NA_ILI9163_H_



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?