电阻式触摸屏的检测原理是触摸后引起上下两个导电层的接触,改变了电压输出,进行A/D转换后成了该点的X,Y坐标。
初始化AD和触摸口:
void TouchSrceen_Test(void)
{
rADCDLY = 50000; //(1/3.68MHz)*50000 = 13.56ms
注: 在ADC转换之前用的是外部时钟X-tal clock:3.68MHz
之后才用到GLK: 50MHz
rADCCON = (1<<14)|(prescaler<<6);
注: bit[14]: 0--disable ADC 1--enable ADC bit[13:6]: prescaler = 9 ADC fleq = 50MHz/(9+1) = 5MHz
Uart_Printf("\nTouch Screen test\n");
rADCTSC = 0xd3;//waiting for interrupt Mode
注: bit[1:0]: 11--waiting for interrupt Mode
bit[2]: 0--Normal ADC 1--Auto Sequential measurement of X-position,Y-position
bit[3]: 0--XP pull-up enable 1--XP pull-up disable
bit[4]: 0--XP output driver enable 1--XP output driver disable
bit[5]: 0--XM output driver disable 1--XM output driver enable
bit[6]: 0--YP output driver enable 1--YP output driver disable
bit[7]: 0--YM output driver disable 1--YM output driver enable
bit[8]: 0--stylus down interrupt signal 1--stylus up interrupt signal
pISR_ADC = (int)ADC_TCTest;
rINTMSK = ~(1<<31); //clear ADC MASK bit
rINTSUBMSK = ~(1<<9); //clear TouchScreen MASK bit
}
void __irq ADC_TCTest(void)
{
U32 saveADCDLY;
if(rADCDAT0 & 0x8000) //bit[15]:0--stylus down 1--stylus up
{
rADCTSC &= 0xff; //clear bit[8]:0 stylus down 1--stylus up
}
rADCTSC = (1<<3)|(1<<2); //disable XP pull-up
//auto sequential measurement of XY position
saveADCDLY = rADCDLY;
rADCDLY = 40000; //(1/50MHz)*40000=0.8ms
注:如下图,在需要对X,Y转换时切换到GCLK,之前用X-Tal
rADCCON |= 0x01; //start ADC
while(rADCCON & 0x1); //waiting for ADC startup
while(!(rADCCON & 0x8000)); //waiting for ADC end
while(!(rSRCPND & (0x1<<31)));//waiting for interrupt bit=1
xdata = rADCDAT0 & 0x3ff;
ydata = rADCDAT1 & 0x3ff;
注: 读取buffer里的X,Y坐标数据
if(((xdata-xdata_save > 5)||(xdata-xdata_save < -5))\
||((ydata-ydata_save > 5)||(ydata-ydata_save < -5)))
{
Uart_Printf("X_value = %d,Y_value = %d,X_data = %d,Y_data = %d\n",\
xdata,ydata,xdata_save,ydata_save);
}
xdata_save = xdata;
ydata_save = ydata;
rSUBSRCPND |= (1<<9);
rINTSUBMSK =~(1<<9);
rSRCPND |= (0x1<<31);
rINTPND |= (0x1<<31);
rINTMSK = ~(0x1<<31);
注: 清所有跟中断有关的标志位,为下次中断做准备
rADCTSC =0xd3; //waiting for interrupt
rADCTSC |= 0x100; //stylus up
while(!(rSUBSRCPND & (1<<9))); //waiting for stylus up interrupt bit=1
Uart_Printf("The pen has stylus up.");
rSUBSRCPND |= (1<<9);
rINTSUBMSK =~(1<<9);
rSRCPND |= (0x1<<31);
rINTPND |= (0x1<<31);
rINTMSK = ~(0x1<<31);
注: 清所有跟中断有关的标志位,为下次中断做准备
rADCDLY = saveADCDLY;
rADCTSC &= ~0x100; //stylus down
}
上一篇:TFT LCD的显色原理
下一篇:S3C2440 测试程序(四) 外部中断实验
推荐阅读最新更新时间:2024-03-16 15:23