广州活力数据恢复中心

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1374|回复: 0

[arduino nodemcu] es8266 ILI9341 LCD显示屏驱动测试代码

[复制链接]

92

主题

104

帖子

688

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
688
发表于 2020-9-13 19:16:42 | 显示全部楼层 |阅读模式
es8266 ILI9341 LCD显示屏驱动测试代码





接线:
  • CS pin is connected to D2 (ESP8266EX GPIO4),
  • RST pin is connected to D3 (ESP8266EX GPIO0),
  • D/C pin is connected to D4 (ESP8266EX GPIO2),
  • MOSI pin is connected to D7 (ESP8266EX GPIO13),
  • SCK pin is connected to D5 (ESP8266EX GPIO14),
  • VCC and BL are connected to pin 3V3,
  • GND is connected to pin GND of the NodeMCU board.





  1. #include <Adafruit_GFX.h>       // include Adafruit graphics library
  2. #include <Adafruit_ILI9341.h>   // include Adafruit ILI9341 TFT library

  3. #define TFT_CS    D2     // TFT CS  pin is connected to NodeMCU pin D2
  4. #define TFT_RST   D3     // TFT RST pin is connected to NodeMCU pin D3
  5. #define TFT_DC    D4     // TFT DC  pin is connected to NodeMCU pin D4
  6. // initialize ILI9341 TFT library with hardware SPI module
  7. // SCK (CLK) ---> NodeMCU pin D5 (GPIO14)
  8. // MOSI(DIN) ---> NodeMCU pin D7 (GPIO13)
  9. Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

  10. void setup() {
  11.   Serial.begin(9600);
  12.   Serial.println("ILI9341 Test!");

  13.   tft.begin();

  14.   // read diagnostics (optional but can help debug problems)
  15.   uint8_t x = tft.readcommand8(ILI9341_RDMODE);
  16.   Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
  17.   x = tft.readcommand8(ILI9341_RDMADCTL);
  18.   Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
  19.   x = tft.readcommand8(ILI9341_RDPIXFMT);
  20.   Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
  21.   x = tft.readcommand8(ILI9341_RDIMGFMT);
  22.   Serial.print("Image Format: 0x"); Serial.println(x, HEX);
  23.   x = tft.readcommand8(ILI9341_RDSELFDIAG);
  24.   Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
  25.   
  26.   Serial.println(F("Benchmark                Time (microseconds)"));

  27.   Serial.print(F("Screen fill              "));
  28.   Serial.println(testFillScreen());
  29.   delay(500);

  30.   Serial.print(F("Text                     "));
  31.   Serial.println(testText());
  32.   delay(3000);

  33.   Serial.print(F("Lines                    "));
  34.   Serial.println(testLines(ILI9341_CYAN));
  35.   delay(500);

  36.   Serial.print(F("Horiz/Vert Lines         "));
  37.   Serial.println(testFastLines(ILI9341_RED, ILI9341_BLUE));
  38.   delay(500);

  39.   Serial.print(F("Rectangles (outline)     "));
  40.   Serial.println(testRects(ILI9341_GREEN));
  41.   delay(500);

  42.   Serial.print(F("Rectangles (filled)      "));
  43.   Serial.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA));
  44.   delay(500);

  45.   Serial.print(F("Circles (filled)         "));
  46.   Serial.println(testFilledCircles(10, ILI9341_MAGENTA));

  47.   Serial.print(F("Circles (outline)        "));
  48.   Serial.println(testCircles(10, ILI9341_WHITE));
  49.   delay(500);

  50.   Serial.print(F("Triangles (outline)      "));
  51.   Serial.println(testTriangles());
  52.   delay(500);

  53.   Serial.print(F("Triangles (filled)       "));
  54.   Serial.println(testFilledTriangles());
  55.   delay(500);

  56.   Serial.print(F("Rounded rects (outline)  "));
  57.   Serial.println(testRoundRects());
  58.   delay(500);

  59.   Serial.print(F("Rounded rects (filled)   "));
  60.   Serial.println(testFilledRoundRects());
  61.   delay(500);

  62.   Serial.println(F("Done!"));

  63. }


  64. void loop(void) {
  65.   for(uint8_t rotation=0; rotation<4; rotation++) {
  66.     tft.setRotation(rotation);
  67.     testText();
  68.     delay(1000);
  69.   }
  70. }

  71. unsigned long testFillScreen() {
  72.   unsigned long start = micros();
  73.   tft.fillScreen(ILI9341_BLACK);
  74.   tft.fillScreen(ILI9341_RED);
  75.   tft.fillScreen(ILI9341_GREEN);
  76.   tft.fillScreen(ILI9341_BLUE);
  77.   tft.fillScreen(ILI9341_BLACK);
  78.   return micros() - start;
  79. }

  80. unsigned long testText() {
  81.   tft.fillScreen(ILI9341_BLACK);
  82.   unsigned long start = micros();
  83.   tft.setCursor(0, 0);
  84.   tft.setTextColor(ILI9341_WHITE);  tft.setTextSize(1);
  85.   tft.println("Hello World!");
  86.   tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2);
  87.   tft.println(1234.56);
  88.   tft.setTextColor(ILI9341_RED);    tft.setTextSize(3);
  89.   tft.println(0xDEADBEEF, HEX);
  90.   tft.println();
  91.   tft.setTextColor(ILI9341_GREEN);
  92.   tft.setTextSize(5);
  93.   tft.println("Groop");
  94.   tft.setTextSize(2);
  95.   tft.println("I implore thee,");
  96.   tft.setTextSize(1);
  97.   tft.println("my foonting turlingdromes.");
  98.   tft.println("And hooptiously drangle me");
  99.   tft.println("with crinkly bindlewurdles,");
  100.   tft.println("Or I will rend thee");
  101.   tft.println("in the gobberwarts");
  102.   tft.println("with my blurglecruncheon,");
  103.   tft.println("see if I don't!");
  104.   return micros() - start;
  105. }

  106. unsigned long testLines(uint16_t color) {
  107.   unsigned long start, t;
  108.   int           x1, y1, x2, y2,
  109.                 w = tft.width(),
  110.                 h = tft.height();

  111.   tft.fillScreen(ILI9341_BLACK);

  112.   x1 = y1 = 0;
  113.   y2    = h - 1;
  114.   start = micros();
  115.   for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  116.   x2    = w - 1;
  117.   for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  118.   t     = micros() - start; // fillScreen doesn't count against timing

  119.   tft.fillScreen(ILI9341_BLACK);

  120.   x1    = w - 1;
  121.   y1    = 0;
  122.   y2    = h - 1;
  123.   start = micros();
  124.   for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  125.   x2    = 0;
  126.   for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  127.   t    += micros() - start;

  128.   tft.fillScreen(ILI9341_BLACK);

  129.   x1    = 0;
  130.   y1    = h - 1;
  131.   y2    = 0;
  132.   start = micros();
  133.   for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  134.   x2    = w - 1;
  135.   for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  136.   t    += micros() - start;

  137.   tft.fillScreen(ILI9341_BLACK);

  138.   x1    = w - 1;
  139.   y1    = h - 1;
  140.   y2    = 0;
  141.   start = micros();
  142.   for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  143.   x2    = 0;
  144.   for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);

  145.   return micros() - start;
  146. }

  147. unsigned long testFastLines(uint16_t color1, uint16_t color2) {
  148.   unsigned long start;
  149.   int           x, y, w = tft.width(), h = tft.height();

  150.   tft.fillScreen(ILI9341_BLACK);
  151.   start = micros();
  152.   for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
  153.   for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);

  154.   return micros() - start;
  155. }

  156. unsigned long testRects(uint16_t color) {
  157.   unsigned long start;
  158.   int           n, i, i2,
  159.                 cx = tft.width()  / 2,
  160.                 cy = tft.height() / 2;

  161.   tft.fillScreen(ILI9341_BLACK);
  162.   n     = min(tft.width(), tft.height());
  163.   start = micros();
  164.   for(i=2; i<n; i+=6) {
  165.     i2 = i / 2;
  166.     tft.drawRect(cx-i2, cy-i2, i, i, color);
  167.   }

  168.   return micros() - start;
  169. }

  170. unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
  171.   unsigned long start, t = 0;
  172.   int           n, i, i2,
  173.                 cx = tft.width()  / 2 - 1,
  174.                 cy = tft.height() / 2 - 1;

  175.   tft.fillScreen(ILI9341_BLACK);
  176.   n = min(tft.width(), tft.height());
  177.   for(i=n; i>0; i-=6) {
  178.     i2    = i / 2;
  179.     start = micros();
  180.     tft.fillRect(cx-i2, cy-i2, i, i, color1);
  181.     t    += micros() - start;
  182.     // Outlines are not included in timing results
  183.     tft.drawRect(cx-i2, cy-i2, i, i, color2);
  184.   }

  185.   return t;
  186. }

  187. unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
  188.   unsigned long start;
  189.   int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;

  190.   tft.fillScreen(ILI9341_BLACK);
  191.   start = micros();
  192.   for(x=radius; x<w; x+=r2) {
  193.     for(y=radius; y<h; y+=r2) {
  194.       tft.fillCircle(x, y, radius, color);
  195.     }
  196.   }

  197.   return micros() - start;
  198. }

  199. unsigned long testCircles(uint8_t radius, uint16_t color) {
  200.   unsigned long start;
  201.   int           x, y, r2 = radius * 2,
  202.                 w = tft.width()  + radius,
  203.                 h = tft.height() + radius;

  204.   // Screen is not cleared for this one -- this is
  205.   // intentional and does not affect the reported time.
  206.   start = micros();
  207.   for(x=0; x<w; x+=r2) {
  208.     for(y=0; y<h; y+=r2) {
  209.       tft.drawCircle(x, y, radius, color);
  210.     }
  211.   }

  212.   return micros() - start;
  213. }

  214. unsigned long testTriangles() {
  215.   unsigned long start;
  216.   int           n, i, cx = tft.width()  / 2 - 1,
  217.                       cy = tft.height() / 2 - 1;

  218.   tft.fillScreen(ILI9341_BLACK);
  219.   n     = min(cx, cy);
  220.   start = micros();
  221.   for(i=0; i<n; i+=5) {
  222.     tft.drawTriangle(
  223.       cx    , cy - i, // peak
  224.       cx - i, cy + i, // bottom left
  225.       cx + i, cy + i, // bottom right
  226.       tft.color565(0, 0, i));
  227.   }

  228.   return micros() - start;
  229. }

  230. unsigned long testFilledTriangles() {
  231.   unsigned long start, t = 0;
  232.   int           i, cx = tft.width()  / 2 - 1,
  233.                    cy = tft.height() / 2 - 1;

  234.   tft.fillScreen(ILI9341_BLACK);
  235.   start = micros();
  236.   for(i=min(cx,cy); i>10; i-=5) {
  237.     start = micros();
  238.     tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
  239.       tft.color565(0, i, i));
  240.     t += micros() - start;
  241.     tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
  242.       tft.color565(i, i, 0));
  243.   }

  244.   return t;
  245. }

  246. unsigned long testRoundRects() {
  247.   unsigned long start;
  248.   int           w, i, i2,
  249.                 cx = tft.width()  / 2 - 1,
  250.                 cy = tft.height() / 2 - 1;

  251.   tft.fillScreen(ILI9341_BLACK);
  252.   w     = min(tft.width(), tft.height());
  253.   start = micros();
  254.   for(i=0; i<w; i+=6) {
  255.     i2 = i / 2;
  256.     tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
  257.   }

  258.   return micros() - start;
  259. }

  260. unsigned long testFilledRoundRects() {
  261.   unsigned long start;
  262.   int           i, i2,
  263.                 cx = tft.width()  / 2 - 1,
  264.                 cy = tft.height() / 2 - 1;

  265.   tft.fillScreen(ILI9341_BLACK);
  266.   start = micros();
  267.   for(i=min(tft.width(), tft.height()); i>20; i-=6) {
  268.     i2 = i / 2;
  269.     tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
  270.   }

  271.   return micros() - start;
  272. }
复制代码





一体优盘数据恢复 www.rflashdata.com
硬盘ROM损坏焊爆丢失配ROM服务
buffalo 隨身碟數據救援 bitlocker WDV2 lacie EFS等加密硬盘数据恢复,指纹爱国者加密优盘数据恢复 +86 18620923827
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|硬盘FLASH数据恢复论坛

GMT+8, 2024-11-24 08:14 , Processed in 0.037717 second(s), 25 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表