follow the instruction in http://mbed.org/users/dreschpe/code/SPI_TFT_ILI9341/, make two update, 1. replace P5, P6, P7, P8, P9, P10 with SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTD0, PTA20, PTA13,"TFT"); // mosi, miso, sclk, cs, reset, dc in graphics.c add const, otherwise not compile.

Dependencies:   SPI_TFT_ILI9341 TFT_fonts mbed

Committer:
you_sun
Date:
Wed Jan 29 20:35:15 2014 +0000
Revision:
1:975aec13da53
Parent:
0:ec5c751ea08e
a 16 bit fish, 160 by 120;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
you_sun 0:ec5c751ea08e 1 // example to test the TFT Display
you_sun 0:ec5c751ea08e 2 // Thanks to the GraphicsDisplay and TextDisplay classes
you_sun 0:ec5c751ea08e 3 // test2.bmp has to be on the mbed file system
you_sun 0:ec5c751ea08e 4
you_sun 0:ec5c751ea08e 5 //#define NO_DMA
you_sun 0:ec5c751ea08e 6
you_sun 0:ec5c751ea08e 7 #include "stdio.h"
you_sun 0:ec5c751ea08e 8 #include "mbed.h"
you_sun 0:ec5c751ea08e 9 #include "SPI_TFT_ILI9341.h"
you_sun 0:ec5c751ea08e 10 #include "string"
you_sun 0:ec5c751ea08e 11 #include "Arial12x12.h"
you_sun 0:ec5c751ea08e 12 #include "Arial24x23.h"
you_sun 0:ec5c751ea08e 13 #include "Arial28x28.h"
you_sun 0:ec5c751ea08e 14 #include "font_big.h"
you_sun 0:ec5c751ea08e 15
you_sun 0:ec5c751ea08e 16 extern unsigned char p1[]; // the mbed logo
you_sun 0:ec5c751ea08e 17
you_sun 0:ec5c751ea08e 18 // the TFT is connected to SPI pin 11-14
you_sun 0:ec5c751ea08e 19 //PinName p5, p6, p7, p8, p9, p10;
you_sun 0:ec5c751ea08e 20 SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTD0, PTA20, PTA13,"TFT"); // mosi, miso, sclk, cs, reset, dc
you_sun 0:ec5c751ea08e 21
you_sun 0:ec5c751ea08e 22
you_sun 0:ec5c751ea08e 23 int main()
you_sun 0:ec5c751ea08e 24 {
you_sun 0:ec5c751ea08e 25 int i;
you_sun 0:ec5c751ea08e 26 //unsigned int y;
you_sun 0:ec5c751ea08e 27 TFT.claim(stdout); // send stdout to the TFT display
you_sun 0:ec5c751ea08e 28 //TFT.claim(stderr); // send stderr to the TFT display
you_sun 1:975aec13da53 29 TFT.set_orientation(1);
you_sun 0:ec5c751ea08e 30 TFT.background(Black); // set background to black
you_sun 0:ec5c751ea08e 31 TFT.foreground(White); // set chars to white
you_sun 0:ec5c751ea08e 32 TFT.cls(); // clear the screen
you_sun 0:ec5c751ea08e 33
you_sun 0:ec5c751ea08e 34 //y= 0;
you_sun 0:ec5c751ea08e 35 TFT.background(Black);
you_sun 0:ec5c751ea08e 36 TFT.cls();
you_sun 0:ec5c751ea08e 37
you_sun 0:ec5c751ea08e 38 TFT.set_font((unsigned char*) Arial12x12);
you_sun 0:ec5c751ea08e 39 TFT.locate(0,0);
you_sun 0:ec5c751ea08e 40 printf(" Hello Mbed ");
you_sun 0:ec5c751ea08e 41
you_sun 0:ec5c751ea08e 42 wait(5); // wait two seconds
you_sun 0:ec5c751ea08e 43
you_sun 0:ec5c751ea08e 44 // draw some graphics
you_sun 0:ec5c751ea08e 45 TFT.cls();
you_sun 0:ec5c751ea08e 46 TFT.set_font((unsigned char*) Arial24x23);
you_sun 0:ec5c751ea08e 47 TFT.locate(100,100);
you_sun 0:ec5c751ea08e 48 TFT.printf("Graphic");
you_sun 0:ec5c751ea08e 49
you_sun 0:ec5c751ea08e 50 TFT.line(0,0,100,0,Green);
you_sun 0:ec5c751ea08e 51 TFT.line(0,0,0,200,Green);
you_sun 0:ec5c751ea08e 52 TFT.line(0,0,100,200,Green);
you_sun 0:ec5c751ea08e 53
you_sun 0:ec5c751ea08e 54 TFT.rect(100,50,150,100,Red);
you_sun 0:ec5c751ea08e 55 TFT.fillrect(180,25,220,70,Blue);
you_sun 0:ec5c751ea08e 56
you_sun 0:ec5c751ea08e 57 TFT.circle(80,150,33,White);
you_sun 0:ec5c751ea08e 58 TFT.fillcircle(160,190,20,Yellow);
you_sun 0:ec5c751ea08e 59
you_sun 0:ec5c751ea08e 60 double s;
you_sun 0:ec5c751ea08e 61
you_sun 0:ec5c751ea08e 62 for (i=0; i<320; i++) {
you_sun 0:ec5c751ea08e 63 s =20 * sin((long double) i / 10 );
you_sun 0:ec5c751ea08e 64 TFT.pixel(i,100 + (int)s ,Red);
you_sun 0:ec5c751ea08e 65 }
you_sun 0:ec5c751ea08e 66
you_sun 0:ec5c751ea08e 67
you_sun 0:ec5c751ea08e 68 wait(5); // wait two seconds
you_sun 0:ec5c751ea08e 69
you_sun 0:ec5c751ea08e 70 // bigger text
you_sun 0:ec5c751ea08e 71 TFT.foreground(White);
you_sun 0:ec5c751ea08e 72 TFT.background(Blue);
you_sun 0:ec5c751ea08e 73 TFT.cls();
you_sun 0:ec5c751ea08e 74 TFT.set_font((unsigned char*) Arial24x23);
you_sun 0:ec5c751ea08e 75 TFT.locate(0,0);
you_sun 0:ec5c751ea08e 76 TFT.printf("Different Fonts :");
you_sun 0:ec5c751ea08e 77
you_sun 0:ec5c751ea08e 78 TFT.set_font((unsigned char*) Neu42x35);
you_sun 0:ec5c751ea08e 79 TFT.locate(0,30);
you_sun 0:ec5c751ea08e 80 TFT.printf("Hello Mbed 1");
you_sun 0:ec5c751ea08e 81 TFT.set_font((unsigned char*) Arial24x23);
you_sun 0:ec5c751ea08e 82 TFT.locate(20,80);
you_sun 0:ec5c751ea08e 83 TFT.printf("Hello Mbed 2");
you_sun 0:ec5c751ea08e 84 TFT.set_font((unsigned char*) Arial12x12);
you_sun 0:ec5c751ea08e 85 TFT.locate(35,120);
you_sun 0:ec5c751ea08e 86 TFT.printf("Hello Mbed 3");
you_sun 0:ec5c751ea08e 87 wait(5);
you_sun 0:ec5c751ea08e 88
you_sun 0:ec5c751ea08e 89 // mbed logo
you_sun 0:ec5c751ea08e 90 TFT.background(Black);
you_sun 0:ec5c751ea08e 91 TFT.cls();
you_sun 0:ec5c751ea08e 92
you_sun 0:ec5c751ea08e 93 TFT.locate(10,10);
you_sun 0:ec5c751ea08e 94 TFT.printf("Graphic from Flash");
you_sun 0:ec5c751ea08e 95
you_sun 1:975aec13da53 96 // TFT.Bitmap(90,90,172,55,p1);
you_sun 1:975aec13da53 97 TFT.Bitmap(90,90,160,120,p1);
you_sun 0:ec5c751ea08e 98
you_sun 1:975aec13da53 99 wait(50);
you_sun 1:975aec13da53 100 /*
you_sun 0:ec5c751ea08e 101 TFT.cls();
you_sun 0:ec5c751ea08e 102 TFT.locate(10,10);
you_sun 0:ec5c751ea08e 103 TFT.printf("Graphic from File System");
you_sun 0:ec5c751ea08e 104 TFT.locate(10,20);
you_sun 1:975aec13da53 105 //TFT.printf("open test.bmp");
you_sun 1:975aec13da53 106 TFT.BMP_16(0,0,"/local/test.bmp");
you_sun 1:975aec13da53 107 int err = TFT.BMP_16(20,50,"/local/test.bmp");
you_sun 0:ec5c751ea08e 108 if (err != 1) TFT.printf(" - Err: %d",err);
you_sun 1:975aec13da53 109 */
you_sun 0:ec5c751ea08e 110 }