
test vor the new lcd with a ILI9341 controller
Dependencies: SPI_TFT_ILI9341 TFT_fonts mbed
Test program for 320*240 LCD with ILI9341 controller. Use SPI and three control lines. The IM mode pins have to be set 1110 (3-0). SPI clock has to be connected to RS labeled pin and DC signal has to be connected to the WR signal.
This driver is written based on datasheet!. I cannot test it at the moment.
main.cpp@0:414a960bd52e, 2013-06-12 (annotated)
- Committer:
- dreschpe
- Date:
- Wed Jun 12 22:56:43 2013 +0000
- Revision:
- 0:414a960bd52e
Test Version for the new lcd with a ILI9341 controller
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 0:414a960bd52e | 1 | // example to test the TFT Display |
dreschpe | 0:414a960bd52e | 2 | // Thanks to the GraphicsDisplay and TextDisplay classes |
dreschpe | 0:414a960bd52e | 3 | // test2.bmp has to be on the mbed file system |
dreschpe | 0:414a960bd52e | 4 | |
dreschpe | 0:414a960bd52e | 5 | //#define NO_DMA |
dreschpe | 0:414a960bd52e | 6 | |
dreschpe | 0:414a960bd52e | 7 | #include "stdio.h" |
dreschpe | 0:414a960bd52e | 8 | #include "mbed.h" |
dreschpe | 0:414a960bd52e | 9 | #include "SPI_TFT_ILI9341.h" |
dreschpe | 0:414a960bd52e | 10 | #include "string" |
dreschpe | 0:414a960bd52e | 11 | #include "Arial12x12.h" |
dreschpe | 0:414a960bd52e | 12 | #include "Arial24x23.h" |
dreschpe | 0:414a960bd52e | 13 | #include "Arial28x28.h" |
dreschpe | 0:414a960bd52e | 14 | #include "font_big.h" |
dreschpe | 0:414a960bd52e | 15 | |
dreschpe | 0:414a960bd52e | 16 | extern unsigned char p1[]; // the mbed logo |
dreschpe | 0:414a960bd52e | 17 | |
dreschpe | 0:414a960bd52e | 18 | // the TFT is connected to SPI pin 11-14 |
dreschpe | 0:414a960bd52e | 19 | |
dreschpe | 0:414a960bd52e | 20 | SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc |
dreschpe | 0:414a960bd52e | 21 | |
dreschpe | 0:414a960bd52e | 22 | |
dreschpe | 0:414a960bd52e | 23 | int main() |
dreschpe | 0:414a960bd52e | 24 | { |
dreschpe | 0:414a960bd52e | 25 | int i; |
dreschpe | 0:414a960bd52e | 26 | //unsigned int y; |
dreschpe | 0:414a960bd52e | 27 | TFT.claim(stdout); // send stdout to the TFT display |
dreschpe | 0:414a960bd52e | 28 | //TFT.claim(stderr); // send stderr to the TFT display |
dreschpe | 0:414a960bd52e | 29 | //TFT.set_orientation(1); |
dreschpe | 0:414a960bd52e | 30 | TFT.background(Black); // set background to black |
dreschpe | 0:414a960bd52e | 31 | TFT.foreground(White); // set chars to white |
dreschpe | 0:414a960bd52e | 32 | TFT.cls(); // clear the screen |
dreschpe | 0:414a960bd52e | 33 | |
dreschpe | 0:414a960bd52e | 34 | //y= 0; |
dreschpe | 0:414a960bd52e | 35 | TFT.background(Black); |
dreschpe | 0:414a960bd52e | 36 | TFT.cls(); |
dreschpe | 0:414a960bd52e | 37 | |
dreschpe | 0:414a960bd52e | 38 | TFT.set_font((unsigned char*) Arial12x12); |
dreschpe | 0:414a960bd52e | 39 | TFT.locate(0,0); |
dreschpe | 0:414a960bd52e | 40 | printf(" Hello Mbed "); |
dreschpe | 0:414a960bd52e | 41 | |
dreschpe | 0:414a960bd52e | 42 | wait(5); // wait two seconds |
dreschpe | 0:414a960bd52e | 43 | |
dreschpe | 0:414a960bd52e | 44 | // draw some graphics |
dreschpe | 0:414a960bd52e | 45 | TFT.cls(); |
dreschpe | 0:414a960bd52e | 46 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 0:414a960bd52e | 47 | TFT.locate(100,100); |
dreschpe | 0:414a960bd52e | 48 | TFT.printf("Graphic"); |
dreschpe | 0:414a960bd52e | 49 | |
dreschpe | 0:414a960bd52e | 50 | TFT.line(0,0,100,0,Green); |
dreschpe | 0:414a960bd52e | 51 | TFT.line(0,0,0,200,Green); |
dreschpe | 0:414a960bd52e | 52 | TFT.line(0,0,100,200,Green); |
dreschpe | 0:414a960bd52e | 53 | |
dreschpe | 0:414a960bd52e | 54 | TFT.rect(100,50,150,100,Red); |
dreschpe | 0:414a960bd52e | 55 | TFT.fillrect(180,25,220,70,Blue); |
dreschpe | 0:414a960bd52e | 56 | |
dreschpe | 0:414a960bd52e | 57 | TFT.circle(80,150,33,White); |
dreschpe | 0:414a960bd52e | 58 | TFT.fillcircle(160,190,20,Yellow); |
dreschpe | 0:414a960bd52e | 59 | |
dreschpe | 0:414a960bd52e | 60 | double s; |
dreschpe | 0:414a960bd52e | 61 | |
dreschpe | 0:414a960bd52e | 62 | for (i=0; i<320; i++) { |
dreschpe | 0:414a960bd52e | 63 | s =20 * sin((long double) i / 10 ); |
dreschpe | 0:414a960bd52e | 64 | TFT.pixel(i,100 + (int)s ,Red); |
dreschpe | 0:414a960bd52e | 65 | } |
dreschpe | 0:414a960bd52e | 66 | |
dreschpe | 0:414a960bd52e | 67 | |
dreschpe | 0:414a960bd52e | 68 | wait(5); // wait two seconds |
dreschpe | 0:414a960bd52e | 69 | |
dreschpe | 0:414a960bd52e | 70 | // bigger text |
dreschpe | 0:414a960bd52e | 71 | TFT.foreground(White); |
dreschpe | 0:414a960bd52e | 72 | TFT.background(Blue); |
dreschpe | 0:414a960bd52e | 73 | TFT.cls(); |
dreschpe | 0:414a960bd52e | 74 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 0:414a960bd52e | 75 | TFT.locate(0,0); |
dreschpe | 0:414a960bd52e | 76 | TFT.printf("Different Fonts :"); |
dreschpe | 0:414a960bd52e | 77 | |
dreschpe | 0:414a960bd52e | 78 | TFT.set_font((unsigned char*) Neu42x35); |
dreschpe | 0:414a960bd52e | 79 | TFT.locate(0,30); |
dreschpe | 0:414a960bd52e | 80 | TFT.printf("Hello Mbed 1"); |
dreschpe | 0:414a960bd52e | 81 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 0:414a960bd52e | 82 | TFT.locate(20,80); |
dreschpe | 0:414a960bd52e | 83 | TFT.printf("Hello Mbed 2"); |
dreschpe | 0:414a960bd52e | 84 | TFT.set_font((unsigned char*) Arial12x12); |
dreschpe | 0:414a960bd52e | 85 | TFT.locate(35,120); |
dreschpe | 0:414a960bd52e | 86 | TFT.printf("Hello Mbed 3"); |
dreschpe | 0:414a960bd52e | 87 | wait(5); |
dreschpe | 0:414a960bd52e | 88 | |
dreschpe | 0:414a960bd52e | 89 | // mbed logo |
dreschpe | 0:414a960bd52e | 90 | TFT.background(Black); |
dreschpe | 0:414a960bd52e | 91 | TFT.cls(); |
dreschpe | 0:414a960bd52e | 92 | |
dreschpe | 0:414a960bd52e | 93 | TFT.locate(10,10); |
dreschpe | 0:414a960bd52e | 94 | TFT.printf("Graphic from Flash"); |
dreschpe | 0:414a960bd52e | 95 | |
dreschpe | 0:414a960bd52e | 96 | TFT.Bitmap(90,90,172,55,p1); |
dreschpe | 0:414a960bd52e | 97 | |
dreschpe | 0:414a960bd52e | 98 | wait(5); |
dreschpe | 0:414a960bd52e | 99 | TFT.cls(); |
dreschpe | 0:414a960bd52e | 100 | TFT.locate(10,10); |
dreschpe | 0:414a960bd52e | 101 | TFT.printf("Graphic from File System"); |
dreschpe | 0:414a960bd52e | 102 | TFT.locate(10,20); |
dreschpe | 0:414a960bd52e | 103 | TFT.printf("open test.bmp"); |
dreschpe | 0:414a960bd52e | 104 | int err = TFT.BMP_16(20,50,"test.bmp"); |
dreschpe | 0:414a960bd52e | 105 | if (err != 1) TFT.printf(" - Err: %d",err); |
dreschpe | 0:414a960bd52e | 106 | } |