![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Using touch screen features of LCD screen.
Dependencies: DmTouch_UniGraphic UniGraphic mbed
Fork of DisplayModule24_demo by
main.cpp@5:c69049e461b7, 2015-03-23 (annotated)
- Committer:
- Geremia
- Date:
- Mon Mar 23 16:02:02 2015 +0000
- Revision:
- 5:c69049e461b7
- Parent:
- 4:818956c30cae
- Child:
- 6:6b6e93790b4c
Add ILI9325 test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Geremia | 0:2ccd65a72ab8 | 1 | #include "stdio.h" |
Geremia | 0:2ccd65a72ab8 | 2 | #include "mbed.h" |
Geremia | 0:2ccd65a72ab8 | 3 | #include "string" |
Geremia | 0:2ccd65a72ab8 | 4 | #include "Arial12x12.h" |
Geremia | 0:2ccd65a72ab8 | 5 | #include "Arial24x23.h" |
Geremia | 0:2ccd65a72ab8 | 6 | //#include "Terminal6x8.h" |
Geremia | 0:2ccd65a72ab8 | 7 | #include "Arial43x48_numb.h" |
Geremia | 0:2ccd65a72ab8 | 8 | #include "pict.h" |
Geremia | 4:818956c30cae | 9 | #include "pavement_48x34.h" |
Geremia | 0:2ccd65a72ab8 | 10 | |
Geremia | 1:083257298075 | 11 | //#include "IST3020.h" |
Geremia | 0:2ccd65a72ab8 | 12 | //#include "UC1608.h" |
Geremia | 5:c69049e461b7 | 13 | //#include "ST7565.h" |
Geremia | 5:c69049e461b7 | 14 | #include "ILI932x.h" |
Geremia | 5:c69049e461b7 | 15 | //#include "ILI9341.h" |
Geremia | 2:2b781c215ac0 | 16 | //#include "ILI9486.h" |
Geremia | 2:2b781c215ac0 | 17 | //#include "TFT_MIPI.h" |
Geremia | 4:818956c30cae | 18 | //#include "SSD1306.h" |
Geremia | 0:2ccd65a72ab8 | 19 | |
Geremia | 0:2ccd65a72ab8 | 20 | Serial pc(USBTX, USBRX); |
Geremia | 0:2ccd65a72ab8 | 21 | |
Geremia | 4:818956c30cae | 22 | //IST3020 myLCD(PAR_8, PortC, PC_8, PC_9, PA_0, PA_1, PA_4,"myLCD", 192, 64); // Parallel 8bit, Port, CS, reset, A0, WR, RD for F302 |
Geremia | 4:818956c30cae | 23 | //UC1608 myLCD(SPI_16, 10000000, D11, D12, D13, D10, D9, D8,"myLCD", 240, 120); // Spi 16bit, 10MHz, mosi, miso, sclk, cs, reset, dc |
Geremia | 5:c69049e461b7 | 24 | //ST7565 myLCD(PAR_8, PortC, PC_8, PC_9, PA_0, PA_1, PA_4,"myLCD", 128, 64); // Parallel 8bit, Port, CS, reset, A0, WR, RD |
Geremia | 5:c69049e461b7 | 25 | ILI932x myLCD(PAR_8, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 8bit, Port, CS, reset, RS, WR, RD for F401 |
Geremia | 5:c69049e461b7 | 26 | //ILI932x myLCD(SPI_16, 10000000, D11, D12, D13, D10, D9,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset |
Geremia | 5:c69049e461b7 | 27 | //ILI9341 myLCD(SPI_16, 12000000, D11, D12, D13, D10, D9, D8,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset, dc |
Geremia | 5:c69049e461b7 | 28 | //ILI9341 myLCD(PAR_16, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 16bit, Port, CS, reset, DC, WR, RD for F401 |
Geremia | 5:c69049e461b7 | 29 | //ILI9486 myLCD(PAR_16, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 16bit, Port, CS, reset, DC, WR, RD for F401 |
Geremia | 5:c69049e461b7 | 30 | //TFT_MIPI myLCD(PAR_16, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 16bit, Port, CS, reset, DC, WR, RD for F401 |
Geremia | 4:818956c30cae | 31 | //SSD1306 myLCD(SPI_16, 10000000, D11, D12, D13, D10, D9, D8,"myLCD", 240, 120); // Spi 16bit, 10MHz, mosi, miso, sclk, cs, reset, dc |
Geremia | 5:c69049e461b7 | 32 | //ILI9486 myLCD(SPI_8, 12000000, PA_7, PA_6, PA_5, PB_6, PA_8, PA_9,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset, dc for minimaple |
Geremia | 5:c69049e461b7 | 33 | //ILI9341 myLCD(SPI_8, 12000000, PA_7, PA_6, PA_5, PB_6, PA_8, PA_9,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset, dc for minimaple |
Geremia | 0:2ccd65a72ab8 | 34 | |
Geremia | 0:2ccd65a72ab8 | 35 | Timer t; |
Geremia | 0:2ccd65a72ab8 | 36 | |
Geremia | 5:c69049e461b7 | 37 | //unsigned short backgroundcolor=White; |
Geremia | 5:c69049e461b7 | 38 | //unsigned short foregroundcolor=Black; |
Geremia | 0:2ccd65a72ab8 | 39 | unsigned short backgroundcolor=Black; |
Geremia | 0:2ccd65a72ab8 | 40 | unsigned short foregroundcolor=White; |
Geremia | 0:2ccd65a72ab8 | 41 | |
Geremia | 0:2ccd65a72ab8 | 42 | char orient=1; |
Geremia | 0:2ccd65a72ab8 | 43 | int main() |
Geremia | 0:2ccd65a72ab8 | 44 | { |
Geremia | 4:818956c30cae | 45 | // myLCD.set_contrast(26);//for uc1608 |
Geremia | 4:818956c30cae | 46 | // myLCD.set_contrast(46);//for ist3020 |
Geremia | 4:818956c30cae | 47 | myLCD.set_orientation(orient); |
Geremia | 3:65af1a9fedda | 48 | int time, time2; |
Geremia | 0:2ccd65a72ab8 | 49 | pc.baud (115200); |
Geremia | 0:2ccd65a72ab8 | 50 | pc.printf("\n\nSystem Core Clock = %.3f MHZ\r\n",(float)SystemCoreClock/1000000); |
Geremia | 0:2ccd65a72ab8 | 51 | t.start(); |
Geremia | 5:c69049e461b7 | 52 | // myLCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 4:818956c30cae | 53 | // myLCD.claim(stdout); // send stdout to the LCD display |
Geremia | 4:818956c30cae | 54 | //myLCD.claim(stderr); // send stderr to the LCD display |
Geremia | 4:818956c30cae | 55 | myLCD.background(backgroundcolor); // set background to black |
Geremia | 4:818956c30cae | 56 | myLCD.foreground(foregroundcolor); // set chars to white |
Geremia | 5:c69049e461b7 | 57 | |
Geremia | 5:c69049e461b7 | 58 | while(1) |
Geremia | 5:c69049e461b7 | 59 | { |
Geremia | 5:c69049e461b7 | 60 | myLCD.set_orientation((orient++)%4); |
Geremia | 5:c69049e461b7 | 61 | // myLCD.set_orientation(2); |
Geremia | 4:818956c30cae | 62 | myLCD.cls(); // clear the screen |
Geremia | 4:818956c30cae | 63 | myLCD.locate(0,30); |
Geremia | 4:818956c30cae | 64 | myLCD.printf("Display ID: %.8X\r\n", myLCD.tftID); |
Geremia | 4:818956c30cae | 65 | pc.printf("Display ID: %.8X\r\n", myLCD.tftID); |
Geremia | 0:2ccd65a72ab8 | 66 | // mem write/read test |
Geremia | 0:2ccd65a72ab8 | 67 | unsigned short readback; |
Geremia | 4:818956c30cae | 68 | unsigned short colorstep = (0x10000/myLCD.width()); |
Geremia | 4:818956c30cae | 69 | for(unsigned short i=0; i<myLCD.width(); i++) |
Geremia | 1:083257298075 | 70 | { |
Geremia | 4:818956c30cae | 71 | myLCD.pixel(i,0,i*colorstep); // write line |
Geremia | 1:083257298075 | 72 | } |
Geremia | 1:083257298075 | 73 | bool readerror=false; |
Geremia | 4:818956c30cae | 74 | for(unsigned short i=0; i<myLCD.width(); i++) // verify line |
Geremia | 0:2ccd65a72ab8 | 75 | { |
Geremia | 4:818956c30cae | 76 | readback = myLCD.pixelread(i,0); |
Geremia | 1:083257298075 | 77 | if(readback!=i*colorstep) |
Geremia | 1:083257298075 | 78 | { |
Geremia | 1:083257298075 | 79 | readerror=true; |
Geremia | 1:083257298075 | 80 | pc.printf("pix %.4X readback %.4X\r\n", i*colorstep, readback); |
Geremia | 1:083257298075 | 81 | } |
Geremia | 0:2ccd65a72ab8 | 82 | } |
Geremia | 4:818956c30cae | 83 | myLCD.locate(0,10); |
Geremia | 4:818956c30cae | 84 | myLCD.printf("pixelread test %s\r\n", readerror ? "FAIL":"PASS"); |
Geremia | 1:083257298075 | 85 | wait(2); |
Geremia | 0:2ccd65a72ab8 | 86 | |
Geremia | 4:818956c30cae | 87 | myLCD.cls(); |
Geremia | 4:818956c30cae | 88 | myLCD.set_font((unsigned char*) Terminal6x8,32,127,false); //variable width disabled |
Geremia | 4:818956c30cae | 89 | myLCD.locate(0,0); |
Geremia | 5:c69049e461b7 | 90 | myLCD.printf("Display Test\r\nSome text just to see if auto carriage return works correctly"); |
Geremia | 4:818956c30cae | 91 | myLCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 4:818956c30cae | 92 | // myLCD.locate(0,0); |
Geremia | 5:c69049e461b7 | 93 | myLCD.printf("\r\nDisplay Test\r\nSome text just to see if auto carriage return works correctly"); |
Geremia | 0:2ccd65a72ab8 | 94 | pc.printf(" Display Test \r\n"); |
Geremia | 0:2ccd65a72ab8 | 95 | wait(3); |
Geremia | 0:2ccd65a72ab8 | 96 | t.reset(); |
Geremia | 4:818956c30cae | 97 | myLCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 98 | time=t.read_us(); |
Geremia | 4:818956c30cae | 99 | myLCD.locate(2,55); |
Geremia | 4:818956c30cae | 100 | myLCD.printf("cls: %.3fms", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 101 | pc.printf("cls: %.3fms\r\n", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 102 | wait(3); |
Geremia | 4:818956c30cae | 103 | |
Geremia | 4:818956c30cae | 104 | myLCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 105 | t.reset(); |
Geremia | 0:2ccd65a72ab8 | 106 | // draw some graphics |
Geremia | 4:818956c30cae | 107 | //myLCD.cls(); |
Geremia | 4:818956c30cae | 108 | myLCD.set_font((unsigned char*) Arial24x23); |
Geremia | 4:818956c30cae | 109 | myLCD.locate(10,10); |
Geremia | 4:818956c30cae | 110 | myLCD.printf("Test"); |
Geremia | 0:2ccd65a72ab8 | 111 | |
Geremia | 4:818956c30cae | 112 | myLCD.line(0,0,myLCD.width()-1,0,foregroundcolor); |
Geremia | 4:818956c30cae | 113 | myLCD.line(0,0,0,myLCD.height()-1,foregroundcolor); |
Geremia | 4:818956c30cae | 114 | myLCD.line(0,0,myLCD.width()-1,myLCD.height()-1,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 115 | |
Geremia | 4:818956c30cae | 116 | myLCD.rect(10,30,50,40,foregroundcolor); |
Geremia | 4:818956c30cae | 117 | myLCD.fillrect(60,30,100,40,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 118 | |
Geremia | 4:818956c30cae | 119 | myLCD.circle(150,32,30,foregroundcolor); |
Geremia | 4:818956c30cae | 120 | myLCD.fillcircle(140,20,10,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 121 | |
Geremia | 0:2ccd65a72ab8 | 122 | double s; |
Geremia | 0:2ccd65a72ab8 | 123 | |
Geremia | 4:818956c30cae | 124 | for (unsigned short i=0; i<myLCD.width(); i++) |
Geremia | 0:2ccd65a72ab8 | 125 | { |
Geremia | 0:2ccd65a72ab8 | 126 | s =10 * sin((long double) i / 10 ); |
Geremia | 4:818956c30cae | 127 | myLCD.pixel(i,40 + (int)s ,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 128 | } |
Geremia | 0:2ccd65a72ab8 | 129 | |
Geremia | 0:2ccd65a72ab8 | 130 | |
Geremia | 0:2ccd65a72ab8 | 131 | time=t.read_us(); |
Geremia | 4:818956c30cae | 132 | myLCD.locate(2,55); |
Geremia | 4:818956c30cae | 133 | myLCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 4:818956c30cae | 134 | myLCD.printf("plot: %.3fms", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 135 | pc.printf("plot: %.3fms\r\n", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 136 | wait(3); |
Geremia | 4:818956c30cae | 137 | myLCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 138 | t.reset(); |
Geremia | 0:2ccd65a72ab8 | 139 | Bitmap_s pic = { |
Geremia | 0:2ccd65a72ab8 | 140 | 64, // XSize |
Geremia | 0:2ccd65a72ab8 | 141 | 64, // YSize |
Geremia | 0:2ccd65a72ab8 | 142 | 8, // Bytes in Line |
Geremia | 0:2ccd65a72ab8 | 143 | burp, // Pointer to picture data |
Geremia | 0:2ccd65a72ab8 | 144 | }; |
Geremia | 4:818956c30cae | 145 | myLCD.Bitmap_BW(pic,myLCD.width()-64,0); |
Geremia | 0:2ccd65a72ab8 | 146 | time=t.read_us(); |
Geremia | 4:818956c30cae | 147 | myLCD.locate(2,55); |
Geremia | 4:818956c30cae | 148 | myLCD.printf("bmp: %.3fms", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 149 | pc.printf("bmp: %.3fms\r\n", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 150 | wait(3); |
Geremia | 4:818956c30cae | 151 | myLCD.cls(); |
Geremia | 4:818956c30cae | 152 | myLCD.set_font((unsigned char*) Arial43x48_numb, 46, 58, false); //only numbers, variable-width disabled |
Geremia | 0:2ccd65a72ab8 | 153 | t.reset(); |
Geremia | 4:818956c30cae | 154 | myLCD.locate(0,0); |
Geremia | 4:818956c30cae | 155 | myLCD.printf("%d", 12345); |
Geremia | 0:2ccd65a72ab8 | 156 | time=t.read_us(); |
Geremia | 4:818956c30cae | 157 | myLCD.locate(2,55); |
Geremia | 4:818956c30cae | 158 | myLCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 5:c69049e461b7 | 159 | myLCD.printf("Big Font: %.3fms", (float)time/1000); |
Geremia | 5:c69049e461b7 | 160 | pc.printf("Big Font: %.3fms\r\n", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 161 | wait(3); |
Geremia | 3:65af1a9fedda | 162 | // sparse pixels test |
Geremia | 4:818956c30cae | 163 | myLCD.cls(); |
Geremia | 4:818956c30cae | 164 | myLCD.FastWindow(true); |
Geremia | 3:65af1a9fedda | 165 | t.reset(); |
Geremia | 3:65af1a9fedda | 166 | for(unsigned int i=0; i<20000; i++) |
Geremia | 3:65af1a9fedda | 167 | { |
Geremia | 4:818956c30cae | 168 | myLCD.pixel((i+(i*89)%myLCD.width()), (i+(i*61)%myLCD.height()), White); |
Geremia | 3:65af1a9fedda | 169 | } |
Geremia | 4:818956c30cae | 170 | myLCD.copy_to_lcd(); |
Geremia | 3:65af1a9fedda | 171 | time=t.read_us(); |
Geremia | 4:818956c30cae | 172 | myLCD.cls(); |
Geremia | 4:818956c30cae | 173 | myLCD.FastWindow(false); |
Geremia | 3:65af1a9fedda | 174 | t.reset(); |
Geremia | 3:65af1a9fedda | 175 | for(unsigned int i=0; i<20000; i++) |
Geremia | 3:65af1a9fedda | 176 | { |
Geremia | 4:818956c30cae | 177 | myLCD.pixel((i+(i*89)%myLCD.width()), (i+(i*61)%myLCD.height()), White); |
Geremia | 3:65af1a9fedda | 178 | } |
Geremia | 4:818956c30cae | 179 | myLCD.copy_to_lcd(); |
Geremia | 3:65af1a9fedda | 180 | time2=t.read_us(); |
Geremia | 4:818956c30cae | 181 | myLCD.locate(2,55); |
Geremia | 5:c69049e461b7 | 182 | myLCD.printf("std:%.3fms fastw:%.3fms", (float)time2/1000, (float)time/1000); |
Geremia | 4:818956c30cae | 183 | pc.printf("std: %.3fms fastw: %.3fms\r\n", (float)time2/1000, (float)time/1000); |
Geremia | 3:65af1a9fedda | 184 | wait(3); |
Geremia | 2:2b781c215ac0 | 185 | // scroll test, only for TFT |
Geremia | 4:818956c30cae | 186 | myLCD.cls(); |
Geremia | 4:818956c30cae | 187 | myLCD.set_font((unsigned char*) Arial24x23); |
Geremia | 5:c69049e461b7 | 188 | myLCD.locate(2,10); |
Geremia | 4:818956c30cae | 189 | myLCD.printf("Scrolling"); |
Geremia | 4:818956c30cae | 190 | myLCD.rect(0,0,myLCD.width()-1,myLCD.height()-1,White); |
Geremia | 4:818956c30cae | 191 | myLCD.rect(1,1,myLCD.width()-2,myLCD.height()-2,Blue); |
Geremia | 4:818956c30cae | 192 | myLCD.setscrollarea(0,myLCD.sizeY()); |
Geremia | 2:2b781c215ac0 | 193 | wait(1); |
Geremia | 4:818956c30cae | 194 | myLCD.scroll(1); //up 1 |
Geremia | 2:2b781c215ac0 | 195 | wait(1); |
Geremia | 4:818956c30cae | 196 | myLCD.scroll(0); //center |
Geremia | 2:2b781c215ac0 | 197 | wait(1); |
Geremia | 4:818956c30cae | 198 | myLCD.scroll(myLCD.sizeY()-1); //down 1 |
Geremia | 2:2b781c215ac0 | 199 | wait(1); |
Geremia | 4:818956c30cae | 200 | myLCD.scroll(myLCD.sizeY()); // same as 0, center |
Geremia | 2:2b781c215ac0 | 201 | wait(1); |
Geremia | 4:818956c30cae | 202 | myLCD.scroll(myLCD.sizeY()>>1); // half screen |
Geremia | 2:2b781c215ac0 | 203 | wait(1); |
Geremia | 4:818956c30cae | 204 | myLCD.scrollreset(); // center |
Geremia | 2:2b781c215ac0 | 205 | wait(1); |
Geremia | 4:818956c30cae | 206 | for(unsigned short i=1; i<=myLCD.sizeY(); i++) |
Geremia | 2:2b781c215ac0 | 207 | { |
Geremia | 4:818956c30cae | 208 | myLCD.scroll(i); |
Geremia | 2:2b781c215ac0 | 209 | wait_ms(2); |
Geremia | 2:2b781c215ac0 | 210 | } |
Geremia | 2:2b781c215ac0 | 211 | wait(2); |
Geremia | 2:2b781c215ac0 | 212 | // color inversion |
Geremia | 2:2b781c215ac0 | 213 | for(unsigned short i=0; i<=8; i++) |
Geremia | 2:2b781c215ac0 | 214 | { |
Geremia | 4:818956c30cae | 215 | myLCD.invert(i&1); |
Geremia | 2:2b781c215ac0 | 216 | wait_ms(200); |
Geremia | 2:2b781c215ac0 | 217 | } |
Geremia | 2:2b781c215ac0 | 218 | wait(2); |
Geremia | 4:818956c30cae | 219 | // bmp 16bit test |
Geremia | 4:818956c30cae | 220 | myLCD.cls(); |
Geremia | 4:818956c30cae | 221 | t.reset(); |
Geremia | 4:818956c30cae | 222 | for(int y=0; y<myLCD.height(); y+=34) |
Geremia | 4:818956c30cae | 223 | { |
Geremia | 4:818956c30cae | 224 | for(int x=0; x<myLCD.width(); x+=48) myLCD.Bitmap(x,y,48,34,(unsigned char *)pavement_48x34); |
Geremia | 4:818956c30cae | 225 | } |
Geremia | 4:818956c30cae | 226 | time=t.read_us(); |
Geremia | 4:818956c30cae | 227 | myLCD.locate(2,55); |
Geremia | 4:818956c30cae | 228 | myLCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 4:818956c30cae | 229 | myLCD.printf("Bmp speed: %.3fms", (float)time/1000); |
Geremia | 4:818956c30cae | 230 | pc.printf("Bmp speed: %.3fms\r\n", (float)time/1000); |
Geremia | 4:818956c30cae | 231 | wait(2); |
Geremia | 0:2ccd65a72ab8 | 232 | } |
Geremia | 0:2ccd65a72ab8 | 233 | } |