Aitendo 1.44inch TFT ZY-FGD1442701V1(ST7735S)を駆動させる. BusOutで接続. Bitmap画像をSDカードから読み込み. Connected with BusOut. Bitmap data read from SD(SDHC) card.

Dependencies:   FatFileSystemCpp SDHC_FileSystem mbed

AitendoのTFT液晶モジュール ZY-FGD1442701V1 (ST7735S搭載版) http://www.aitendo.com/product/1621をmbedで動作させるサンプル。

bmp565形式のsample画像

_spi.frequencyを32MHzにするとfreadが高速化します。

SDHCFileSystem.cpp

230:    _spi.frequency(32000000);
Committer:
9SQ
Date:
Wed Nov 19 13:08:24 2014 +0000
Revision:
0:80e5869332ba
initial commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
9SQ 0:80e5869332ba 1 #include "mbed.h"
9SQ 0:80e5869332ba 2 #include "SDHCFileSystem.h"
9SQ 0:80e5869332ba 3
9SQ 0:80e5869332ba 4 Serial pc(USBTX, USBRX);
9SQ 0:80e5869332ba 5 SDFileSystem sd(p5, p6, p7, p8, "sd");
9SQ 0:80e5869332ba 6
9SQ 0:80e5869332ba 7 DigitalOut CS0(p21);
9SQ 0:80e5869332ba 8 DigitalOut CD(p22);
9SQ 0:80e5869332ba 9 DigitalOut RD(p23);
9SQ 0:80e5869332ba 10 DigitalOut WR(p24);
9SQ 0:80e5869332ba 11 DigitalOut RSTB(p25);
9SQ 0:80e5869332ba 12
9SQ 0:80e5869332ba 13 BusOut Bout(p17, p16, p15, p14, p13, p12, p11, p10);
9SQ 0:80e5869332ba 14
9SQ 0:80e5869332ba 15 Timer t;
9SQ 0:80e5869332ba 16
9SQ 0:80e5869332ba 17 void LCD_Write_CMD(unsigned char cmd)
9SQ 0:80e5869332ba 18 {
9SQ 0:80e5869332ba 19 CS0=0;
9SQ 0:80e5869332ba 20 RD=1;
9SQ 0:80e5869332ba 21 CD=0;
9SQ 0:80e5869332ba 22 Bout=cmd;
9SQ 0:80e5869332ba 23 WR=0;
9SQ 0:80e5869332ba 24 WR=1;
9SQ 0:80e5869332ba 25 CS0=1;
9SQ 0:80e5869332ba 26 }
9SQ 0:80e5869332ba 27
9SQ 0:80e5869332ba 28 void LCD_Write_Data(unsigned char d)
9SQ 0:80e5869332ba 29 {
9SQ 0:80e5869332ba 30 CS0=0;
9SQ 0:80e5869332ba 31 RD=1;
9SQ 0:80e5869332ba 32 CD=1;
9SQ 0:80e5869332ba 33 Bout=d;
9SQ 0:80e5869332ba 34 WR=0;
9SQ 0:80e5869332ba 35 WR=1;
9SQ 0:80e5869332ba 36 CS0=1;
9SQ 0:80e5869332ba 37 }
9SQ 0:80e5869332ba 38
9SQ 0:80e5869332ba 39 void LCD_Reset(void)
9SQ 0:80e5869332ba 40 {
9SQ 0:80e5869332ba 41 RSTB=1;
9SQ 0:80e5869332ba 42 wait_ms(1);
9SQ 0:80e5869332ba 43 RSTB=0;
9SQ 0:80e5869332ba 44 wait_ms(1);
9SQ 0:80e5869332ba 45 RSTB=1;
9SQ 0:80e5869332ba 46 wait_ms(120);
9SQ 0:80e5869332ba 47 LCD_Write_CMD(0x11); // Sleep Out and Booster On
9SQ 0:80e5869332ba 48 wait_ms(120);
9SQ 0:80e5869332ba 49 }
9SQ 0:80e5869332ba 50
9SQ 0:80e5869332ba 51 void LCD_Init(void)
9SQ 0:80e5869332ba 52 {
9SQ 0:80e5869332ba 53 LCD_Reset();
9SQ 0:80e5869332ba 54
9SQ 0:80e5869332ba 55 LCD_Write_CMD(0xB1); //In Normal Mode(Full Colors) Frame rate 80Hz
9SQ 0:80e5869332ba 56 LCD_Write_Data(0x02);
9SQ 0:80e5869332ba 57 LCD_Write_Data(0x35);
9SQ 0:80e5869332ba 58 LCD_Write_Data(0x36);
9SQ 0:80e5869332ba 59
9SQ 0:80e5869332ba 60 LCD_Write_CMD(0xB2); //In Idle Mode(8-colors)
9SQ 0:80e5869332ba 61 LCD_Write_Data(0x02);
9SQ 0:80e5869332ba 62 LCD_Write_Data(0x35);
9SQ 0:80e5869332ba 63 LCD_Write_Data(0x36);
9SQ 0:80e5869332ba 64
9SQ 0:80e5869332ba 65 LCD_Write_CMD(0xB3); //In Partial Mode + Full Colors
9SQ 0:80e5869332ba 66 LCD_Write_Data(0x02);
9SQ 0:80e5869332ba 67 LCD_Write_Data(0x35);
9SQ 0:80e5869332ba 68 LCD_Write_Data(0x36);
9SQ 0:80e5869332ba 69 LCD_Write_Data(0x02);
9SQ 0:80e5869332ba 70 LCD_Write_Data(0x35);
9SQ 0:80e5869332ba 71 LCD_Write_Data(0x36);
9SQ 0:80e5869332ba 72
9SQ 0:80e5869332ba 73 LCD_Write_CMD(0xB4); //Dot Inversion Control
9SQ 0:80e5869332ba 74 LCD_Write_Data(0x03); // Inversion setting in Idle mode and full Colors partial mode
9SQ 0:80e5869332ba 75
9SQ 0:80e5869332ba 76 LCD_Write_CMD(0xC0); // Power Control Setting (GVDD Voltage)
9SQ 0:80e5869332ba 77 LCD_Write_Data(0xA2); // AVDD=5, GVDD=4.6
9SQ 0:80e5869332ba 78 LCD_Write_Data(0x02); // VGCL=-4.6
9SQ 0:80e5869332ba 79 LCD_Write_Data(0x84); // MODE=AUTO
9SQ 0:80e5869332ba 80
9SQ 0:80e5869332ba 81 LCD_Write_CMD(0xC1); // Power Control Setting (VGH/VGL Voltage)
9SQ 0:80e5869332ba 82 LCD_Write_Data(0xC5); // VGH and VGL supply power level = 2.4, VGL=-10, VGH=3*AVDD-0.5
9SQ 0:80e5869332ba 83
9SQ 0:80e5869332ba 84 LCD_Write_CMD(0xC2); // In Normal Mode(Full Colors) APA/DCA
9SQ 0:80e5869332ba 85 LCD_Write_Data(0x0D); // SAP=Small, AP=Large
9SQ 0:80e5869332ba 86 LCD_Write_Data(0x00); // Clock frequency for Booster circuit/1,/3,/1,/1,/1
9SQ 0:80e5869332ba 87
9SQ 0:80e5869332ba 88 LCD_Write_CMD(0xC3); // In Idle Mode(8-colors) APA/DCA
9SQ 0:80e5869332ba 89 LCD_Write_Data(0x8D);
9SQ 0:80e5869332ba 90 LCD_Write_Data(0xEA);
9SQ 0:80e5869332ba 91
9SQ 0:80e5869332ba 92 LCD_Write_CMD(0xC4); // In Partial Mode(Full Colors) APA/DCA
9SQ 0:80e5869332ba 93 LCD_Write_Data(0x8D);
9SQ 0:80e5869332ba 94 LCD_Write_Data(0xEE);
9SQ 0:80e5869332ba 95
9SQ 0:80e5869332ba 96 LCD_Write_CMD(0xC5); // VCOM
9SQ 0:80e5869332ba 97 LCD_Write_Data(0x05); // -0.55
9SQ 0:80e5869332ba 98
9SQ 0:80e5869332ba 99 LCD_Write_CMD(0x36); // Memory Data Access Control
9SQ 0:80e5869332ba 100 LCD_Write_Data(0x48); // MX, RGB mode (Row Address Order, RGB color filter panel)
9SQ 0:80e5869332ba 101
9SQ 0:80e5869332ba 102 LCD_Write_CMD(0xE0); // Gamma Adjustment (+Polarity)
9SQ 0:80e5869332ba 103 LCD_Write_Data(0x03);
9SQ 0:80e5869332ba 104 LCD_Write_Data(0x1B);
9SQ 0:80e5869332ba 105 LCD_Write_Data(0x09);
9SQ 0:80e5869332ba 106 LCD_Write_Data(0x0E);
9SQ 0:80e5869332ba 107 LCD_Write_Data(0x32);
9SQ 0:80e5869332ba 108 LCD_Write_Data(0x2D);
9SQ 0:80e5869332ba 109 LCD_Write_Data(0x28);
9SQ 0:80e5869332ba 110 LCD_Write_Data(0x2C);
9SQ 0:80e5869332ba 111 LCD_Write_Data(0x2B);
9SQ 0:80e5869332ba 112 LCD_Write_Data(0x29);
9SQ 0:80e5869332ba 113 LCD_Write_Data(0x30);
9SQ 0:80e5869332ba 114 LCD_Write_Data(0x3B);
9SQ 0:80e5869332ba 115 LCD_Write_Data(0x00);
9SQ 0:80e5869332ba 116 LCD_Write_Data(0x01);
9SQ 0:80e5869332ba 117 LCD_Write_Data(0x02);
9SQ 0:80e5869332ba 118 LCD_Write_Data(0x10);
9SQ 0:80e5869332ba 119
9SQ 0:80e5869332ba 120 LCD_Write_CMD(0xE1); // Gamma Adjustment (-Polarity)
9SQ 0:80e5869332ba 121 LCD_Write_Data(0x03);
9SQ 0:80e5869332ba 122 LCD_Write_Data(0x1B);
9SQ 0:80e5869332ba 123 LCD_Write_Data(0x09);
9SQ 0:80e5869332ba 124 LCD_Write_Data(0x0E);
9SQ 0:80e5869332ba 125 LCD_Write_Data(0x32);
9SQ 0:80e5869332ba 126 LCD_Write_Data(0x2E);
9SQ 0:80e5869332ba 127 LCD_Write_Data(0x28);
9SQ 0:80e5869332ba 128 LCD_Write_Data(0x2C);
9SQ 0:80e5869332ba 129 LCD_Write_Data(0x2B);
9SQ 0:80e5869332ba 130 LCD_Write_Data(0x28);
9SQ 0:80e5869332ba 131 LCD_Write_Data(0x31);
9SQ 0:80e5869332ba 132 LCD_Write_Data(0x3C);
9SQ 0:80e5869332ba 133 LCD_Write_Data(0x00);
9SQ 0:80e5869332ba 134 LCD_Write_Data(0x00);
9SQ 0:80e5869332ba 135 LCD_Write_Data(0x02);
9SQ 0:80e5869332ba 136 LCD_Write_Data(0x10);
9SQ 0:80e5869332ba 137
9SQ 0:80e5869332ba 138 LCD_Write_CMD(0x3A); // Interface Pixel Format
9SQ 0:80e5869332ba 139 LCD_Write_Data(0x05); // 16-bit/pixel
9SQ 0:80e5869332ba 140
9SQ 0:80e5869332ba 141 LCD_Write_CMD(0x2A); // Column Address Set
9SQ 0:80e5869332ba 142 LCD_Write_Data(0x00);
9SQ 0:80e5869332ba 143 LCD_Write_Data(0x02);
9SQ 0:80e5869332ba 144 LCD_Write_Data(0x00);
9SQ 0:80e5869332ba 145 LCD_Write_Data(0x81);
9SQ 0:80e5869332ba 146
9SQ 0:80e5869332ba 147 LCD_Write_CMD(0x2B); // Row Address Set
9SQ 0:80e5869332ba 148 LCD_Write_Data(0x00);
9SQ 0:80e5869332ba 149 LCD_Write_Data(0x01);
9SQ 0:80e5869332ba 150 LCD_Write_Data(0x00);
9SQ 0:80e5869332ba 151 LCD_Write_Data(0x80);
9SQ 0:80e5869332ba 152
9SQ 0:80e5869332ba 153 wait_ms(100);
9SQ 0:80e5869332ba 154 LCD_Write_CMD(0x2C); // Memory Write
9SQ 0:80e5869332ba 155
9SQ 0:80e5869332ba 156 }
9SQ 0:80e5869332ba 157
9SQ 0:80e5869332ba 158 void LCD_Enter_Sleep(void)
9SQ 0:80e5869332ba 159 {
9SQ 0:80e5869332ba 160 LCD_Write_CMD(0x10); //Sleep in
9SQ 0:80e5869332ba 161 wait_ms(120);
9SQ 0:80e5869332ba 162 }
9SQ 0:80e5869332ba 163 void LCD_Exit_Sleep(void)
9SQ 0:80e5869332ba 164 {
9SQ 0:80e5869332ba 165 LCD_Write_CMD(0x11); //Sleep out
9SQ 0:80e5869332ba 166 wait_ms(120);
9SQ 0:80e5869332ba 167 }
9SQ 0:80e5869332ba 168
9SQ 0:80e5869332ba 169 void LCD_Fill_Black(void)
9SQ 0:80e5869332ba 170 {
9SQ 0:80e5869332ba 171 t.start();
9SQ 0:80e5869332ba 172 LCD_Write_CMD(0x2C); // Memory Write
9SQ 0:80e5869332ba 173 for (int i=0; i<128; i++) {
9SQ 0:80e5869332ba 174 for (int j=0; j<128*2; j++) {
9SQ 0:80e5869332ba 175 LCD_Write_Data(0x00);
9SQ 0:80e5869332ba 176 }
9SQ 0:80e5869332ba 177 }
9SQ 0:80e5869332ba 178 LCD_Write_CMD(0x29); // Display On
9SQ 0:80e5869332ba 179 t.stop();
9SQ 0:80e5869332ba 180 pc.printf("Fill Black %dms\r\n",t.read_ms());
9SQ 0:80e5869332ba 181 t.reset();
9SQ 0:80e5869332ba 182 }
9SQ 0:80e5869332ba 183
9SQ 0:80e5869332ba 184 void LCD_Fill_White(void)
9SQ 0:80e5869332ba 185 {
9SQ 0:80e5869332ba 186 t.start();
9SQ 0:80e5869332ba 187 LCD_Write_CMD(0x2C); // Memory Write
9SQ 0:80e5869332ba 188 for (int i=0; i<128; i++) {
9SQ 0:80e5869332ba 189 for (int j=0; j<128*2; j++) {
9SQ 0:80e5869332ba 190 LCD_Write_Data(0xFF);
9SQ 0:80e5869332ba 191 }
9SQ 0:80e5869332ba 192 }
9SQ 0:80e5869332ba 193 LCD_Write_CMD(0x29); // Display On
9SQ 0:80e5869332ba 194 t.stop();
9SQ 0:80e5869332ba 195 pc.printf("Fill White %dms\r\n",t.read_ms());
9SQ 0:80e5869332ba 196 t.reset();
9SQ 0:80e5869332ba 197 }
9SQ 0:80e5869332ba 198
9SQ 0:80e5869332ba 199 void LCD_Print_Bitmap(char path[32])
9SQ 0:80e5869332ba 200 {
9SQ 0:80e5869332ba 201 t.start();
9SQ 0:80e5869332ba 202 FILE *fp;
9SQ 0:80e5869332ba 203 int i,j;
9SQ 0:80e5869332ba 204 unsigned char offset;
9SQ 0:80e5869332ba 205 unsigned short pixel[128];
9SQ 0:80e5869332ba 206
9SQ 0:80e5869332ba 207 if ((fp=fopen(path, "rb")) == NULL) {
9SQ 0:80e5869332ba 208 LCD_Fill_Black();
9SQ 0:80e5869332ba 209 exit(1);
9SQ 0:80e5869332ba 210 }
9SQ 0:80e5869332ba 211
9SQ 0:80e5869332ba 212 //LCD_Write_CMD(0x28); // Display Off
9SQ 0:80e5869332ba 213
9SQ 0:80e5869332ba 214 fseek(fp, 0x0a, SEEK_SET);
9SQ 0:80e5869332ba 215 fread(&offset, 1, 1, fp);
9SQ 0:80e5869332ba 216 fseek(fp, offset, SEEK_SET);
9SQ 0:80e5869332ba 217
9SQ 0:80e5869332ba 218 LCD_Write_CMD(0x2C); // Memory Write
9SQ 0:80e5869332ba 219
9SQ 0:80e5869332ba 220 for (i=0; i<128; i++) {
9SQ 0:80e5869332ba 221 fread(&pixel, 2, 128, fp);
9SQ 0:80e5869332ba 222 for(j=0;j<128;j++){
9SQ 0:80e5869332ba 223 LCD_Write_Data((unsigned char)((pixel[j] & 0xFFFF) >> 8));
9SQ 0:80e5869332ba 224 LCD_Write_Data((unsigned char)pixel[j]);
9SQ 0:80e5869332ba 225 }
9SQ 0:80e5869332ba 226 }
9SQ 0:80e5869332ba 227
9SQ 0:80e5869332ba 228 LCD_Write_CMD(0x29); // Display On
9SQ 0:80e5869332ba 229
9SQ 0:80e5869332ba 230 fclose(fp);
9SQ 0:80e5869332ba 231 t.stop();
9SQ 0:80e5869332ba 232 pc.printf("Print Bitmap %dms\r\n",t.read_ms());
9SQ 0:80e5869332ba 233 t.reset();
9SQ 0:80e5869332ba 234 }
9SQ 0:80e5869332ba 235
9SQ 0:80e5869332ba 236 int main()
9SQ 0:80e5869332ba 237 {
9SQ 0:80e5869332ba 238 LCD_Init();
9SQ 0:80e5869332ba 239 pc.baud(115200);
9SQ 0:80e5869332ba 240
9SQ 0:80e5869332ba 241 if (sd.disk_initialize()){
9SQ 0:80e5869332ba 242 pc.printf("error\r\n");
9SQ 0:80e5869332ba 243 LCD_Fill_Black();
9SQ 0:80e5869332ba 244 exit(1);
9SQ 0:80e5869332ba 245 }
9SQ 0:80e5869332ba 246
9SQ 0:80e5869332ba 247 while(1) {
9SQ 0:80e5869332ba 248 LCD_Print_Bitmap("/sd/sample.bmp");
9SQ 0:80e5869332ba 249 wait(5);
9SQ 0:80e5869332ba 250 LCD_Print_Bitmap("/sd/sample2.bmp");
9SQ 0:80e5869332ba 251 wait(5);
9SQ 0:80e5869332ba 252 LCD_Print_Bitmap("/sd/sample3.bmp");
9SQ 0:80e5869332ba 253 wait(5);
9SQ 0:80e5869332ba 254 }
9SQ 0:80e5869332ba 255 }