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