S3C2440 触摸屏应用
时间:11-21
来源:互联网
点击:
要三个取样点,在这里我们选取LCD上的(32,24),(160,216),(288,120)为这三个取样点,我们在这三个取样点上画一个十字(如下图所示),只需要依次点击这三个点,即可完成触摸屏的校正。
以上文字从网上摘录。觉得写得不错,当做笔记记下,我下面贴出的方法为裸奔三部曲中的方法,我验证了一下,不错,误差很小了,不到4个像素点。下面只贴出触摸屏初始化函数和中断函数的代码
[cpp]view plaincopy
- voidTouch_Init(void)
- {
- rADCDLY=50000;//正常转换模式下延时
- rADCCON=(1<14)|(ADCPRS<6);//使能AD转换预分频器
- rADCTSC=0xd3;//等待中断模式,正常AD转换,XP上拉使能,XP,XM,YP输出禁止,YM输出使能
- if(rSRCPND&BIT_ADC)rSRCPND|=BIT_ADC;
- if(rINTPND&BIT_ADC)rINTPND|=BIT_ADC;
- if(rSUBSRCPND&BIT_SUB_TC)rSUBSRCPND|=BIT_SUB_TC;
- if(rSUBSRCPND&BIT_SUB_ADC)rSUBSRCPND|=BIT_SUB_ADC;//清除中断标志
- rINTMSK&=~BIT_ADC;
- rINTSUBMSK&=~(BIT_SUB_TC);//使能中断
- pISR_ADC=(unsigned)AdcTsAuto;//中断服务程序入口
- }
[cpp]view plaincopy
- void__irqAdcTsAuto(void)
- {
- unsignedinti;
- U32PtX[6],PtY[6];
- shorttemp;
- if(rADCDAT0&0x8000)
- {
- rADCTSC&=0xff;//Setstylusdowninterruptbit
- }
- rADCTSC=(1<3)|(1<2);//XP上拉禁止,自动顺序X,Y测量
- //rADCDLY=50000;
- rADCCON|=0x1;//使能AD转换
- for(i=0;i<5;i++)
- {
- while(rADCCON&0x1);//判断使能ADC转换后被清零
- while(!(rADCCON&0x8000));//等待转换结束
- while(!(rSRCPND&(BIT_ADC)));//checkifADCisfinishedwithinterruptbit
- PtX[i]=(rADCDAT0&0x3ff);
- PtY[i]=(rADCDAT1&0x3ff);
- }
- PtX[5]=(PtX[0]+PtX[1]+PtX[2]+PtX[3]+PtX[4])/5;
- PtY[5]=(PtY[0]+PtY[1]+PtY[2]+PtY[3]+PtY[4])/5;
- xdata=PtX[5];
- ydata=PtY[5];
- xdata*=0.272;
- ydata*=0.480;
- ydata=480-ydata;
- temp=ydata;
- ydata=xdata;
- xdata=temp;
- xdata=(xdata-20.0303)/0.8972;
- ydata=(ydata-37.86667)/0.7486;//将触摸屏的AD转换值转换为LCD像素点的值
- //checkStylusUpInterrupt.
- rSUBSRCPND|=BIT_SUB_TC;
- ClearPending(BIT_ADC);
- rINTSUBMSK=~(BIT_SUB_TC);
- rINTMSK=~(BIT_ADC);//清中断标志,再次使能中断
- rADCTSC=0xd3;//再次设置等待中断模式,这一次是判断触笔的抬起
- rADCTSC=rADCTSC|(1<8);//检测笔尖抬起中断信号
- while(1)//tocheckPen-upstate
- {
- if(rSUBSRCPND&(BIT_SUB_TC))//checkifADCisfinishedwithinterruptbit
- {
- break;//ifStylusisup(1)state
- }
- }
- Uart_Printf("count=%03dXP=%04d,YP=%04d\n",count++,xdata,ydata);//X-positionConversiondata
- //rADCDLY=50000;
- rADCTSC=rADCTSC&~(1<8);//DetectstylusDowninterruptsignal.
- rSUBSRCPND|=BIT_SUB_TC;
- rINTSUBMSK=~(BIT_SUB_TC);//Unmasksubinterrupt(TC)
- ClearPending(BIT_ADC);//再次清A/D中断
- }
S3C2440触摸屏驱动代 相关文章:
- S3C2440触摸屏驱动代码分析(12-01)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)