for Aitendo TFT LCD (M018C7735SPI)

Dependencies:   ST7735_TFT mbed

Fork of SPI18TFT_FRDM-KL25Z by Masato YAMANISHI

Committer:
morgonXak
Date:
Sat Mar 15 17:13:46 2014 +0000
Revision:
1:adc1be6d282f
Parent:
0:e32728270b5b
l

Who changed what in which revision?

UserRevisionLine numberNew contents of line
masato 0:e32728270b5b 1 #include "stdio.h"
masato 0:e32728270b5b 2 #include "stdlib.h"
masato 0:e32728270b5b 3 #include "math.h"
masato 0:e32728270b5b 4 #include "mbed.h"
masato 0:e32728270b5b 5 #include "ST7735_TFT.h"
masato 0:e32728270b5b 6 #include "string"
masato 0:e32728270b5b 7 #include "Arial12x12.h"
masato 0:e32728270b5b 8
masato 0:e32728270b5b 9 #define SCREEN_WIDTH 160
masato 0:e32728270b5b 10 #define SCREEN_HEIGHT 128
masato 0:e32728270b5b 11
masato 0:e32728270b5b 12 // Antendo M018C7735SPI TFT-LCD
masato 0:e32728270b5b 13 // with mbed LPC1768
masato 0:e32728270b5b 14 // the TFT is connected to SPI pin 5-7, CS is p8, RS is p11, reset is p15
masato 0:e32728270b5b 15 // ST7735_TFT TFT(p5, p6, p7, p8, p11, p15, "TFT"); // mosi, miso, sclk, cs, rs, reset
masato 0:e32728270b5b 16 // with FRDM-KL25Z
masato 0:e32728270b5b 17 ST7735_TFT TFT(PTD2, PTD3, PTD1, PTC11, PTC12, PTC13, "TFT"); // PTA13, PTD5, PTD0, "TFT");
masato 0:e32728270b5b 18 /*
masato 0:e32728270b5b 19 ST7735_TFT( // for FRDM-KL25
masato 0:e32728270b5b 20 PinName mosi = SDA, // p5 9 // PTD2
masato 0:e32728270b5b 21 PinName miso = NC, // p6(NC) // PTD3
masato 0:e32728270b5b 22 PinName sclk = SCK, // p7, 10 // PTD1
masato 0:e32728270b5b 23 PinName cs = CS, // p8 15 // PTA13
masato 0:e32728270b5b 24 PinName rs = A0, // 8 // PTD5
masato 0:e32728270b5b 25 PinName reset = RESET // 17 // PTD0
masato 0:e32728270b5b 26 );
masato 0:e32728270b5b 27 */
masato 0:e32728270b5b 28
masato 0:e32728270b5b 29 #define USE_LED 0
masato 0:e32728270b5b 30
masato 0:e32728270b5b 31 #if USE_LED
masato 0:e32728270b5b 32 DigitalOut myled1(LED1);
masato 0:e32728270b5b 33 #endif
masato 0:e32728270b5b 34
masato 0:e32728270b5b 35 Serial pc(USBTX, USBRX); // tx, rx
masato 0:e32728270b5b 36 Timer t;
masato 0:e32728270b5b 37
masato 0:e32728270b5b 38 extern const unsigned char p1[]; // the mbed logo
masato 0:e32728270b5b 39
masato 0:e32728270b5b 40 int main() {
masato 0:e32728270b5b 41
masato 0:e32728270b5b 42 unsigned int centerx, centery;
masato 0:e32728270b5b 43 int i, j; // tempx, tempy;
masato 0:e32728270b5b 44 // init();
masato 0:e32728270b5b 45 TFT.set_orientation(1);
masato 0:e32728270b5b 46 centerx = TFT.width() >> 1;
masato 0:e32728270b5b 47 centery = TFT.height() >> 1;
masato 0:e32728270b5b 48 TFT.claim(stdout); // send stdout to the TFT display
masato 0:e32728270b5b 49 //TFT.claim(stderr); // send stderr to the TFT display
masato 0:e32728270b5b 50
masato 0:e32728270b5b 51 while (1) {
masato 0:e32728270b5b 52 fprintf(stderr, "START\r\n");
masato 0:e32728270b5b 53
masato 0:e32728270b5b 54 TFT.background(White); // set background to black
masato 0:e32728270b5b 55 TFT.foreground(Black); // set chars to white
masato 0:e32728270b5b 56
masato 0:e32728270b5b 57 TFT.cls();
masato 0:e32728270b5b 58 // break;
masato 0:e32728270b5b 59 // TFT.set_font((unsigned char*) Arial24x23); // select the font
masato 0:e32728270b5b 60 TFT.set_font((unsigned char*) Arial12x12);
masato 0:e32728270b5b 61
masato 0:e32728270b5b 62 TFT.Bitmap(centerx-64,centery-24,128,47, (unsigned char*)p1);
masato 0:e32728270b5b 63 // TFT.rect(0, 0, 4, 127, Blue);
masato 0:e32728270b5b 64
masato 0:e32728270b5b 65 for (i = 0; i < SCREEN_HEIGHT; i+=8)
masato 0:e32728270b5b 66 TFT.line(0, i, SCREEN_WIDTH - 1, i, Red);
masato 0:e32728270b5b 67 for (j = 0; j < SCREEN_WIDTH; j+=8)
masato 0:e32728270b5b 68 TFT.line(j, 0, j, SCREEN_HEIGHT - 1, Blue);
masato 0:e32728270b5b 69
masato 0:e32728270b5b 70 for (i = 0; i < SCREEN_HEIGHT; i++)
masato 0:e32728270b5b 71 // for (j = 0; j < SCREEN_WIDTH; j++)
masato 0:e32728270b5b 72 TFT.pixel(i, i, Green);
masato 0:e32728270b5b 73
masato 0:e32728270b5b 74 // TFT.locate(16,10);
masato 0:e32728270b5b 75 // TFT.set_font((unsigned char*) Arial2x12); // select the font
masato 0:e32728270b5b 76 // printf("Time %f s\n", t.read());
masato 0:e32728270b5b 77
masato 0:e32728270b5b 78 // wait(0.5);
masato 0:e32728270b5b 79 TFT.Bitmap(centerx-64,centery-24,128,47,(unsigned char*)p1);
masato 0:e32728270b5b 80 // TFT.locate(76,100);
masato 0:e32728270b5b 81 // fprintf(stdout, "ss_ABC");
masato 0:e32728270b5b 82 TFT.locate(24,100);
masato 0:e32728270b5b 83 fprintf(stdout, "@n24bass_ABC");
masato 0:e32728270b5b 84 // TFT.locate(76,100);
masato 0:e32728270b5b 85 // fprintf(stdout, "ss_ABC");
masato 0:e32728270b5b 86 // fprintf(stderr, "END\r\n");
masato 0:e32728270b5b 87 break;
masato 0:e32728270b5b 88 }
masato 0:e32728270b5b 89 #if USE_LED
masato 0:e32728270b5b 90 while (1) {
masato 0:e32728270b5b 91 myled1 = 1;
masato 0:e32728270b5b 92 wait(0.5);
masato 0:e32728270b5b 93 myled1 = 0;
masato 0:e32728270b5b 94 wait(0.5);
masato 0:e32728270b5b 95 }
masato 0:e32728270b5b 96 #endif
masato 0:e32728270b5b 97 while (1)
masato 0:e32728270b5b 98 wait(1);
masato 0:e32728270b5b 99 }