![](/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@0:2ccd65a72ab8, 2015-02-14 (annotated)
- Committer:
- Geremia
- Date:
- Sat Feb 14 19:56:13 2015 +0000
- Revision:
- 0:2ccd65a72ab8
- Child:
- 1:083257298075
UniGraphic demo for lcd and tft, par and spi
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 | 0:2ccd65a72ab8 | 9 | |
Geremia | 0:2ccd65a72ab8 | 10 | #include "IST3020.h" |
Geremia | 0:2ccd65a72ab8 | 11 | //#include "UC1608.h" |
Geremia | 0:2ccd65a72ab8 | 12 | //#include "ILI9341.h" |
Geremia | 0:2ccd65a72ab8 | 13 | |
Geremia | 0:2ccd65a72ab8 | 14 | Serial pc(USBTX, USBRX); |
Geremia | 0:2ccd65a72ab8 | 15 | |
Geremia | 0:2ccd65a72ab8 | 16 | IST3020 LCD(PAR_8, PortC, PC_8, PC_9, PA_0, PA_1, PA_4,"LCD"); // Parallel8bit, Port, CS, reset, A0, WR, RD for F302 |
Geremia | 0:2ccd65a72ab8 | 17 | //UC1608 LCD(SPI_16, 10000000, D11, D12, D13, D10, D9, D8,"LCD"); // Spi16bit, 10MHz, mosi, miso, sclk, cs, reset, dc |
Geremia | 0:2ccd65a72ab8 | 18 | //ILI9341 LCD(SPI_16, 10000000, D11, D12, D13, D10, D9, D8,"LCD"); // Spi16bit, 10MHz, mosi, miso, sclk, cs, reset, dc |
Geremia | 0:2ccd65a72ab8 | 19 | |
Geremia | 0:2ccd65a72ab8 | 20 | Timer t; |
Geremia | 0:2ccd65a72ab8 | 21 | |
Geremia | 0:2ccd65a72ab8 | 22 | unsigned short backgroundcolor=Black; |
Geremia | 0:2ccd65a72ab8 | 23 | unsigned short foregroundcolor=White; |
Geremia | 0:2ccd65a72ab8 | 24 | |
Geremia | 0:2ccd65a72ab8 | 25 | char orient=1; |
Geremia | 0:2ccd65a72ab8 | 26 | int main() |
Geremia | 0:2ccd65a72ab8 | 27 | { |
Geremia | 0:2ccd65a72ab8 | 28 | // LCD.set_contrast(26);//for uc1608 |
Geremia | 0:2ccd65a72ab8 | 29 | // LCD.set_contrast(46);//for ist3020 |
Geremia | 0:2ccd65a72ab8 | 30 | LCD.set_orientation(orient); |
Geremia | 0:2ccd65a72ab8 | 31 | int time; |
Geremia | 0:2ccd65a72ab8 | 32 | pc.baud (115200); |
Geremia | 0:2ccd65a72ab8 | 33 | pc.printf("\n\nSystem Core Clock = %.3f MHZ\r\n",(float)SystemCoreClock/1000000); |
Geremia | 0:2ccd65a72ab8 | 34 | t.start(); |
Geremia | 0:2ccd65a72ab8 | 35 | |
Geremia | 0:2ccd65a72ab8 | 36 | // LCD.claim(stdout); // send stdout to the LCD display |
Geremia | 0:2ccd65a72ab8 | 37 | //LCD.claim(stderr); // send stderr to the LCD display |
Geremia | 0:2ccd65a72ab8 | 38 | LCD.background(backgroundcolor); // set background to black |
Geremia | 0:2ccd65a72ab8 | 39 | LCD.foreground(foregroundcolor); // set chars to white |
Geremia | 0:2ccd65a72ab8 | 40 | LCD.cls(); // clear the screen |
Geremia | 0:2ccd65a72ab8 | 41 | |
Geremia | 0:2ccd65a72ab8 | 42 | // mem write/read test |
Geremia | 0:2ccd65a72ab8 | 43 | /* LCD.locate(0,0); |
Geremia | 0:2ccd65a72ab8 | 44 | unsigned short readback; |
Geremia | 0:2ccd65a72ab8 | 45 | unsigned short colorstep = (0x10000/LCD.width()) |
Geremia | 0:2ccd65a72ab8 | 46 | for(unsigned short i=0; i<LCD.width(); i++) LCD.pixel(i,0,i*colorstep); // write line |
Geremia | 0:2ccd65a72ab8 | 47 | for(unsigned short i=0; i<LCD.width(); i++) // verify line |
Geremia | 0:2ccd65a72ab8 | 48 | { |
Geremia | 0:2ccd65a72ab8 | 49 | readback = LCD.pixelread(i,0); |
Geremia | 0:2ccd65a72ab8 | 50 | if(readback!=i*colorstep) pc.printf("pix %.4X readback %.4X\r\n", i*colorstep, readback); |
Geremia | 0:2ccd65a72ab8 | 51 | } |
Geremia | 0:2ccd65a72ab8 | 52 | */ |
Geremia | 0:2ccd65a72ab8 | 53 | |
Geremia | 0:2ccd65a72ab8 | 54 | |
Geremia | 0:2ccd65a72ab8 | 55 | while(1) |
Geremia | 0:2ccd65a72ab8 | 56 | { |
Geremia | 0:2ccd65a72ab8 | 57 | LCD.set_orientation((orient++)%4); |
Geremia | 0:2ccd65a72ab8 | 58 | // LCD.set_orientation(2); |
Geremia | 0:2ccd65a72ab8 | 59 | LCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 60 | LCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 0:2ccd65a72ab8 | 61 | LCD.locate(0,0); |
Geremia | 0:2ccd65a72ab8 | 62 | LCD.printf("Display Test\r\nSome text just to see if auto carriage return works correctly"); |
Geremia | 0:2ccd65a72ab8 | 63 | pc.printf(" Display Test \r\n"); |
Geremia | 0:2ccd65a72ab8 | 64 | wait(3); |
Geremia | 0:2ccd65a72ab8 | 65 | t.reset(); |
Geremia | 0:2ccd65a72ab8 | 66 | LCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 67 | time=t.read_us(); |
Geremia | 0:2ccd65a72ab8 | 68 | LCD.locate(2,55); |
Geremia | 0:2ccd65a72ab8 | 69 | LCD.printf("cls: %.3fms", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 70 | pc.printf("cls: %.3fms\r\n", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 71 | wait(3); |
Geremia | 0:2ccd65a72ab8 | 72 | LCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 73 | t.reset(); |
Geremia | 0:2ccd65a72ab8 | 74 | // draw some graphics |
Geremia | 0:2ccd65a72ab8 | 75 | //LCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 76 | LCD.set_font((unsigned char*) Arial24x23); |
Geremia | 0:2ccd65a72ab8 | 77 | LCD.locate(10,10); |
Geremia | 0:2ccd65a72ab8 | 78 | LCD.printf("Test"); |
Geremia | 0:2ccd65a72ab8 | 79 | |
Geremia | 0:2ccd65a72ab8 | 80 | LCD.line(0,0,LCD.width()-1,0,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 81 | LCD.line(0,0,0,LCD.height()-1,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 82 | LCD.line(0,0,LCD.width()-1,LCD.height()-1,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 83 | |
Geremia | 0:2ccd65a72ab8 | 84 | LCD.rect(10,30,50,40,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 85 | LCD.fillrect(60,30,100,40,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 86 | |
Geremia | 0:2ccd65a72ab8 | 87 | LCD.circle(150,32,30,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 88 | LCD.fillcircle(140,20,10,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 89 | |
Geremia | 0:2ccd65a72ab8 | 90 | double s; |
Geremia | 0:2ccd65a72ab8 | 91 | |
Geremia | 0:2ccd65a72ab8 | 92 | for (unsigned short i=0; i<LCD.width(); i++) |
Geremia | 0:2ccd65a72ab8 | 93 | { |
Geremia | 0:2ccd65a72ab8 | 94 | s =10 * sin((long double) i / 10 ); |
Geremia | 0:2ccd65a72ab8 | 95 | LCD.pixel(i,40 + (int)s ,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 96 | } |
Geremia | 0:2ccd65a72ab8 | 97 | |
Geremia | 0:2ccd65a72ab8 | 98 | |
Geremia | 0:2ccd65a72ab8 | 99 | time=t.read_us(); |
Geremia | 0:2ccd65a72ab8 | 100 | LCD.locate(2,55); |
Geremia | 0:2ccd65a72ab8 | 101 | LCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 0:2ccd65a72ab8 | 102 | LCD.printf("plot: %.3fms", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 103 | pc.printf("plot: %.3fms\r\n", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 104 | wait(3); |
Geremia | 0:2ccd65a72ab8 | 105 | LCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 106 | t.reset(); |
Geremia | 0:2ccd65a72ab8 | 107 | Bitmap_s pic = { |
Geremia | 0:2ccd65a72ab8 | 108 | 64, // XSize |
Geremia | 0:2ccd65a72ab8 | 109 | 64, // YSize |
Geremia | 0:2ccd65a72ab8 | 110 | 8, // Bytes in Line |
Geremia | 0:2ccd65a72ab8 | 111 | burp, // Pointer to picture data |
Geremia | 0:2ccd65a72ab8 | 112 | }; |
Geremia | 0:2ccd65a72ab8 | 113 | LCD.Bitmap_BW(pic,LCD.width()-64,0); |
Geremia | 0:2ccd65a72ab8 | 114 | time=t.read_us(); |
Geremia | 0:2ccd65a72ab8 | 115 | LCD.locate(2,55); |
Geremia | 0:2ccd65a72ab8 | 116 | LCD.printf("bmp: %.3fms", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 117 | pc.printf("bmp: %.3fms\r\n", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 118 | wait(3); |
Geremia | 0:2ccd65a72ab8 | 119 | LCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 120 | LCD.set_font((unsigned char*) Arial43x48_numb, 46, 58, false); //only numbers, variable-width disabled |
Geremia | 0:2ccd65a72ab8 | 121 | t.reset(); |
Geremia | 0:2ccd65a72ab8 | 122 | LCD.locate(0,0); |
Geremia | 0:2ccd65a72ab8 | 123 | LCD.printf("%d", 12345); |
Geremia | 0:2ccd65a72ab8 | 124 | time=t.read_us(); |
Geremia | 0:2ccd65a72ab8 | 125 | LCD.locate(2,55); |
Geremia | 0:2ccd65a72ab8 | 126 | LCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 0:2ccd65a72ab8 | 127 | LCD.printf("Big Font speed: %.3fms", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 128 | pc.printf("Big Font speed: %.3fms\r\n", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 129 | wait(3); |
Geremia | 0:2ccd65a72ab8 | 130 | } |
Geremia | 0:2ccd65a72ab8 | 131 | } |