返回列表 回复 发帖

打造史上最强tft学习贴(持续更新中。。。。。)

本帖势在为广大网友 提供一个全面的tft学习资料和笔记贴。
  需要的网友可以到论坛上边淘宝店购买 或者 发帖留言
  • 主题   TFT学习强贴
  •                        目录
  •             1# ---------------目录
  •             2# --------------TFT模块原理图(protel 99se)
  •             3# --------------PCB板(图片)
  •             4#---------------TFT模块成品(图片)
  •             5#---------------TFT模块效果图片
  •             6# --------------应用代码集合(包括基本驱动、gui、JPG解码等)
  •             7#---------------TFT屏规格书
  •             8#---------------ADS7843 datasheet
  •             12#--------------ADS7843 触摸代码(移植到stmsky001开发板)
  •             13#--------------TFT屏使用8位接口方式驱动程序(移植stmsky001开发板)
  •           16# ----------------- 官方裸奔gui程序 基于stm32
  •           17#-----------------本论坛STM32SKY开发板上移植的GUI程序,支持 IAR和KEI 两个版本,STM32固件库 3.1.2
在路上 我们一起奋斗
淘宝平台:http://shop60442272.taobao.com/
原理图  protel版本

Backup of 2.8tft.Sch (16.69 KB)

在路上 我们一起奋斗
淘宝平台:http://shop60442272.taobao.com/
pcb板
模块-3.jpg
在路上 我们一起奋斗
淘宝平台:http://shop60442272.taobao.com/
模块
未命名-1.jpg
在路上 我们一起奋斗
淘宝平台:http://shop60442272.taobao.com/
点亮
子.jpg
字1.jpg
子2.jpg
在路上 我们一起奋斗
淘宝平台:http://shop60442272.taobao.com/
1 移植了ucos+ucgui的Demo程序(相机有点问题,稍后上图)
复制代码
2 lcd显示 实时时间界面

复制代码


3 lcd显示  画了一个小人

复制代码


4 jpeg解码的移植

复制代码
在路上 我们一起奋斗
淘宝平台:http://shop60442272.taobao.com/
  1. http://www.stmsky.com/bbs/viewth ... p;extra=&page=1

  2. 规格和驱动
复制代码
在路上 我们一起奋斗
淘宝平台:http://shop60442272.taobao.com/
触摸芯片ADS7843 datasheet:
ADS7843.pdf (251.22 KB)
在路上 我们一起奋斗
淘宝平台:http://shop60442272.taobao.com/
谢谢分享!
谢谢分享!
谢谢分享!
触摸屏 的 初始化过程----移植成功:
  1. #define TP_CS() GPIO_ResetBits(GPIOC,GPIO_Pin_4)
  2. #define TP_DCS() GPIO_SetBits(GPIOC,GPIO_Pin_4)

  3. void Touch_Initializtion(void)
  4. {
  5. GPIO_InitTypeDef GPIO_InitStructure;
  6. SPI_InitTypeDef SPI_InitStructure;

  7. //GPIO Periph clock enable
  8. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO,ENABLE);
  9. //RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
  10. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);

  11. //RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);

  12. //SPI2 Periph clock enable
  13. RCC_APB2PeriphClockCmd( RCC_APB2Periph_SPI1, ENABLE );

  14. //Configure SPI2 pins: SCK, MISO and MOSI
  15. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_7|GPIO_Pin_6;
  16. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  17. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
  18. GPIO_Init(GPIOA,&GPIO_InitStructure);

  19. //Configure PF10 pin: TP_CS pin
  20. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
  21. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  22. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
  23. GPIO_Init(GPIOC,&GPIO_InitStructure);

  24. //Configure PA8 pin: TP_BUSY pin
  25. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 ;
  26. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  27. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入
  28. // GPIO_Init(GPIOG,&GPIO_InitStructure);

  29. // Configure PE.06 as input floating For TP_IRQ
  30. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  31. // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  32. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  33. GPIO_Init(GPIOC,&GPIO_InitStructure);

  34. // SPI1 Config
  35. SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  36. SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  37. SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  38. SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
  39. SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
  40. SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  41. SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;
  42. SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  43. SPI_InitStructure.SPI_CRCPolynomial = 7;
  44. SPI_Init(SPI1,&SPI_InitStructure);

  45. // SPI1 enable
  46. SPI_Cmd(SPI1,ENABLE);
  47. }

  48. u8 Touch_PenIRQ(void)
  49. {
  50. // PG7 -> TS_nPENIRQ
  51. return GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_5);
  52. }

  53. unsigned char SPI_WriteByte(unsigned char data)
  54. {
  55. unsigned char Data = 0;

  56. //Wait until the transmit buffer is empty
  57. while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE)==RESET);
  58. // Send the byte
  59. SPI_I2S_SendData(SPI1,data);

  60. //Wait until a data is received
  61. while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_RXNE)==RESET);
  62. // Get the received data
  63. Data = SPI_I2S_ReceiveData(SPI1);

  64. // Return the shifted data
  65. return Data;
  66. }

  67. void SpiDelay(unsigned int DelayCnt)
  68. {
  69. unsigned int i;
  70. for(i=0;i<DelayCnt;i++);
  71. }

  72. u16 ReadTouchAD(u16 mode)
  73. {
  74. u8 RegVal;
  75. u16 x=0;

  76. switch(mode)
  77. {
  78. case TouchModeX:
  79. RegVal=TouchCommandX;
  80. break;
  81. case TouchModeY:
  82. RegVal=TouchCommandY;
  83. break;
  84. case TouchModeIn3:
  85. RegVal=TouchCommandIn3;
  86. break;
  87. case TouchModeIn4:
  88. RegVal=TouchCommandIn4;
  89. break;
  90. default:
  91. RegVal=TouchCommandY;
  92. break;
  93. }

  94. TP_CS();
  95. SpiDelay(10);
  96. SPI_WriteByte(RegVal);
  97. SpiDelay(10);
  98. x=SPI_WriteByte(0x00);
  99. x<<=8;
  100. x+=SPI_WriteByte(0x00);
  101. SpiDelay(10);
  102. TP_DCS();
  103. return (x>>3);
  104. }

  105. u16 GetTouchVal(u16 mode)
  106. {
  107. u16 n,i,j;
  108. u16 buf[7];
  109. u16 temp;

  110. for (n=0;n<7;n++)
  111. {
  112. buf[n] = ReadTouchAD(mode);
  113. SpiDelay(1000);
  114. }

  115. for (j=0;j<7-1;j++)
  116. {
  117. for (i=0;i<7-j;i++)
  118. {
  119. if ( buf[i]>buf[i+1] )
  120. {
  121. temp = buf[i];
  122. buf[i] = buf[i+1];
  123. buf[i+1] = temp;
  124. }
  125. }
  126. }

  127. return ( (buf[2]+buf[3]+buf[4])/3 );
  128. }


  129. static tMinMax xyMinMax[2] = {
  130. #if TOUCH_AD_LEFT < TOUCH_AD_RIGHT
  131. { TOUCH_AD_LEFT, TOUCH_AD_RIGHT },
  132. #else
  133. { TOUCH_AD_RIGHT, TOUCH_AD_LEFT },
  134. #endif
  135. #if TOUCH_AD_TOP < TOUCH_AD_BOTTOM
  136. { TOUCH_AD_TOP, TOUCH_AD_BOTTOM }
  137. #else
  138. { TOUCH_AD_BOTTOM, TOUCH_AD_TOP }
  139. #endif
  140. };


  141. u16 AD2X(void)
  142. {
  143. u16 adx;
  144. u32 r;

  145. adx = GetTouchVal(TouchModeX);

  146. if(adx > xyMinMax[COORD_X].Max) return InvalidKey;
  147. if(adx < xyMinMax[COORD_X].Min) return InvalidKey;

  148. r = adx - xyMinMax[COORD_X].Min;
  149. r *= TOUCH_XSIZE - 1;
  150. return r / (xyMinMax[COORD_X].Max - xyMinMax[COORD_X].Min);
  151. }

  152. u16 AD2Y(void)
  153. {
  154. u16 ady;
  155. u32 r;

  156. ady = GetTouchVal(TouchModeY);

  157. if(ady > xyMinMax[COORD_Y].Max) return InvalidKey;
  158. if(ady < xyMinMax[COORD_Y].Min) return InvalidKey;

  159. r = ady - xyMinMax[COORD_Y].Min;
  160. r *= TOUCH_YSIZE - 1;
  161. return r/(xyMinMax[COORD_Y].Max - xyMinMax[COORD_Y].Min);
  162. }


  163. u16 GetTouchX(void)
  164. {
  165. u16 X;
  166. X = AD2X();
  167. if(X == InvalidKey)
  168. return InvalidKey;
  169. else
  170. {
  171. #if TOUCH_AD_LEFT < TOUCH_AD_RIGHT
  172. return X;
  173. #else
  174. return TOUCH_XSIZE-X;
  175. #endif
  176. }
  177. }

  178. u16 GetTouchY(void)
  179. {
  180. u16 Y;
  181. Y = AD2Y();
  182. if(Y == InvalidKey)
  183. return InvalidKey;
  184. else
  185. {
  186. #if TOUCH_AD_TOP < TOUCH_AD_BOTTOM
  187. return Y;
  188. #else
  189. return TOUCH_YSIZE-Y;
  190. #endif
  191. }
  192. }
复制代码
在路上 我们一起奋斗
淘宝平台:http://shop60442272.taobao.com/
为了 配合使用8位机 16位机的朋友 更好的使用本论坛的tft屏  在这里 我们专门做了8位接口的程序:
  1. void LCD_GPIO_Config(void)
  2. {
  3. GPIO_InitTypeDef GPIO_InitStructure;

  4. /* Enable GPIOE lcd data clock */
  5. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
  6. GPIO_InitStructure.GPIO_Pin = 0x000000ff;
  7. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  8. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  9. GPIO_Init(GPIOE, &GPIO_InitStructure);

  10. /* Enable GPIOA clock */
  11. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  12. GPIO_InitStructure.GPIO_Pin = LCD_RST_BIT|LCD_RD_BIT|LCD_WR_BIT|LCD_CS_BIT|LCD_BL_BIT|LCD_RS_BIT;
  13. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  14. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  15. GPIO_Init(GPIOA, &GPIO_InitStructure);
  16. }
  17. void LCD_WR_DATA16(unsigned int data)//写积存器数据
  18. {
  19. LCD_RD_H();
  20. LCD_RS_H();
  21. LCD_CS_L();
  22. LCD_WR_L();
  23. DATA_LCD_PORT=data>>8;
  24. LCD_WR_H();
  25. LCD_WR_L();
  26. DATA_LCD_PORT=data&0XFF;
  27. LCD_WR_H();
  28. LCD_CS_H();

  29. }
  30. void LCD_WR_REG16(unsigned int index)//写积存器命令
  31. {
  32. LCD_RD_H();
  33. LCD_RS_L();
  34. LCD_CS_L();
  35. LCD_WR_L();
  36. DATA_LCD_PORT=index>>8;
  37. LCD_WR_H();
  38. LCD_WR_L();
  39. DATA_LCD_PORT=index&0XFF;
  40. LCD_WR_H();
  41. LCD_CS_H();
  42. }

  43. void LCD_WR_REG(unsigned int index,unsigned int data)
  44. {
  45. LCD_WR_REG16(index);
  46. LCD_WR_DATA16(data);
  47. }
  48. void LCD_Init(void)
  49. {
  50. LCD_GPIO_Config();
  51. LCD_RST_L();//硬件复位
  52. delay_ms(400);
  53. LCD_RST_H();
  54. delay_ms(400);
  55. //initializing funciton 1
  56. LCD_WR_REG(0x01, 0x0000); // set SS and SM bit
  57. LCD_WR_REG(0x02, 0x0700); // set 1 line inversion
  58. // LCD_WR_REG(0x03, 0x10B0); // set GRAM write direction and BGR=1.
  59. #if ID_AM==000
  60. LCD_WR_REG(0x0003,0x1000);//屏幕旋转控制 TFM=0,TRI=0,SWAP=1,16 bits system interface swap RGB to BRG,此处ORG和HWM 为0
  61. #elif ID_AM==001
  62. LCD_WR_REG(0x0003,0x1008);
  63. #elif ID_AM==010
  64. LCD_WR_REG(0x0003,0x1010);
  65. #elif ID_AM==011
  66. LCD_WR_REG(0x0003,0x1018);
  67. #elif ID_AM==100
  68. LCD_WR_REG(0x0003,0x1020);
  69. #elif ID_AM==101
  70. LCD_WR_REG(0x0003,0x1028);
  71. #elif ID_AM==110
  72. LCD_WR_REG(0x0003,0x1030);
  73. #elif ID_AM==111
  74. LCD_WR_REG(0x0003,0x1038);
  75. #endif
  76. LCD_WR_REG(0x04, 0x0000); // Resize register
  77. LCD_WR_REG(0x08, 0x0207); // set the back porch and front porch
  78. LCD_WR_REG(0x09, 0x0000); // set non-display area refresh cycle ISC[3:0]
  79. LCD_WR_REG(0x0A, 0x0000); // FMARK function
  80. LCD_WR_REG(0x0C, 0x0000); // RGB interface setting
  81. LCD_WR_REG(0x0D, 0x0000); // Frame marker Position
  82. LCD_WR_REG(0x0F, 0x0000); // RGB interface polarity
  83. //*************Power On sequence ****************//
  84. LCD_WR_REG(0x10, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB
  85. LCD_WR_REG(0x11, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
  86. LCD_WR_REG(0x12, 0x0000); // VREG1OUT voltage
  87. LCD_WR_REG(0x13, 0x0000); // VDV[4:0] for VCOM amplitude
  88. delay_ms(3000); // Dis-charge capacitor power voltage

  89. LCD_WR_REG(0x10, 0x1590); // SAP, BT[3:0], AP, DSTB, SLP, STB
  90. LCD_WR_REG(0x11, 0x0227); // DC1[2:0], DC0[2:0], VC[2:0]
  91. delay_ms(200); // Delay 50ms

  92. LCD_WR_REG(0x12, 0x009b); // Internal reference voltage= Vci;
  93. delay_ms(200); // Delay 50ms
  94. LCD_WR_REG(0x13, 0x1f00); // Set VDV[4:0] for VCOM amplitude
  95. LCD_WR_REG(0x29, 0x001f); // Set VCM[5:0] for VCOMH
  96. LCD_WR_REG(0x2B, 0x000e); // Set Frame Rate
  97. delay_ms(200); // Delay 50ms

  98. #if ID_AM==000
  99. LCD_WR_REG(0x0020,0x00ef);//GRAM水平起始位置
  100. LCD_WR_REG(0x0021,0x013f);
  101. #elif ID_AM==001
  102. LCD_WR_REG(0x0020,0x00ef);
  103. LCD_WR_REG(0x0021,0x013f);
  104. #elif ID_AM==010
  105. LCD_WR_REG(0x0020,0x0000);
  106. LCD_WR_REG(0x0021,0x013f);
  107. #elif ID_AM==011
  108. LCD_WR_REG(0x0020,0x0000);
  109. LCD_WR_REG(0x0021,0x013f);
  110. #elif ID_AM==100
  111. LCD_WR_REG(0x0020,0x00ef);
  112. LCD_WR_REG(0x0021,0x0000);
  113. #elif ID_AM==101
  114. LCD_WR_REG(0x0020,0x00ef);
  115. LCD_WR_REG(0x0021,0x0000);
  116. #elif ID_AM==110
  117. LCD_WR_REG(0x0020,0x0000);
  118. LCD_WR_REG(0x0021,0x0000);
  119. #elif ID_AM==111
  120. LCD_WR_REG(0x0020,0x0000);
  121. LCD_WR_REG(0x0021,0x0000);
  122. #endif

  123. // ----------- Adjust the Gamma Curve ----------//
  124. LCD_WR_REG(0x30, 0x0201);
  125. LCD_WR_REG(0x31, 0x0707);
  126. LCD_WR_REG(0x32, 0x0407);
  127. LCD_WR_REG(0x35, 0x0101);
  128. LCD_WR_REG(0x36, 0x0407);
  129. LCD_WR_REG(0x37, 0x0003);
  130. LCD_WR_REG(0x38, 0x0000);
  131. LCD_WR_REG(0x39, 0x0605);
  132. LCD_WR_REG(0x3C, 0x0101);
  133. LCD_WR_REG(0x3D, 0x0606);


  134. //------------------ Set GRAM area ---------------//
  135. LCD_WR_REG(0x50, 0x0000); // Horizontal GRAM Start Address
  136. LCD_WR_REG(0x51, 0x00EF); // Horizontal GRAM End Address
  137. LCD_WR_REG(0x52, 0x0000); // Vertical GRAM Start Address
  138. LCD_WR_REG(0x53, 0x013F); // Vertical GRAM Start Address
  139. LCD_WR_REG(0x60, 0x2700); // Gate Scan Line A700
  140. LCD_WR_REG(0x61, 0x0001); // NDL,VLE, REV
  141. LCD_WR_REG(0x6A, 0x0000); // set scrolling line
  142. //-------------- Partial Display Control ---------//
  143. LCD_WR_REG(0x80, 0x0000);
  144. LCD_WR_REG(0x81, 0x0000);
  145. LCD_WR_REG(0x82, 0x0000);
  146. LCD_WR_REG(0x83, 0x0000);
  147. LCD_WR_REG(0x84, 0x0000);
  148. LCD_WR_REG(0x85, 0x0000);
  149. //-------------- Panel Control -------------------//
  150. LCD_WR_REG(0x90, 0x0010);
  151. LCD_WR_REG(0x92, 0x0600);
  152. LCD_WR_REG(0x93, 0x0003);
  153. LCD_WR_REG(0x95, 0x0110);
  154. LCD_WR_REG(0x97, 0x0000);
  155. LCD_WR_REG(0x98, 0x0000);
  156. LCD_WR_REG(0x07, 0x0173); // 262K color and display ON 0133
  157. LCD_Clear(0);
  158. delay_ms(200); // Delay 5ms
  159. LCD_BL_H();

  160. }

  161. /**********************************************
  162. 函数名:Lcd全屏擦除函数
  163. 功能:将Lcd整屏擦为指定颜色
  164. 入口参数:color 指定Lcd全屏颜色 RGB(5-6-5)
  165. 返回值:无
  166. ***********************************************/
  167. void LCD_Clear(unsigned int Color)
  168. {
  169. unsigned long index = 0;

  170. LCD_WR_REG(0x0020,0x0000);//GRAM水平起始位置
  171. LCD_WR_REG(0x0021,0x013F);

  172. LCD_WR_REG(0x0050,0x00);//水平 GRAM起始位置
  173. LCD_WR_REG(0x0051,239);//水平GRAM终止位置
  174. LCD_WR_REG(0x0052,0x00);//垂直GRAM起始位置
  175. LCD_WR_REG(0x0053,319);//垂直GRAM终止位置
  176. LCD_WR_REG16(0x0022);

  177. LCD_RD_H();
  178. LCD_RS_H();
  179. LCD_CS_L();
  180. for(index = 0; index < 76800; index++)
  181. {
  182. // LCD_WR_DATA16(Color);

  183. LCD_WR_L();
  184. DATA_LCD_PORT=Color>>8;
  185. LCD_WR_H();
  186. LCD_WR_L();
  187. DATA_LCD_PORT=Color&0XFF;
  188. LCD_WR_H();


  189. }
  190. LCD_CS_H();
  191. }
复制代码

8位tftstm家园.rar (1.7 MB)

在路上 我们一起奋斗
淘宝平台:http://shop60442272.taobao.com/
8位 16位 使用的屏模块 完全相通  不必使用74系列的芯片即可
在路上 我们一起奋斗
淘宝平台:http://shop60442272.taobao.com/
稍后上照片
在路上 我们一起奋斗
淘宝平台:http://shop60442272.taobao.com/
返回列表