Randy 发表于 2012-4-16 09:59:44

arduino学习笔记33 - Mega 2560+TFT3.2寸屏的演示实验

经过了一段时间的学习,慢慢的对TFT 有一些些的了解,对于我们这些初学者来说,写驱动那是不可能的事情,唯一能做的就是看得懂驱动是啥、或者是很好的阅读驱动程序即可。如果是应用,那会这些足矣!如果是开发的,那还需要更多的学习和了解。之前群里的Zzz玩过TFT 3.2+mega2560的,只是他时间有点忙吧,没时间出来写测评,我现在能驱动了,就出来说一下是怎么用的吧。欢迎大家一起讨论实验中的问题,毕竟把问题都回答完了就会理解一点的。
介绍
HY-TFT320是一个3.2英寸屏幕的TFT液晶模块,320X240(分辨率),65K色,40引脚接口,而不只是一个LCD的模块,因为它包含触摸功能和SD卡,所以这是一个强大的显示扩展模块。这个TFT的控制IC是SSD1289,它是16位数据接口的,相对比较容易驱动它,我们可以使用STM32、AVR、8051单片机对它进行控制,HY-TFT320里面也包含了一个触摸控制IC(XPT2046),而且触摸接口也是包含在屏幕的40引脚中,其中还含有SD卡相应的接口,所以此块TFT模块功能还算是比较丰富的。
规格:
1、3.2寸彩屏TFT LCD
2、分辨率 320X240
3、65535种颜色(16位)
4、强大的16位控制器(SSD1289)
5、内置视频内存缓冲区
6、集成电阻触摸屏
7、集成SD卡
8、5V操作电压
9、LED背光

应用
数码相框(DPF)
视频终端
测试设备
GPS
游戏机
视频电视和便携式VCD、DVD

引脚定义:


首先所使用的器材:
一个mega 2560
一个mega V4 扩展板
一个 TFT 3.2寸(主控IC是SSD1289 、触控IC是XPT2046)
一条USB线
若干条杜邦线等等

在这里引用一下本链接的学习资料:http://www.geeetech.com/2012/04/interface-3-2tft-lcd-module-to-arduino/

大概的连接方法是这样的:
(LEDK -> GND)   only 3.2″ TFT LCD
LEDA -> 5V
VCC -> 5V
RD -> 3.3V
GND -> GND
DB0->DB7 to pin D37->D30
DB8->DB15 to pin D22->D29
RS -> D38
WR -> D39
CS(pin6) -> D40
RSET-> D41

把线连接好以后,需要把这个库文件拷到Arduino IDE libraries 里面!

看一下我们的实物连接图!


下面是主要的代码!因为现在对于我的TFT 3.2寸没有合适的转接板,所以需要我们一条条连连起来,除非需要自己画一个转接板,这样用起来就方便很多很多啊!#include <ITDB02_Graph16.h>

// Declare which fonts we will be using
extern uint8_t SmallFont[];

// Uncomment the next line for the ITDB02 Shield
//ITDB02 myGLCD(19,18,17,16);

// Uncomment the next line for the ITDB02 Mega Shield
ITDB02 myGLCD(38,39,40,41);

void setup()
{
randomSeed(analogRead(0));

// Setup the LCD
myGLCD.InitLCD();
myGLCD.setFont(SmallFont);
}

void loop()
{
int buf;
int x, x2;
int y, y2;
int r;

// Clear the screen and draw the frame
myGLCD.clrScr();

myGLCD.setColor(255, 0, 0);
myGLCD.fillRect(0, 0, 239, 13);
myGLCD.setColor(64, 64, 64);
myGLCD.fillRect(0, 306, 239, 319);
myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(255, 0, 0);
myGLCD.print("ITDB02 - 240x320 Color Display", CENTER, 1);
myGLCD.setColor(255, 128, 128);
myGLCD.setBackColor(64, 64, 64);
myGLCD.print("H.Karlsen", LEFT, 307);
myGLCD.print("(C)2010", RIGHT, 307);
myGLCD.setColor(255,255,0);
myGLCD.print("Portrait", CENTER, 307);

myGLCD.setColor(0, 0, 255);
myGLCD.drawLine(0, 14, 239, 14);
myGLCD.drawLine(0, 14, 0, 305);
myGLCD.drawLine(239, 14, 239, 305);
myGLCD.drawLine(0, 305, 239, 305);

// Draw crosshairs
myGLCD.setColor(0, 0, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.drawLine(119, 15, 119, 304);
myGLCD.drawLine(1, 159, 238, 159);
for (int i=9; i<240; i+=10)
    myGLCD.drawLine(i, 157, i, 161);
for (int i=19; i<300; i+=10)
    myGLCD.drawLine(117, i, 121, i);

// Draw sin-, cos- and tan-lines
myGLCD.setColor(0,255,255);
myGLCD.print("Sin", 5, 15);
for (int i=1; i<238; i++)
{
    myGLCD.drawPixel(i,159+(sin(((i*1.51)*3.14)/180)*100));
}

myGLCD.setColor(255,0,0);
myGLCD.print("Cos", 5, 27);
for (int i=1; i<238; i++)
{
    myGLCD.drawPixel(i,159+(cos(((i*1.51)*3.14)/180)*100));
}

myGLCD.setColor(255,255,0);
myGLCD.print("Tan", 5, 39);
for (int i=1; i<238; i++)
{
    myGLCD.drawPixel(i,159+(tan(((i*1.51)*3.14)/180)));
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,238,304);
myGLCD.setColor(0, 0, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.drawLine(119, 15, 119, 304);
myGLCD.drawLine(1, 159, 238, 159);

// Draw a moving sinewave
x=1;
for (int i=1; i<6902; i++)
{
    x++;
    if (x==239)
      x=1;
    if (i>239)
    {
      if ((x==119)||(buf==159))
      myGLCD.setColor(0,0,255);
      else
      myGLCD.setColor(0,0,0);
      myGLCD.drawPixel(x,buf);
    }
    myGLCD.setColor(0,255,255);
    y=159+(sin(((i*1.4)*3.14)/180)*(100-(i / 100)));
    myGLCD.drawPixel(x,y);
    buf=y;
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,238,304);

// Draw some filled rectangles
for (int i=1; i<6; i++)
{
    switch (i)
    {
      case 1:
      myGLCD.setColor(255,0,255);
      break;
      case 2:
      myGLCD.setColor(255,0,0);
      break;
      case 3:
      myGLCD.setColor(0,255,0);
      break;
      case 4:
      myGLCD.setColor(0,0,255);
      break;
      case 5:
      myGLCD.setColor(255,255,0);
      break;
    }
    myGLCD.fillRect(30+(i*20), 70+(i*20), 90+(i*20), 130+(i*20));
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,238,304);

// Draw some filled, rounded rectangles
for (int i=1; i<6; i++)
{
    switch (i)
    {
      case 1:
      myGLCD.setColor(255,0,255);
      break;
      case 2:
      myGLCD.setColor(255,0,0);
      break;
      case 3:
      myGLCD.setColor(0,255,0);
      break;
      case 4:
      myGLCD.setColor(0,0,255);
      break;
      case 5:
      myGLCD.setColor(255,255,0);
      break;
    }
    myGLCD.fillRoundRect(150-(i*20),70+(i*20), 210-(i*20), 130+(i*20));
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,238,304);

// Draw some filled circles
for (int i=1; i<6; i++)
{
    switch (i)
    {
      case 1:
      myGLCD.setColor(255,0,255);
      break;
      case 2:
      myGLCD.setColor(255,0,0);
      break;
      case 3:
      myGLCD.setColor(0,255,0);
      break;
      case 4:
      myGLCD.setColor(0,0,255);
      break;
      case 5:
      myGLCD.setColor(255,255,0);
      break;
    }
    myGLCD.fillCircle(60+(i*20),100+(i*20), 30);
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,238,304);

// Draw some lines in a pattern
myGLCD.setColor (255,0,0);
for (int i=15; i<304; i+=5)
{
    myGLCD.drawLine(1, i, (i/1.22)-10, 304);
}
myGLCD.setColor (255,0,0);
for (int i=304; i>15; i-=5)
{
    myGLCD.drawLine(238, i, (i/1.22)-11, 15);
}
myGLCD.setColor (0,255,255);
for (int i=304; i>15; i-=5)
{
    myGLCD.drawLine(1, i, 251-(i/1.22), 15);
}
myGLCD.setColor (0,255,255);
for (int i=15; i<304; i+=5)
{
    myGLCD.drawLine(238, i, 250-(i/1.22), 304);
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,238,304);

// Draw some random circles
for (int i=0; i<100; i++)
{
    myGLCD.setColor(random(255), random(255), random(255));
    x=32+random(175);
    y=45+random(212);
    r=random(30);
    myGLCD.drawCircle(x, y, r);
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,238,304);

// Draw some random rectangles
for (int i=0; i<100; i++)
{
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(236);
    y=16+random(287);
    x2=2+random(236);
    y2=16+random(287);
    myGLCD.drawRect(x, y, x2, y2);
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,238,304);

// Draw some random rounded rectangles
for (int i=0; i<100; i++)
{
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(236);
    y=16+random(287);
    x2=2+random(236);
    y2=16+random(287);
    myGLCD.drawRoundRect(x, y, x2, y2);
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(2,16,238,304);

for (int i=0; i<100; i++)
{
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(236);
    y=16+random(289);
    x2=2+random(236);
    y2=16+random(289);
    myGLCD.drawLine(x, y, x2, y2);
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,238,304);

for (int i=0; i<10000; i++)
{
    myGLCD.setColor(random(255), random(255), random(255));
    myGLCD.drawPixel(2+random(236), 16+random(289));
}

delay(2000);

myGLCD.fillScr(0, 0, 255);
myGLCD.setColor(255, 0, 0);
myGLCD.fillRoundRect(30, 100, 209, 219);

myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(255, 0, 0);
myGLCD.print("That's it!", CENTER, 133);
myGLCD.print("Restarting in a", CENTER, 159);
myGLCD.print("few seconds...", CENTER, 172);

myGLCD.setColor(0, 0, 0);
myGLCD.setBackColor(0, 0, 255);
myGLCD.print("Runtime: (msecs)", CENTER, 290);
myGLCD.printNumI(millis(), CENTER, 305);

delay (10000);
}所用到的库文件!


大家也把自己用过得,有什么问题的,都贴出来大家一起讨论,研究!

zhanggang1971 发表于 2012-4-16 18:10:24

感谢分享,学习了,我也有一块,商家焊好接口的,拿来试试。

ymcu 发表于 2014-6-1 12:52:42

我忽略了什么,不能编译通过(Mega256+TFT3.2)

Randy 发表于 2012-4-16 10:00:11

沙发留给自己来坐了!

黑马 发表于 2012-4-16 10:04:05

好帖!刷新速度如何?

Randy 发表于 2012-4-16 10:06:11

黑马 发表于 2012-4-16 10:04 static/image/common/back.gif
好帖!刷新速度如何?

3秒左右刷新一次,具体没计算过!欢迎你们也试试!

thomas 发表于 2012-4-16 12:28:11

好东西,只是线太夸张了,没有spi的吗?我印象tb有卖的。我没法确定尺寸,所以一直没买

Randy 发表于 2012-4-16 13:37:52

thomas 发表于 2012-4-16 12:28 static/image/common/back.gif
好东西,只是线太夸张了,没有spi的吗?我印象tb有卖的。我没法确定尺寸,所以一直没买

SPI,我没去查过,花点时间去了解一下!欢迎爆料!

河山 发表于 2012-4-16 14:47:59

连地板也没有了,只好围观咯.:P

taotao71 发表于 2012-4-16 15:39:33

我有一个MTK的山寨手机是TFT 3.2的如果可以用2560驱动就太完美了!
我马上研究研究!

Randy 发表于 2012-4-16 16:57:38

taotao71 发表于 2012-4-16 15:39 static/image/common/back.gif
我有一个MTK的山寨手机是TFT 3.2的如果可以用2560驱动就太完美了!
我马上研究研究!

是的,有强大的库,别浪费了资源!期待你也把测评发上来看看!

Randy 发表于 2012-4-16 21:38:19

zhanggang1971 发表于 2012-4-16 18:10 static/image/common/back.gif
感谢分享,学习了,我也有一块,商家焊好接口的,拿来试试。

试了有啥问题或者好的建议过来贴出来分享!

━__Neo_ˇ 发表于 2012-4-17 22:12:24

不顶不行啊···

Randy 发表于 2012-4-17 22:18:23

━__Neo_ˇ 发表于 2012-4-17 22:12 static/image/common/back.gif
不顶不行啊···

谢谢支持,一起分享!

Randy 发表于 2012-4-18 08:37:14

黑马 发表于 2012-4-16 10:04 static/image/common/back.gif
好帖!刷新速度如何?

今天发现,用UNO也是可以驱动的,只是不能实现触摸功能,因为I/O全部被占完,所以...

黑马 发表于 2012-4-18 10:11:45

Randy 发表于 2012-4-18 08:37 static/image/common/back.gif
今天发现,用UNO也是可以驱动的,只是不能实现触摸功能,因为I/O全部被占完,所以...

嗯~要是用串口芯片驱动的话倒是可以节省一些IO,不过估计那个刷新速度就更慢了
页: [1] 2 3 4 5 6
查看完整版本: arduino学习笔记33 - Mega 2560+TFT3.2寸屏的演示实验