DL144128TF, 128dot x 128dot TFT LCD module driving program.

Dependencies:   mbed

128dot x 128dot TFT LCD表示

erecrowが販売しているTFTタイプのLCDモジュール、DL144128TFをmbedに接続してみました。

/media/uploads/morita/image_20140614132421a.jpg

Nokia5110 の同系モデルです。
このサイズでnokiaの流通品は殆どがCSTN(表記がTFTになっていたりして、売る方も混乱)に対し、こちらは本当のTFTです。
昨今のスマホ画面と比べるのは酷ですが、CSTNに比べると、さすがに綺麗です。

elecrowのページには、ライブラリが紹介されていますが、製品がSPIなのに、ライブラリはAVR用のパラレル接続になっています。
mbed用として、SPIに変更しました。
DL144128TFの信号名はSCKとSDAですが、SPIです。 I2C用の基板をそのまま流用したと思われます。
コントローラの信号説明とDL144128TFの信号名は一致しませんので、A0がレジスタ選択と推測しました。
LCDからのデータ出力線は無いようです。
このあたりは、かなり適当です。
元のライブラリで、lcdFilledRectangleプログラムのピクセル数計算が間違っていましたので、修正しました。

クラスを作らず、ライブラリをそのままmbedに持ち込みましたので、ピン番号設定のコンストラクタはありません。
ili9163lcd.cppを編集して、直接接続ピン番号を入れてください。

ili9163lcd.cppの37行目~

DigitalOut SCK_(D2);
DigitalOut SDA_(D3);
DigitalOut A0_(D4);
DigitalOut RESET_(D5);
DigitalOut CS_(D6);


デモ画面は基本オリジナルなままですが、Hello Worldは時間と共に、色が変化するようにしています。
プログラムの生死確認用にLD2(NUCLEO用)を点滅させています。

Committer:
morita
Date:
Sat Jun 14 02:27:06 2014 +0000
Revision:
0:c0be4e018a09
DL144128TF driving Test.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
morita 0:c0be4e018a09 1 /**
morita 0:c0be4e018a09 2 * @file ili9163lcd.h
morita 0:c0be4e018a09 3 * @brief ILI9163 128x128 LCD Driver (Header file)
morita 0:c0be4e018a09 4 *
morita 0:c0be4e018a09 5 * This code has been ported from the ili9163lcd library for mbed
morita 0:c0be4e018a09 6 * made by Jun Morita.
morita 0:c0be4e018a09 7 * Source form <http://files.noccylabs.info/lib430/liblcd/ili9163lcd_8c.html>
morita 0:c0be4e018a09 8 *
morita 0:c0be4e018a09 9 * This code has been ported from the ili9163lcd library for avr made
morita 0:c0be4e018a09 10 * by Simon Inns, to run on a msp430.
morita 0:c0be4e018a09 11 *
morita 0:c0be4e018a09 12 * This program is free software: you can redistribute it and/or modify
morita 0:c0be4e018a09 13 * it under the terms of the GNU General Public License as published by
morita 0:c0be4e018a09 14 * the Free Software Foundation, either version 3 of the License, or
morita 0:c0be4e018a09 15 * (at your option) any later version.
morita 0:c0be4e018a09 16 *
morita 0:c0be4e018a09 17 * This program is distributed in the hope that it will be useful,
morita 0:c0be4e018a09 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
morita 0:c0be4e018a09 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
morita 0:c0be4e018a09 20 * GNU General Public License for more details.
morita 0:c0be4e018a09 21 *
morita 0:c0be4e018a09 22 * You should have received a copy of the GNU General Public License
morita 0:c0be4e018a09 23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
morita 0:c0be4e018a09 24 *
morita 0:c0be4e018a09 25 * @author Jun Morita (iccraft)
morita 0:c0be4e018a09 26 * @author Simon Inns <simon.inns@gmail.com>
morita 0:c0be4e018a09 27 * @author Christopher Vagnetoft (NoccyLabs)
morita 0:c0be4e018a09 28 * @copyright (C) 2012 Simon Inns
morita 0:c0be4e018a09 29 * @copyright parts (C) 2012 NoccyLabs
morita 0:c0be4e018a09 30 */
morita 0:c0be4e018a09 31
morita 0:c0be4e018a09 32 #ifndef ILI9163LCD_H_
morita 0:c0be4e018a09 33 #define ILI9163LCD_H_
morita 0:c0be4e018a09 34
morita 0:c0be4e018a09 35 // Definitions for control lines (port C)
morita 0:c0be4e018a09 36 #define LCD_WR (1 << 2)
morita 0:c0be4e018a09 37 #define LCD_RS (1 << 4)
morita 0:c0be4e018a09 38 #define LCD_RD (1 << 5)
morita 0:c0be4e018a09 39 #define LCD_CS (1 << 6)
morita 0:c0be4e018a09 40 #define LCD_RESET (1 << 7)
morita 0:c0be4e018a09 41
morita 0:c0be4e018a09 42 // Screen orientation defines:
morita 0:c0be4e018a09 43 // 0 = Ribbon at top
morita 0:c0be4e018a09 44 // 1 = Ribbon at left
morita 0:c0be4e018a09 45 // 2 = Ribbon at right
morita 0:c0be4e018a09 46 // 3 = Ribbon at bottom
morita 0:c0be4e018a09 47 #define LCD_ORIENTATION0 0
morita 0:c0be4e018a09 48 #define LCD_ORIENTATION1 96
morita 0:c0be4e018a09 49 #define LCD_ORIENTATION2 160
morita 0:c0be4e018a09 50 #define LCD_ORIENTATION3 192
morita 0:c0be4e018a09 51
morita 0:c0be4e018a09 52 // ILI9163 LCD Controller Commands
morita 0:c0be4e018a09 53 #define NOP 0x00
morita 0:c0be4e018a09 54 #define SOFT_RESET 0x01
morita 0:c0be4e018a09 55 #define GET_RED_CHANNEL 0x06
morita 0:c0be4e018a09 56 #define GET_GREEN_CHANNEL 0x07
morita 0:c0be4e018a09 57 #define GET_BLUE_CHANNEL 0x08
morita 0:c0be4e018a09 58 #define GET_PIXEL_FORMAT 0x0C
morita 0:c0be4e018a09 59 #define GET_POWER_MODE 0x0A
morita 0:c0be4e018a09 60 #define GET_ADDRESS_MODE 0x0B
morita 0:c0be4e018a09 61 #define GET_DISPLAY_MODE 0x0D
morita 0:c0be4e018a09 62 #define GET_SIGNAL_MODE 0x0E
morita 0:c0be4e018a09 63 #define GET_DIAGNOSTIC_RESULT 0x0F
morita 0:c0be4e018a09 64 #define ENTER_SLEEP_MODE 0x10
morita 0:c0be4e018a09 65 #define EXIT_SLEEP_MODE 0x11
morita 0:c0be4e018a09 66 #define ENTER_PARTIAL_MODE 0x12
morita 0:c0be4e018a09 67 #define ENTER_NORMAL_MODE 0x13
morita 0:c0be4e018a09 68 #define EXIT_INVERT_MODE 0x20
morita 0:c0be4e018a09 69 #define ENTER_INVERT_MODE 0x21
morita 0:c0be4e018a09 70 #define SET_GAMMA_CURVE 0x26
morita 0:c0be4e018a09 71 #define SET_DISPLAY_OFF 0x28
morita 0:c0be4e018a09 72 #define SET_DISPLAY_ON 0x29
morita 0:c0be4e018a09 73 #define SET_COLUMN_ADDRESS 0x2A
morita 0:c0be4e018a09 74 #define SET_PAGE_ADDRESS 0x2B
morita 0:c0be4e018a09 75 #define WRITE_MEMORY_START 0x2C
morita 0:c0be4e018a09 76 #define WRITE_LUT 0x2D
morita 0:c0be4e018a09 77 #define READ_MEMORY_START 0x2E
morita 0:c0be4e018a09 78 #define SET_PARTIAL_AREA 0x30
morita 0:c0be4e018a09 79 #define SET_SCROLL_AREA 0x33
morita 0:c0be4e018a09 80 #define SET_TEAR_OFF 0x34
morita 0:c0be4e018a09 81 #define SET_TEAR_ON 0x35
morita 0:c0be4e018a09 82 #define SET_ADDRESS_MODE 0x36
morita 0:c0be4e018a09 83 #define SET_SCROLL_START 0X37
morita 0:c0be4e018a09 84 #define EXIT_IDLE_MODE 0x38
morita 0:c0be4e018a09 85 #define ENTER_IDLE_MODE 0x39
morita 0:c0be4e018a09 86 #define SET_PIXEL_FORMAT 0x3A
morita 0:c0be4e018a09 87 #define WRITE_MEMORY_CONTINUE 0x3C
morita 0:c0be4e018a09 88 #define READ_MEMORY_CONTINUE 0x3E
morita 0:c0be4e018a09 89 #define SET_TEAR_SCANLINE 0x44
morita 0:c0be4e018a09 90 #define GET_SCANLINE 0x45
morita 0:c0be4e018a09 91 #define READ_ID1 0xDA
morita 0:c0be4e018a09 92 #define READ_ID2 0xDB
morita 0:c0be4e018a09 93 #define READ_ID3 0xDC
morita 0:c0be4e018a09 94 #define FRAME_RATE_CONTROL1 0xB1
morita 0:c0be4e018a09 95 #define FRAME_RATE_CONTROL2 0xB2
morita 0:c0be4e018a09 96 #define FRAME_RATE_CONTROL3 0xB3
morita 0:c0be4e018a09 97 #define DISPLAY_INVERSION 0xB4
morita 0:c0be4e018a09 98 #define SOURCE_DRIVER_DIRECTION 0xB7
morita 0:c0be4e018a09 99 #define GATE_DRIVER_DIRECTION 0xB8
morita 0:c0be4e018a09 100 #define POWER_CONTROL1 0xC0
morita 0:c0be4e018a09 101 #define POWER_CONTROL2 0xC1
morita 0:c0be4e018a09 102 #define POWER_CONTROL3 0xC2
morita 0:c0be4e018a09 103 #define POWER_CONTROL4 0xC3
morita 0:c0be4e018a09 104 #define POWER_CONTROL5 0xC4
morita 0:c0be4e018a09 105 #define VCOM_CONTROL1 0xC5
morita 0:c0be4e018a09 106 #define VCOM_CONTROL2 0xC6
morita 0:c0be4e018a09 107 #define VCOM_OFFSET_CONTROL 0xC7
morita 0:c0be4e018a09 108 #define WRITE_ID4_VALUE 0xD3
morita 0:c0be4e018a09 109 #define NV_MEMORY_FUNCTION1 0xD7
morita 0:c0be4e018a09 110 #define NV_MEMORY_FUNCTION2 0xDE
morita 0:c0be4e018a09 111 #define POSITIVE_GAMMA_CORRECT 0xE0
morita 0:c0be4e018a09 112 #define NEGATIVE_GAMMA_CORRECT 0xE1
morita 0:c0be4e018a09 113 #define GAM_R_SEL 0xF2
morita 0:c0be4e018a09 114
morita 0:c0be4e018a09 115 // Macros and in-lines:
morita 0:c0be4e018a09 116
morita 0:c0be4e018a09 117 // Translates a 3 byte RGB value into a 2 byte value for the LCD (values should be 0-31)
morita 0:c0be4e018a09 118 inline uint16_t decodeRgbValue(uint8_t r, uint8_t g, uint8_t b)
morita 0:c0be4e018a09 119 {
morita 0:c0be4e018a09 120 return (b << 11) | (g << 6) | (r);
morita 0:c0be4e018a09 121 }
morita 0:c0be4e018a09 122
morita 0:c0be4e018a09 123 // This routine takes a row number from 0 to 20 and
morita 0:c0be4e018a09 124 // returns the x coordinate on the screen (0-127) to make
morita 0:c0be4e018a09 125 // it easy to place text
morita 0:c0be4e018a09 126 inline uint8_t lcdTextX(uint8_t x) { return x*6; }
morita 0:c0be4e018a09 127
morita 0:c0be4e018a09 128 // This routine takes a column number from 0 to 20 and
morita 0:c0be4e018a09 129 // returns the y coordinate on the screen (0-127) to make
morita 0:c0be4e018a09 130 // it easy to place text
morita 0:c0be4e018a09 131 inline uint8_t lcdTextY(uint8_t y) { return y*8; }
morita 0:c0be4e018a09 132
morita 0:c0be4e018a09 133 // LCD function prototypes
morita 0:c0be4e018a09 134 void lcdReset(void);
morita 0:c0be4e018a09 135 void lcdWriteCommand(uint8_t address);
morita 0:c0be4e018a09 136 void lcdWriteParameter(uint8_t parameter);
morita 0:c0be4e018a09 137 void lcdWriteData(uint8_t dataByte1, uint8_t dataByte2);
morita 0:c0be4e018a09 138 void lcdInitialise(uint8_t orientation);
morita 0:c0be4e018a09 139
morita 0:c0be4e018a09 140 void lcdClearDisplay(uint16_t colour);
morita 0:c0be4e018a09 141 void lcdPlot(uint8_t x, uint8_t y, uint16_t colour);
morita 0:c0be4e018a09 142 void lcdLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t colour);
morita 0:c0be4e018a09 143 void lcdRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t colour);
morita 0:c0be4e018a09 144 void lcdFilledRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t colour);
morita 0:c0be4e018a09 145 void lcdCircle(int16_t xCentre, int16_t yCentre, int16_t radius, uint16_t colour);
morita 0:c0be4e018a09 146
morita 0:c0be4e018a09 147 void lcdPutCh(unsigned char character, uint8_t x, uint8_t y, uint16_t fgColour, uint16_t bgColour);
morita 0:c0be4e018a09 148 void lcdPutS(const char *string, uint8_t x, uint8_t y, uint16_t fgColour, uint16_t bgColour);
morita 0:c0be4e018a09 149
morita 0:c0be4e018a09 150 #endif /* ILI9163LCD_H_ */