aitendoさんから手に入れた2.4インチ液晶モジュール(TP付き) [M024C9320TP] をarduinoに接続してみる。
使用するのは「3.3V版8MHz動作のArduinoUNO互換機」だ。
https://ameblo.jp/fc2miha/entry-12833772800.html


映像

aitendoさんのページからポイントを拾って行く。
1.動作電源は3.3v
2.タッチコントローラーはXPT2046
3.ディスプレイコントローラーはILI9320
4.パラレル8ビットまたは16ビットインターフェース
5.ジャンパーJ2をショートすると8ビット、オープンで16ビット
6.8ビットの場合はD8-D15、16ビットの場合はD0-D15
7.デフォルトは16ビットモード
8.接続(たぶん8ビットモード時)
 液晶側/Arduino UNO側
 LED-A/3.3V
 VCC/5V
 GND/GND
 DB8~DB15/D0~D7
 RS/A0
 WR/A1
 CS/A2
 RESET/A3
 RD/3.3V
M028C9320TP-pinout

上記を踏まえサンプルソースはと探すと、AdafruitからダウンロードしておいたTFT-LCD-Library-masterの中のgraphictestあたりがのソースのコメントが素敵な感じだったので・・・
とりあえず、採用する。
ソースコメント抜粋。
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
//   D0 connects to digital pin 8  (Notice these are
//   D1 connects to digital pin 9   NOT in order!)
//   D2 connects to digital pin 2
//   D3 connects to digital pin 3
//   D4 connects to digital pin 4
//   D5 connects to digital pin 5
//   D6 connects to digital pin 6
//   D7 connects to digital pin 7

なんか矛盾があるような気がするけなんか素敵な感じ。

とりあえず、半田付け。
M028C9320TP-pinout.jpg
1.ピン配置に2列のピンソケットを接続
2.J2をショートさせる

配線
上記を参考にして以下のように接続
 液晶側/Arduino UNO側
 GND/GND
 VCC/VCC
 RS/A2 
 WR/A1 
 RD/A0 
 DB8~DB15/D0~D7
 CS/A3 
 RESET/A4
 LED-A/AREF

さて、実行!!
むむ、動かない!!英語で知らないチップだと言っているぞ。
ソースを見ると、なんと、ILI9320には対応していないらしい!!
困った。

こんな時は・・・やっぱりgoogle先生に聞いてみた。
じゃーん
http://blog.tkjelectronics.dk/2010/03/arduino-mega-and-ili9320-display/
arduino MEGAにてILI9320に接続しているデモを発見!!
ArduinoUNO用に改造!!
あっさり動いたので記録しておきます。
ありがとうThomas

回路図

 

ソース
// Remember that the LCD area goes from:
//   X: 0-239
//   Y: 0-319


#define LCD PORTD  // Set the DB 0-7 to PORTA 0-7 (Pin 22-29)
#define LCD_RS A2
#define LCD_RS_LO digitalWrite(LCD_RS, LOW)
#define LCD_RS_HI digitalWrite(LCD_RS, HIGH)
#define LCD_CS A3
#define LCD_CS_LO digitalWrite(LCD_CS, LOW)
#define LCD_CS_HI digitalWrite(LCD_CS, HIGH)
#define LCD_WR A1
#define LCD_WR_LO digitalWrite(LCD_WR, LOW)
#define LCD_WR_HI digitalWrite(LCD_WR, HIGH)
#define LCD_RD A0
#define LCD_RD_LO digitalWrite(LCD_RD, LOW)
#define LCD_RD_HI digitalWrite(LCD_RD, HIGH)
#define LCD_RESET A4
#define LCD_RESET_LO digitalWrite(LCD_RESET, LOW)
#define LCD_RESET_HI digitalWrite(LCD_RESET, HIGH)
#define VERTICAL 0
#define HORIZONTAL 1
#define LCD_ALIGNMENT VERTICAL
//#define LCD_ALIGNMENT HORIZONTAL  // Not finished yet!

//LCDDRIVER VARIABLER
//Color codes
#define RED    0xf800
#define GREEN 0x07e0
#define BLUE  0x001f
#define WHITE 0xffff
#define BLACK 0x0000
#define YELLOW   0xFFE0

const PROGMEM byte Verdana_font_11[] = {
//const byte Verdana_font_11[] = {
    0,   // format
    11,   // fontHeight
    9,   // ascent
    33,   // from
    95,   // count
    59,   // totalWidth/8
    0x00,0x01,0x00,0x04,0x00,0x0B,0x00,0x10,0x00,0x1A,0x00,0x21,0x00,0x22,0x00,0x25,0x00,0x28,0x00,0x2D,0x00,0x34,0x00,0x36,0x00,0x39,0x00,0x3A,0x00,0x3F,0x00,0x44,0x00,0x49,0x00,0x4E,0x00,0x53,0x00,0x59,0x00,0x5E,0x00,0x63,0x00,0x68,0x00,0x6D,0x00,0x72,0x00,0x73,0x00,0x75,0x00,0x7B,0x00,0x82,0x00,0x88,0x00,0x8C,0x00,0x94,0x00,0x9A,0x00,0xA0,0x00,0xA7,0x00,0xAE,0x00,0xB3,0x00,0xB8,0x00,0xBF,0x00,0xC5,0x00,0xC8,0x00,0xCC,0x00,0xD2,0x00,0xD7,0x00,0xDE,0x00,0xE4,0x00,0xEB,0x00,0xF0,0x00,0xF7,0x00,0xFD,0x01,0x03,0x01,0x0A,0x01,0x10,0x01,0x16,0x01,0x1F,0x01,0x25,0x01,0x2C,0x01,0x32,0x01,0x35,0x01,0x3A,0x01,0x3D,0x01,0x44,0x01,0x4B,0x01,0x4D,0x01,0x52,0x01,0x57,0x01,0x5C,0x01,0x61,0x01,0x66,0x01,0x6A,0x01,0x6F,0x01,0x74,0x01,0x75,0x01,0x78,0x01,0x7D,0x01,0x7E,0x01,0x87,0x01,0x8C,0x01,0x91,0x01,0x96,0x01,0x9B,0x01,0x9F,0x01,0xA3,0x01,0xA7,0x01,0xAC,0x01,0xB1,0x01,0xB8,0x01,0xBD,0x01,0xC2,0x01,0xC6,0x01,0xCB,0x01,0xCC,0x01,0xD1,0x01,0xD8,0x01,0xD8,    // Col ends
    0x50,0x04,0x00,0x00,0x4C,0x20,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x38,0x00,0x10,0x20,0x00,0x80,0xC1,0x09,0x84,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x00,    // Line 0
    0xD1,0x44,0x62,0x18,0x52,0xA8,0x00,0x02,0xE2,0x39,0xC1,0x7C,0xDF,0x73,0x80,0x00,0x00,0xE3,0xE3,0x3C,0x3D,0xF3,0xFF,0x3D,0x0F,0x78,0x61,0x8F,0x13,0x9E,0x39,0xE3,0xDF,0xE1,0x86,0x23,0x0C,0x1F,0xE4,0x08,0x80,0x08,0x20,0x00,0x81,0x01,0x00,0x84,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x92,0x00,    // Line 1
    0xD1,0x4F,0x92,0x24,0x52,0x70,0x80,0x05,0x1E,0x46,0x23,0x41,0x01,0x8C,0x40,0x00,0x00,0x14,0x13,0x22,0x43,0x0A,0x10,0x43,0x0A,0x18,0xA1,0x8F,0x14,0x51,0x45,0x14,0x22,0x21,0x86,0x23,0x0A,0x20,0x62,0x09,0x40,0x00,0x20,0x00,0x81,0x01,0x00,0x84,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x92,0x00,    // Line 2
    0x87,0xF4,0x94,0x24,0x21,0xA8,0x80,0x05,0x12,0x04,0x25,0x42,0x02,0x8C,0x68,0x60,0x30,0x19,0xD4,0xA2,0x81,0x06,0x10,0x81,0x0A,0x19,0x21,0x56,0x98,0x31,0x83,0x14,0x02,0x21,0x85,0x54,0x91,0x40,0xA2,0x0A,0x20,0x03,0xBC,0xE7,0xBB,0xDF,0xEB,0x8F,0xDD,0xE7,0x79,0xF6,0xFF,0x18,0xC9,0x8C,0x7C,0x92,0x00,    // Line 3
    0x82,0x94,0x64,0x19,0x21,0x20,0x80,0x09,0x12,0x08,0xC9,0x7B,0xC2,0x74,0x69,0x9F,0xCC,0x2A,0x54,0xBE,0x81,0x07,0xFE,0x81,0xFA,0x1A,0x21,0x56,0x98,0x31,0x83,0x13,0x02,0x21,0x49,0x54,0x60,0x81,0x21,0x0C,0x10,0x00,0x63,0x18,0xC5,0x23,0x19,0x96,0x23,0x18,0xC6,0x39,0x09,0x18,0xC9,0x52,0x84,0x92,0x31,    // Line 4
    0x82,0x8E,0x09,0xA5,0x21,0x07,0xF3,0x89,0x12,0x10,0x31,0x06,0x24,0x8B,0xC6,0x00,0x03,0x4A,0x54,0xA1,0x81,0x06,0x10,0x8F,0x0A,0x1E,0x21,0x26,0x58,0x3E,0x83,0xE0,0xC2,0x21,0x49,0x54,0x60,0x82,0x21,0x08,0x00,0x03,0xE3,0x08,0xFD,0x23,0x19,0xA6,0x23,0x18,0xC6,0x31,0x89,0x15,0x55,0x22,0x8B,0x11,0xC9,    // Line 5
    0x8F,0xC5,0x0A,0x62,0x21,0x00,0x80,0x11,0x12,0x20,0x3F,0x86,0x24,0x88,0x41,0x9F,0xCC,0x4A,0x5F,0xE1,0x81,0x06,0x10,0x83,0x0A,0x19,0x21,0x26,0x58,0x30,0x83,0x20,0x22,0x21,0x49,0x54,0x90,0x84,0x20,0x88,0x00,0x04,0x63,0x08,0xC1,0x23,0x19,0xE6,0x23,0x18,0xC6,0x30,0x69,0x15,0x55,0x22,0x90,0x92,0x46,    // Line 6
    0x05,0x05,0x12,0x63,0x21,0x00,0x84,0x51,0x12,0x42,0x21,0x46,0x28,0x88,0xA8,0x60,0x30,0x09,0xA8,0x61,0x43,0x0A,0x10,0x43,0x0A,0x18,0xA1,0x06,0x34,0x50,0x45,0x14,0x22,0x21,0x30,0x89,0x08,0x88,0x20,0x88,0x00,0x04,0x63,0x18,0xC5,0x23,0x19,0x96,0x23,0x18,0xC6,0x30,0x29,0x12,0x22,0x51,0x20,0x92,0x00,    // Line 7
    0x85,0x1E,0x11,0x9C,0x92,0x00,0x84,0x60,0xEF,0xFD,0xC1,0x39,0xC8,0x73,0x28,0x00,0x00,0x44,0x08,0x7E,0x3D,0xF3,0xF0,0x3D,0x0F,0xE8,0x7F,0x06,0x33,0x90,0x39,0x0B,0xC2,0x1E,0x30,0x89,0x08,0x8F,0xE0,0x48,0x00,0x03,0xFC,0xE7,0xB9,0x1F,0x19,0x8E,0x23,0x17,0x79,0xF1,0xC6,0xF2,0x22,0x89,0x3C,0x92,0x00,    // Line 8
    0x00,0x04,0x00,0x00,0x12,0x00,0x04,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x48,0x00,0x00,0x00,0x00,0x00,0x02,0x01,0x00,0x00,0x00,0x40,0x20,0x00,0x00,0x00,0x01,0x00,0x92,0x00,    // Line 9
    0x00,0x04,0x00,0x00,0x0C,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x38,0x0F,0xE0,0x00,0x00,0x00,0x1C,0x06,0x00,0x00,0x00,0x40,0x20,0x00,0x00,0x00,0x02,0x00,0x7C,0x00,    // Line 10
};

//#ifdef pgm_read_byte
#define FNT(_x) pgm_read_byte(Verdana_font_11 + (_x))
//#else
//#define FNT(_x) Verdana_font_11[_x]
//#endif

unsigned int current_color = BLUE;

void setup()   {
  LCD_Init();
 
  LCD_Clear(BLACK);

  LCD_HorLine(0,239,20,YELLOW);
  LCD_HorLine(0,239,30,RED);
  LCD_HorLine(0,239,40,YELLOW); 
 
  LCD_HorLine(0,239,280,YELLOW);
  LCD_HorLine(0,239,290,RED);
  LCD_HorLine(0,239,300,YELLOW);

  LCD_Rectangle(70,130,180,190,GREEN);
  LCD_HorLine(70,180,130,RED);
  LCD_HorLine(70,180,190,RED); 
  LCD_VerLine(130,190,70,RED); 
  LCD_VerLine(130,190,180,RED); 
  LCD_DrawString("Hello World", 98, 155, BLACK); 
 
  delay(5000);
  LCD_Clear_ScrollUp(1, WHITE);
 
  LCD_HorLine(0,239,20,RED);
  LCD_HorLine(0,239,30,BLUE);
  LCD_HorLine(0,239,40,RED); 
 
  LCD_HorLine(0,239,280,RED);
  LCD_HorLine(0,239,290,BLUE);
  LCD_HorLine(0,239,300,RED);

  LCD_Rectangle(70,130,180,190,YELLOW);
  LCD_HorLine(70,180,130,BLUE);
  LCD_HorLine(70,180,190,BLUE); 
  LCD_VerLine(130,190,70,BLUE); 
  LCD_VerLine(130,190,180,BLUE); 
  LCD_DrawString("Hello World", 98, 155, BLACK);
 
  delay(5000);
  LCD_Clear_ScrollDown(1, BLUE);
}


void loop()                    
{
  current_color = current_color + 0x732;
  if (current_color+0x732 >= 0xFFFF) {
    current_color = (current_color+0x732) - 0xFFFF;
  }
  LCD_Clear(current_color);
}

void LCD_WriteIndex(byte index)
{
  // Write Index
  LCD_RS_LO;
  LCD = 0;
  LCD_WR_LO;
  LCD_WR_HI;
  LCD = index;
  LCD_WR_LO;
  LCD_WR_HI;
}

void LCD_WriteData(unsigned int data)
{
  // Write Data
  LCD_RS_HI;
  LCD = highByte(data);
  LCD_WR_LO;
  LCD_WR_HI;
  LCD = lowByte(data);
  LCD_WR_LO;
  LCD_WR_HI;
  LCD = 0;

void LCD_WriteReg(byte index, unsigned int data)
{
  // Write Index
  LCD_WriteIndex(index);
 
  // Write Data
  LCD_WriteData(data);

void LCD_Init()
{
  pinMode(LCD_CS, OUTPUT);    // Set LCD CS pin As Output
  LCD_CS_HI;                  // Disable LCD
  pinMode(LCD_RESET, OUTPUT); // Set reset pin As Output
  LCD_RESET_LO;               // Hold in reset
  pinMode(LCD_RS, OUTPUT);    // Set RS pin As Output
  LCD_RS_LO; 
  pinMode(LCD_RD, OUTPUT);    // Set RD pin As Output
  LCD_RD_HI; 
  pinMode(LCD_WR, OUTPUT);    // Set WR pin As Output
  LCD_WR_HI; 
 
  DDRD = B11111111; // Set Data BUS As Output
 
  // Reset controller
  LCD_RESET_LO;
  delay(2);
  LCD_RESET_HI;
  delay(2);
 
  /*** Setup display For ILI9320 driver IC ***/
  LCD_CS_LO; // Enable LCD
  LCD_WriteReg(0xe5, 0x8000); //start osc
  LCD_WriteReg(0x00, 0x0001);
  delay(10);
  LCD_WriteReg(0xa4, 0x0001); //calb
  LCD_WriteReg(0x07, 0x0000); //display control(1)
  delay(10);
 
  /*** Display Setting ***/
  LCD_WriteReg(0x01, 0x0100); //Driver output control (1)
  LCD_WriteReg(0x02, 0x0700); //LCD driving control
 
  // Check page 55 in the datasheet for more information about alignment
  #if LCD_ALIGNMENT == VERTICAL
    LCD_WriteReg(0x03, 0x1030);   //Entry mode
  #elif LCD_ALIGNMENT == HORIZONTAL
    LCD_WriteReg(0x03, 0x1028);   //Entry mode
  #endif 
 
  LCD_WriteReg(0x04, 0x0000); //Resize control
  LCD_WriteReg(0x08, 0x0202); //Display control (2)
  LCD_WriteReg(0x09, 0x0000); //Display control (3)
 
  /*** Power Control ***/
  LCD_WriteReg(0x07, 0x0101); //power control 1 BT, AP
  LCD_WriteReg(0x17, 0x0001);
  LCD_WriteReg(0x10, 0x0000);
  LCD_WriteReg(0x11, 0x0007); //power control 2 DC, VC
  LCD_WriteReg(0x12, 0x0000); //power control 3 VRH
  LCD_WriteReg(0x12, 0x0000); //power control 3 VRH
  LCD_WriteReg(0x13, 0x0000); //power control 4 VCOM amplitude
  delay(20);
 
  LCD_WriteReg(0x10, 0x16B0);             //power control 1 BT,AP  
  LCD_WriteReg(0x11, 0x0037);             //power control 2 DC,VC
  delay(50); 
  LCD_WriteReg(0x12, 0x013E);             //power control 3 VRH
  delay(50); 
  LCD_WriteReg(0x13, 0x1A00);             //power control 4 vcom amplitude 
  LCD_WriteReg(0x29, 0x000F);             //power control 7 VCOMH
  delay(50); 
  LCD_WriteReg(0x20, 0x0000);              //Horizontal GRAM Address Set 
  LCD_WriteReg(0x21, 0x0000);              //Vertical GRAM Address Set 

  LCD_WriteReg(0x50, 0x0000);              //Horizontal Address Start Position 
  LCD_WriteReg(0x51, 0x00EF);              //Horizontal Address end Position (239) 
  LCD_WriteReg(0x52, 0x0000);              //Vertical Address Start Position 
  LCD_WriteReg(0x53, 0x013F);              //Vertical Address end Position (319)
 
 
  LCD_WriteReg(0x60, 0x2700);              //Driver Output Control 2 
//  LCD_WriteReg(0x61, 0x0001);              //Base Image Display Control 
  LCD_WriteReg(0x61, 0x0003);              //Base Image Display Control 
  LCD_WriteReg(0x6a, 0x0000);              //Base Image Display Control
 
  LCD_WriteReg(0x90, 0x0010);              //Panel Interface Control 1
  LCD_WriteReg(0x92, 0x0000);              //Panel Interface Control 2 
  LCD_WriteReg(0x93, 0x0000);              //Panel Interface Control 3

  /*** GAMMA Control ***/ 
  LCD_WriteReg(0x30, 0x0007);
  LCD_WriteReg(0x31, 0x0403);   
  LCD_WriteReg(0x32, 0x0404);
  LCD_WriteReg(0x35, 0x0002);
  LCD_WriteReg(0x36, 0x0707);
  LCD_WriteReg(0x37, 0x0606);
  LCD_WriteReg(0x38, 0x0106);
  LCD_WriteReg(0x39, 0x0007);
  LCD_WriteReg(0x3c, 0x0700);
  LCD_WriteReg(0x3d, 0x0707); 
 
  LCD_WriteReg(0x07, 0x0173);
 
  LCD_CS_HI;
 
  delay(30);
  LCD_CS_LO;  
}

void LCD_SetCursor(unsigned int x, unsigned int y)
{
if (x < 240 && y < 320) {
  #if LCD_ALIGNMENT == VERTICAL
    LCD_WriteReg(0x20, x);
    LCD_WriteReg(0x21, y);
  #elif LCD_ALIGNMENT == HORIZONTAL
    LCD_WriteReg(0x20, 240-y);
    LCD_WriteReg(0x21, x);
  #endif 

}

void LCD_Clear(unsigned int color)
{
  LCD_SetCursor(0,0);
  /*LCD_WriteIndex(0x22);
  for (long i=0; i <= 76799; i++){
    LCD_WriteData(color);
  }
  */
  LCD_SolidFill(76800, color);  // This is a faster method
}

void LCD_ResetWindow()
{
  LCD_WriteReg(0x50, 0x0000);              //Horizontal Address Start Position 
  LCD_WriteReg(0x51, 0x00EF);              //Horizontal Address end Position (239) 
  LCD_WriteReg(0x52, 0x0000);              //Vertical Address Start Position 
  LCD_WriteReg(0x53, 0x013F);              //Vertical Address end Position (319)
}

void LCD_PutPixel(byte x, unsigned int y, unsigned int color)
{
  LCD_SetCursor(x,y);
  LCD_WriteIndex(0x22);
  LCD_WriteData(color);

void LCD_HorLine(byte x1, byte x2, unsigned int y, unsigned int color)
{
if (x1 < 240 && x2 < 240 && y < 320) {
  LCD_SetCursor(x1,y);
  /*LCD_WriteIndex(0x22);
  for (byte i=x1; i < x2; i++){
    LCD_WriteData(color);
  }
  */
  LCD_SolidFill((x2-x1), color);  // This is a faster method

void LCD_VerLine(unsigned int y1, unsigned int y2, byte x, unsigned int color)
{
  LCD_SetCursor(x,y1);
  LCD_SetWindow(x,y1,x,y2);
  /*LCD_WriteIndex(0x22);
  for (byte i=x1; i < x2; i++){
    LCD_WriteData(color);
  }
  */
  LCD_SolidFill((y2-y1), color);  // This is a faster method
  LCD_ResetWindow();

void LCD_HardwareScroll(int y)
{
    while (y < 0)
        y += 320;
    while (y >= 320)
        y -= 320;
    LCD_WriteReg(0x6a,y);
}   

void LCD_Clear_ScrollUp(byte delay_between, unsigned int color)
{
  for (int i=1; i <= 320; i++) {   
    LCD_HardwareScroll(i);
    LCD_HorLine(0,239,i-1,color);   
    delay(delay_between);
  }
  LCD_HardwareScroll(0);

void LCD_Clear_ScrollDown(byte delay_between, unsigned int color)
{
  for (int i=-1; i >= -320; i--) {   
    LCD_HorLine(0,239,320+i,color); 
    LCD_HardwareScroll(i); 
    delay(delay_between);   
  }
  LCD_HardwareScroll(0); 
}

int LCD_DrawChar(byte xx, unsigned int yy, int c, unsigned int color)
{
    //byte* f = Verdana_font_11;
    if (c == 32)
        return FNT(1)>>2;  // Space is 1/4 font height (yuk);

    int i = c - FNT(3);
    if (i < 0 || i >= FNT(4)) return 0;

    int ci = 6 + i * 2;
    int width = (FNT(ci) << 8) | FNT(ci + 1);   // simplify
    int height = FNT(1);
    int src = 0;
    if (i > 0)
    {
        src = (FNT(ci - 2) << 8) | FNT(ci - 1);
        width -= src;
    }
   
    //  clip?
    src += (6 + 2 * FNT(4)) * 8;    // start of pixels (roll into cols)
    byte mask = 0x80 >> (src & 7);  // Mask at start of line
    int end = (src+width) >> 3;     // number of bytes read
    src >>= 3;
    int makeup = FNT(5) - (end + 1 - src);
    for (byte y = 0; y < (byte)height; y++)
    {
        byte p = FNT(src++);
        byte m = mask;
        for (byte x = 0; x < (byte)width; x++)
        {
            if (p & m)
                LCD_PutPixel(x + xx, y + yy, color);
            m >>= 1;
            if (m == 0)
            {
                p = FNT(src++);
                if (p == 0 && (width-x) <= 8)   // early out
                    break;
                m = 0x80;
            }
        }
        src += makeup;
    }
    return width;
}

void LCD_DrawString2(const char* s, int len, byte x, unsigned int y, unsigned int color)
{
    for (int i = 0; i < len; i++)
        x += LCD_DrawChar(x,y,s[i], color) + 1;
}

void LCD_DrawString(const char* s, byte x, unsigned int y, unsigned int color)
{
    LCD_DrawString2(s,strlen(s),x,y, color);
}

void LCD_SetWindow(byte x1, unsigned int y1, byte x2, unsigned int y2)
{
  #if LCD_ALIGNMENT == VERTICAL 
    LCD_WriteReg(0x50, x1);           //Horizontal Address Start Position 
    LCD_WriteReg(0x51, x2); //Horizontal Address end Position (239) 
    LCD_WriteReg(0x52, y1);           //Vertical Address Start Position 
    LCD_WriteReg(0x53, y2);//Vertical Address end Position (319)               
  #elif LCD_ALIGNMENT == HORIZONTAL
    #error "Windows Clearing in Horizontal mode is not possible yet!"
  #endif    
}

void LCD_Rectangle(byte x1, unsigned int y1, byte x2, unsigned int y2, int color)
{     
    LCD_SetWindow(x1,y1,x2,y2);
    LCD_SetCursor(x1,y1);
   
    byte width = x2-x1+1;
    unsigned int height = y2-y1+1;
    LCD_SolidFill(width*height, color);
    LCD_ResetWindow();
}

void LCD_SolidFill(unsigned long count, unsigned int color)
{
  // Write Index
  LCD_WriteIndex(0x22);
 
  // Write Data
  LCD_RS_HI;
  LCD = highByte(color);
  LCD_WR_LO;
  LCD_WR_HI;
  LCD = lowByte(color);
  LCD_WR_LO;
  LCD_WR_HI;
  LCD = 0;
 
  for (unsigned long i=0; i <= count-1; i++){
    // Write Data
    LCD = highByte(color);
    LCD_WR_LO;
    LCD_WR_HI;
    LCD = lowByte(color);
    LCD_WR_LO;
    LCD_WR_HI;
  }
}


写真