DX能否帮我分析下这段TouchScreen的代码操作流程 ?
/***************************************** NAME: Touchpanel.c DESC: ADC & Touch screen test HISTORY: 2003.09.23:Leon YH KIM: draft ver 1.0 *****************************************/ #include "def.h" #include "2440addr.h" #include "2440lib.h"
#define REQCNT 30 #define ADCPRS 9 //YH 0627 #define LOOP 1
void __irq AdcTsAuto(void);
int count=0; volatile int xdata, ydata; void Test_Touchpanel(void) { rADCDLY=50000; //Normal conversion mode delay about (1/3.6864M)*50000=13.56ms //Touch down to conversion delay time width , X coordinate & Y coordinate conversion time width setting rADCCON=(1<<14)+(ADCPRS<<6); //ADCPRS En, ADCPRS Value // A/D converter prescaler enable , PRSCVL value setting , A/D Frequency = PCLK / (PRSCVL + 1) Uart_Printf("ADC touch screen test
");
rADCTSC=0xd3; //Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En //Detect stylus down interrupt signal , YM Enable , YP Disable , XM Disable, XP Disable , XP Pull-up enable , Normal ADC Conversion , Waiting for interrupt mode pISR_ADC = (int)AdcTsAuto;//将中断处理程序名放入中断向量表中对应地址 // rINTMSK=~BIT_ADC; //ADC Touch Screen Mask bit clear rINTSUBMSK=~(BIT_SUB_TC);//Touch Screen Mask bit clear
Uart_Printf("
Type any key to exit!!!
"); Uart_Printf("
Stylus Down, please......
"); Uart_Getch();
rINTSUBMSK|=BIT_SUB_TC;//Touch Screen Mask bit set rINTMSK|=BIT_ADC;//ADC Touch Screen Mask bit set Uart_Printf("Touch Screen Test is Finished!!!
");
}
void __irq AdcTsAuto(void) { int i; U32 saveAdcdly;
if(rADCDAT0&0x8000)//判断 updown bit ,如果提起则 { //Uart_Printf("
Stylus Up!!
"); rADCTSC&=0xff; // Set stylus down interrupt bit } //else //Uart_Printf("
Stylus Down!!
");
rADCTSC=(1<<3)|(1<<2); //XP Pull-up disable, Seq. X,Y postion measure. saveAdcdly=rADCDLY; rADCDLY=40000; //Normal conversion mode delay about (1/50M)*40000=0.8ms
rADCCON|=0x1; //start ADC AD转换开始且该位在开始后清零
while(rADCCON & 0x1); //check if Enable_start is low while(!(rADCCON & 0x8000)); //check if EC(End of Conversion) flag is high, This line is necessary~!! while(!(rSRCPND & (BIT_ADC))); //check if ADC is finished with interrupt bit
xdata=(rADCDAT0&0x3ff); ydata=(rADCDAT1&0x3ff);
//YH 0627, To check Stylus Up Interrupt. rSUBSRCPND|=BIT_SUB_TC;// ClearPending(BIT_ADC);// rINTSUBMSK=~(BIT_SUB_TC);// rINTMSK=~(BIT_ADC);// rADCTSC =0xd3; //Waiting for interrupt rADCTSC=rADCTSC|(1<<8); // Detect stylus up interrupt signal.
while(1) //to check Pen-up state { if(rSUBSRCPND & (BIT_SUB_TC)) //check if ADC is finished with interrupt bit { //Uart_Printf("Stylus Up Interrupt~!
"); break; //if Stylus is up(1) state } }
Uart_Printf("count=%03d XP=%04d, YP=%04d
", count++, xdata, ydata); //X-position Conversion data
rADCDLY=saveAdcdly; rADCTSC=rADCTSC&~(1<<8); // Detect stylus Down interrupt signal. rSUBSRCPND|=BIT_SUB_TC; rINTSUBMSK=~(BIT_SUB_TC); // Unmask sub interrupt (TC) ClearPending(BIT_ADC); }
自己看单句还基本看明白了,可整个流程不了解,如果我要多次采集一个点,又该如何处理呢,有没有裸奔玩触摸屏的朋友指导一二 .... |