查看: 4479|回复: 1

[提问] TFT图片显示

[复制链接]
发表于 2012-3-17 15:18:47 | 显示全部楼层 |阅读模式
关键词: 16位数据同时送TFT , 为什么图片扫描不出来
  1. #include "stm32f10x.h"
  2. //#include "JPG.h"
  3. #include "JPG1.h"
  4. //#include "JPG2.h"



  5. /*

  6. 控制线:RS-P3^5; WR-P3^6; RD-P3^7; CS-P1^0; REST-P1^1;

  7. 数据线: DB0-DB7依次连接P0^0-P0^7; DB8-DB15依次连接P2^0-P2^7;

  8. 触摸功能连接方式:(不使用触摸可不连接)
  9. D_CLK-P1^2; D_CS-P1^3; D_DIN-P1^4; D_OUT-P1^6; D_PENIRQ-P1^7;

  10. SD卡接线;(不使用触摸可不连接)
  11. SD_MISO-P31; SD_SCK-P32; SD_MOSI-P33; SD_CS-P34;
  12. */


  13. #define LCD_RS_1 GPIO_SetBits(GPIOB,GPIO_Pin_0)
  14. #define LCD_RS_0 GPIO_ResetBits(GPIOB,GPIO_Pin_0)
  15. #define LCD_RW_1 GPIO_SetBits(GPIOB,GPIO_Pin_1)
  16. #define LCD_RW_0 GPIO_ResetBits(GPIOB,GPIO_Pin_1)
  17. #define LCD_RD_1 GPIO_SetBits(GPIOE,GPIO_Pin_2)
  18. #define LCD_RD_0 GPIO_ResetBits(GPIOE,GPIO_Pin_2)
  19. #define LCD_CS_1 GPIO_SetBits(GPIOE,GPIO_Pin_3)
  20. #define LCD_CS_0 GPIO_ResetBits(GPIOE,GPIO_Pin_3)

  21. #define LCD_REST_1 GPIO_SetBits(GPIOE,GPIO_Pin_4)
  22. #define LCD_REST_0 GPIO_ResetBits(GPIOE,GPIO_Pin_4)
  23. #define Data GPIOF->ODR
  24. //#define LCD_DataPortH GPIOF->ODR
  25. //#define LCD_DataPortL GPIOG->ODR

  26. void delay_nus(unsigned long n);
  27. void delay_nms(unsigned long count);
  28. void RCC_Configuration(void);
  29. void GPIO_Configuration(void);





  30. /******************************************************
  31. ** 函数名:void Lcd_Write_Com( int DH)
  32. ** 描述 :TFT写命令
  33. ** 输入 : 无
  34. ** 输出 :无
  35. ** 返回 :无
  36. ******************************************************/
  37. void Lcd_Write_Com( uint16_t DH) //命令
  38. {
  39. LCD_RS_0;
  40. LCD_CS_0;
  41. Data=DH;
  42. LCD_RW_0;
  43. LCD_RW_1;
  44. LCD_CS_1;

  45. }
  46. /******************************************************
  47. ** 函数名:void lcd_write_color(char hh,char ll)
  48. ** 描述 :TFT写发送图片的高8位数据与低8位数据的颜色位
  49. ** 输入 : 无
  50. ** 输出 :无
  51. ** 返回 :无
  52. ******************************************************/
  53. void lcd_write_color(uint16_t hh) //发送颜色数据为提高速度高8位低8位分别传递
  54. {
  55. LCD_RS_1;
  56. LCD_CS_0;
  57. Data=hh;
  58. LCD_RW_0;
  59. LCD_RW_1;
  60. LCD_CS_1;

  61. }
  62. /******************************************************
  63. ** 函数名:void Lcd_Write_Data(int DH)
  64. ** 描述 :TFT写发送图片的高8位数据与低8位数据
  65. ** 输入 : 无
  66. ** 输出 :无
  67. ** 返回 :无
  68. ******************************************************/
  69. void Lcd_Write_Data(uint16_t DH) //数据
  70. {
  71. LCD_RS_1;
  72. LCD_CS_0;
  73. Data=DH;
  74. LCD_RW_0;
  75. LCD_RW_1;
  76. LCD_CS_1;

  77. }

  78. /******************************************************
  79. ** 函数名:void Lcd_Write_Com_Data( int com1,int dat1)
  80. ** 描述 :TFT写命令数据
  81. ** 输入 : 无
  82. ** 输出 :无
  83. ** 返回 :无
  84. ******************************************************/
  85. void Lcd_Write_Com_Data( uint16_t com1,uint16_t dat1) //命令数据一起
  86. {
  87. Lcd_Write_Com(com1);
  88. Lcd_Write_Data(dat1);
  89. }
  90. /******************************************************
  91. ** 函数名:void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
  92. ** 描述 :设置窗口显示扫描开始地址
  93. ** 输入 : 无
  94. ** 输出 :无
  95. ** 返回 :无
  96. ******************************************************/
  97. void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
  98. {
  99. Lcd_Write_Com_Data(0x0044,(x2<<8)+x1);
  100. Lcd_Write_Com_Data(0x0045,y1);
  101. Lcd_Write_Com_Data(0x0046,y2);
  102. Lcd_Write_Com_Data(0x004e,x1);
  103. Lcd_Write_Com_Data(0x004f,y1);
  104. Lcd_Write_Com(0x0022);

  105. }
  106. /******************************************************
  107. ** 函数名:void main_init(void)
  108. ** 描述 :TFT控制器初始化配置
  109. ** 输入 : 无
  110. ** 输出 :无
  111. ** 返回 :无
  112. ******************************************************/
  113. void main_init(void)
  114. {

  115. LCD_REST_1;
  116. delay_nms(5);
  117. LCD_REST_0;
  118. delay_nms(10);
  119. LCD_REST_1;
  120. LCD_CS_1;
  121. LCD_RD_1;
  122. LCD_RW_1;
  123. delay_nms(20);

  124. Lcd_Write_Com_Data(0x0000,0x0001); delay_nms(1); //打开晶振
  125. Lcd_Write_Com_Data(0x0003,0xA8A4); delay_nms(1); //0xA8A4
  126. Lcd_Write_Com_Data(0x000C,0x0000); delay_nms(1);
  127. Lcd_Write_Com_Data(0x000D,0x080C); delay_nms(1);
  128. Lcd_Write_Com_Data(0x000E,0x2B00); delay_nms(1);
  129. Lcd_Write_Com_Data(0x001E,0x00B0); delay_nms(1);
  130. Lcd_Write_Com_Data(0x0001,0x2B3F); delay_nms(1); //驱动输出控制320*240 0x6B3F
  131. Lcd_Write_Com_Data(0x0002,0x0600); delay_nms(1);
  132. Lcd_Write_Com_Data(0x0010,0x0000); delay_nms(1);
  133. Lcd_Write_Com_Data(0x0011,0x6070); delay_nms(1); //0x4030 //定义数据格式 16位色
  134. Lcd_Write_Com_Data(0x0005,0x0000); delay_nms(1);
  135. Lcd_Write_Com_Data(0x0006,0x0000); delay_nms(1);
  136. Lcd_Write_Com_Data(0x0016,0xEF1C); delay_nms(1);
  137. Lcd_Write_Com_Data(0x0017,0x0003); delay_nms(1);
  138. Lcd_Write_Com_Data(0x0007,0x0233); delay_nms(1); //0x0233
  139. Lcd_Write_Com_Data(0x000B,0x0000); delay_nms(1);
  140. Lcd_Write_Com_Data(0x000F,0x0000); delay_nms(1); //扫描开始地址
  141. Lcd_Write_Com_Data(0x0041,0x0000); delay_nms(1);
  142. Lcd_Write_Com_Data(0x0042,0x0000); delay_nms(1);
  143. Lcd_Write_Com_Data(0x0048,0x0000); delay_nms(1);
  144. Lcd_Write_Com_Data(0x0049,0x013F); delay_nms(1);
  145. Lcd_Write_Com_Data(0x004A,0x0000); delay_nms(1);
  146. Lcd_Write_Com_Data(0x004B,0x0000); delay_nms(1);
  147. Lcd_Write_Com_Data(0x0044,0xEF00); delay_nms(1);
  148. Lcd_Write_Com_Data(0x0045,0x0000); delay_nms(1);
  149. Lcd_Write_Com_Data(0x0046,0x013F); delay_nms(1);
  150. Lcd_Write_Com_Data(0x0030,0x0707); delay_nms(1);
  151. Lcd_Write_Com_Data(0x0031,0x0204); delay_nms(1);
  152. Lcd_Write_Com_Data(0x0032,0x0204); delay_nms(1);
  153. Lcd_Write_Com_Data(0x0033,0x0502); delay_nms(1);
  154. Lcd_Write_Com_Data(0x0034,0x0507); delay_nms(1);
  155. Lcd_Write_Com_Data(0x0035,0x0204); delay_nms(1);
  156. Lcd_Write_Com_Data(0x0036,0x0204); delay_nms(1);
  157. Lcd_Write_Com_Data(0x0037,0x0502); delay_nms(1);
  158. Lcd_Write_Com_Data(0x003A,0x0302); delay_nms(1);
  159. Lcd_Write_Com_Data(0x003B,0x0302); delay_nms(1);
  160. Lcd_Write_Com_Data(0x0023,0x0000); delay_nms(1);
  161. Lcd_Write_Com_Data(0x0024,0x0000); delay_nms(1);
  162. Lcd_Write_Com_Data(0x0025,0x8000); delay_nms(1);
  163. Lcd_Write_Com_Data(0x004f,0); //行首址0
  164. Lcd_Write_Com_Data(0x004e,0); //列首址0
  165. Lcd_Write_Com(0x0022);
  166. }
  167. /******************************************************
  168. ** 函数名:void Pant(unsigned int color)
  169. ** 描述 :TFT初始化清屏显示
  170. ** 输入 : 无
  171. ** 输出 :无
  172. ** 返回 :无
  173. ******************************************************/
  174. void Pant(unsigned int color)
  175. {
  176. int i,j;
  177. Address_set(0,0,239,319);

  178. for(i=0;i<320;i++)
  179. {
  180. for (j=0;j<240;j++)
  181. {
  182. Lcd_Write_Data(color);
  183. }

  184. }
  185. }

  186. int main()
  187. {
  188. int i;
  189. uint16_t data=0;
  190. SystemInit();
  191. RCC_Configuration();
  192. GPIO_Configuration();
  193. main_init(); //tft初始化



  194. //Pant(0xf800); //红色
  195. //Pant(0X07E0); //绿色
  196. //Pant(0x001f); //蓝色
  197. Pant(0xffff); //清屏

  198. delay_nms(10);

  199. Address_set(0,0,239,319); //设置图片扫描的起始位置
  200. for(i=0;i<76800;i++)
  201. {
  202. data=image1[i*2];
  203. data=data<<8;
  204. data=data+image1[i*2+1];
  205. //delay_nms(10);
  206. lcd_write_color(data); //数据的高8位与低8位分别传送
  207. // delay_nms(1);
  208. }
  209. /*
  210. for(k=0;k<8;k++)
  211. {
  212. for(j=0;j<6;j++)
  213. {
  214. Address_set(40*j,40*k,40*j+39,40*k+39); //坐标设置
  215. for(i=0;i<1600;i++)
  216. {
  217. lcd_write_color(image[i*2+1],image[i*2]); //发送颜色数据为提高速度高8位低8位分别传递
  218. }
  219. }
  220. }
  221. */
  222. while(1);
  223. }
  224. /******************************************************
  225. ** 函数名:void RCC_Configuration()
  226. ** 描述 :us延时函数
  227. ** 输入 : 无
  228. ** 输出 :无
  229. ** 返回 :无
  230. ******************************************************/
  231. void RCC_Configuration()
  232. {
  233. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG,ENABLE);
  234. //RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
  235. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
  236. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);
  237. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);
  238. }
  239. /******************************************************
  240. ** 函数名:void GPIO_Configuration()
  241. ** 描述 :GPIO端口初始化
  242. ** 输入 : 无
  243. ** 输出 :无
  244. ** 返回 :无
  245. ******************************************************/
  246. void GPIO_Configuration()
  247. {
  248. GPIO_InitTypeDef GPIO_InitStructure;
  249. GPIO_InitStructure.GPIO_Pin=GPIO_Pin_All;
  250. GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  251. GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  252. GPIO_Init(GPIOF,&GPIO_InitStructure);

  253. GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
  254. GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  255. GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  256. GPIO_Init(GPIOG,&GPIO_InitStructure);

  257. GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1;
  258. GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  259. GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  260. GPIO_Init(GPIOB,&GPIO_InitStructure);

  261. GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4;
  262. GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  263. GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  264. GPIO_Init(GPIOE,&GPIO_InitStructure);
  265. }

  266. /******************************************************
  267. ** 函数名:void delay_nus(unsigned long n)
  268. ** 描述 :us延时函数
  269. ** 输入 : 无
  270. ** 输出 :无
  271. ** 返回 :无
  272. ******************************************************/
  273. void delay_nus(unsigned long n)
  274. {
  275. unsigned long j;
  276. while(n--)
  277. {
  278. j=8;
  279. while(j--);
  280. }
  281. }
  282. /******************************************************
  283. ** 函数名:void delay_nms(unsigned long n)
  284. ** 描述 :ms延时函数
  285. ** 输入 : 无
  286. ** 输出 :无
  287. ** 返回 :无
  288. ******************************************************/
  289. void delay_nms(unsigned long count) // /* X1ms */
  290. {
  291. int i,j;
  292. for(i=0;i
  293. for(j=0;j<100;j++);
  294. }

复制代码
发表于 2012-4-17 16:14:33 | 显示全部楼层
谢分享。。。。。。。。。。。。。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于我们  -  服务条款  -  使用指南  -  站点地图  -  友情链接  -  联系我们
电子工程网 © 版权所有   京ICP备16069177号 | 京公网安备11010502021702
快速回复 返回顶部 返回列表