新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > s3c2440的觸摸屏校正與測(cè)試

s3c2440的觸摸屏校正與測(cè)試

作者: 時(shí)間:2016-11-20 來(lái)源:網(wǎng)絡(luò) 收藏

本文引用地址:http://butianyuan.cn/article/201611/318934.htm
  1. /********************************************************************
  2. *文件名:main.c
  3. *功能:測(cè)試TFT屏的驅(qū)動(dòng)函數(shù)
  4. *作者:jianqi
  5. *版本:v1.0
  6. ********************************************************************/
  7. #include"2440addr.h"http://包含2440相關(guān)寄存器的設(shè)置
  8. #include"TFT.h"
  9. #include"Touch.h"
  10. #include"MMU.h"
  11. #include"UART.h"
  12. volatileintA,B,C,D,E,F,K;//校正參數(shù)
  13. intflagTS=0;//觸摸屏轉(zhuǎn)換標(biāo)志
  14. intxdata,ydata;//觸摸屏A/D轉(zhuǎn)換數(shù)據(jù)
  15. /*******************************************
  16. *名稱:Touch_Int
  17. *功能:觸摸屏中斷程序,讀取A/D轉(zhuǎn)換的值
  18. *入口參數(shù):無(wú)
  19. *出口參數(shù):無(wú)
  20. **********************************************/
  21. void__irqTouch_Int(void)//中斷函數(shù)
  22. {
  23. rINTSUBMSK|=((U32)0x1<<9);//關(guān)閉中斷服務(wù)
  24. if(rADCUPDN&(U32)0x01)//觸筆down
  25. {
  26. rADCUPDN=0;//清除標(biāo)志位
  27. Send_String("down");//打印信息(調(diào)試用)
  28. rADCTSC=(1<<3)|(1<<2);//上拉無(wú)效,自動(dòng)XY坐標(biāo)轉(zhuǎn)換模式
  29. rADCCON|=0x1;//開(kāi)始A/D轉(zhuǎn)換
  30. while(rADCCON&0x1);//等待AD轉(zhuǎn)換開(kāi)始
  31. while(!(rADCCON&(1<<15)));//等待AD轉(zhuǎn)換結(jié)束
  32. xdata=(rADCDAT0&0x3ff);//保存A/D轉(zhuǎn)換的x位置
  33. ydata=(rADCDAT1&0x3ff);//保存A/D轉(zhuǎn)換的y位置
  34. flagTS=0;
  35. rADCTSC=0xd3|(1<<8);//再次設(shè)置等待中斷模式,目的判斷觸筆up
  36. }
  37. if((rADCUPDN>>1)&(U32)0x01)//觸筆up
  38. {
  39. rADCUPDN=0;//清除標(biāo)志位
  40. Send_String("up");//打印信息(調(diào)試用)
  41. flagTS=1;//一次接觸完畢
  42. rADCTSC=0xd3;//設(shè)置觸摸屏為等待中斷模式。
  43. }
  44. rSRCPND|=(U32)0x1<<31;//清中斷標(biāo)志
  45. rSUBSRCPND|=(U32)0x01<<9;
  46. rINTPND|=(U32)0x1<<31;
  47. rINTSUBMSK&=~((U32)0x1<<9);//打開(kāi)中斷服務(wù)
  48. }
  49. /*******************************************
  50. *名稱:Delay
  51. *功能:延時(shí)
  52. *入口參數(shù):無(wú)
  53. *出口參數(shù):無(wú)
  54. **********************************************/
  55. voidDelay(void)
  56. {
  57. inti,j,k;
  58. for(i=0;i<20;i++)
  59. {
  60. for(j=0;j<100;j++)
  61. {
  62. for(k=0;k<1000;k++);
  63. }
  64. }
  65. }
  66. /*******************************************
  67. *名稱:Calibration
  68. *功能:觸摸屏校正
  69. *入口參數(shù):無(wú)
  70. *出口參數(shù):無(wú)
  71. **********************************************/
  72. voidCalibration(void)
  73. {
  74. chari;
  75. intxt[3],yt[3];
  76. TFT_CLearScreen(0xFFFFFF);
  77. Draw_Cross(32,24,0xFF0000);
  78. Draw_Cross(160,216,0xFF0000);
  79. Draw_Cross(288,120,0xFF0000);
  80. //依次讀取三個(gè)采樣點(diǎn)的坐標(biāo)值
  81. for(i=0;i<3;i++)
  82. {
  83. while(flagTS==0)
  84. {
  85. Delay();
  86. }
  87. Send_String("Over");
  88. xt[i]=xdata;
  89. yt[i]=ydata;
  90. flagTS=0;
  91. }
  92. //計(jì)算參數(shù)
  93. K=(xt[0]-xt[2])*(yt[1]-yt[2])-(xt[1]-xt[2])*(yt[0]-yt[2]);
  94. A=(32-288)*(yt[1]-yt[2])-(160-288)*(yt[0]-yt[2]);
  95. B=(xt[0]-xt[2])*(160-288)-(32-288)*(xt[1]-xt[2]);
  96. C=yt[0]*(xt[2]*160-xt[1]*288)+yt[1]*(xt[0]*288-xt[2]*32)+yt[2]*(xt[1]*32-xt[0]*160);
  97. D=(24-120)*(yt[1]-yt[2])-(216-120)*(yt[0]-yt[2]);
  98. E=(xt[0]-xt[2])*(216-120)-(24-120)*(xt[1]-xt[2]);
  99. F=yt[0]*(xt[2]*216-xt[1]*120)+yt[1]*(xt[0]*120-xt[2]*24)+yt[2]*(xt[1]*24-xt[0]*216);
  100. }
  101. /*******************************************
  102. *名稱:Touch_Screen_Init
  103. *功能:觸摸屏中斷初始化
  104. *入口參數(shù):無(wú)
  105. *出口參數(shù):無(wú)
  106. **********************************************/
  107. voidTouch_Screen_Init(void)
  108. {
  109. rADCDLY=50000;//設(shè)置延時(shí)
  110. rADCCON=(1<<14)|(20<<6);//設(shè)置A/D預(yù)分頻
  111. rADCTSC=0xd3;//設(shè)置等待中斷模式
  112. rSUBSRCPND|=(1<<9);
  113. rSRCPND|=(1<<31);
  114. rINTPND|=(1<<31);
  115. rINTSUBMSK&=~(1<<9);
  116. rINTMSK&=~(1<<31);//打開(kāi)中斷屏蔽
  117. }
  118. /*******************************************
  119. *名稱:Clk_Set
  120. *功能:關(guān)于系統(tǒng)時(shí)鐘的初始化
  121. *入口參數(shù):無(wú)
  122. *出口參數(shù):無(wú)
  123. **********************************************/
  124. voidClk_Set(void)
  125. {
  126. intcount;
  127. rUPLLCON=(56<<12)|(2<<4)|2;//UCLK為48MHZ
  128. for(count=0;count<10;count++)
  129. {
  130. ;
  131. }
  132. rMPLLCON=(92<<12)|(1<<4)|1;//FCLK為400MHZ
  133. rCLKDIVN=(0<<3)|(2<<1)|1;//HCLK位100MHZ,PCLK為50MHZ
  134. rCAMDIVN=(0<<9);//PCLK=HCLK/4
  135. }
  136. /*******************************************
  137. *名稱:Main
  138. *功能:測(cè)試TFT屏幕
  139. *入口參數(shù):無(wú)
  140. *出口參數(shù):無(wú)
  141. **********************************************/
  142. voidMain(void)
  143. {
  144. intx,y;
  145. MMU_Init();//MMU初始化
  146. UART0_init();//串口初始化
  147. TFT_Power_Enable(1);//TFT電源管理使能
  148. TFT_Contraller_Init();//TFT初始化
  149. TFT_Video_ON(1);//打開(kāi)TFT
  150. pISR_ADC=(U32)Touch_Int;//注冊(cè)觸摸屏中斷函數(shù)
  151. Touch_Screen_Init();//觸摸屏初始化
  152. Calibration();//觸摸屏校正
  153. TFT_CLearScreen((0x00<<11)|(0x00<<5)|(0x1f));
  154. //Paint_Picture(0,0,480,272,TQ_LOGO_480272_2);
  155. while(1)
  156. {
  157. if(flagTS)
  158. {
  159. flagTS=0;
  160. Send_String("OK");
  161. x=(A*xdata+B*ydata+C)/K;//計(jì)算X軸坐標(biāo)
  162. y=(D*xdata+E*ydata+F)/K;//計(jì)算Y軸坐標(biāo)
  163. Draws_Quare(x,y,0x00);//在觸摸坐標(biāo)處繪制正方形
  164. }
  165. }
  166. }




評(píng)論


技術(shù)專區(qū)

關(guān)閉