S3C2440之觸摸屏
- #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 rADCCON=(1<<14)+(ADCPRS<<6); //ADCPRS En, ADCPRS Value Uart_Printf("ADC touch screen test"); rADCTSC=0xd3; //[0:7]Wfait,XP_PU(在等待中斷模式下,上拉電阻要有效),XP_Dis,XM_Dis,YP_Dis,YM_En pISR_ADC = (int)AdcTsAuto; rINTMSK=~BIT_ADC; //ADC Touch Screen Mask bit clear,enable ADCint rINTSUBMSK=~(BIT_SUB_TC);//enable sub ADCint Uart_Printf("Type any key to exit!!!"); Uart_Printf("Stylus Down, please...... "); Uart_Getch(); rINTSUBMSK|=BIT_SUB_TC;//get a key then mask sub ADCint ;exit rINTMSK|=BIT_ADC;//mask ADCint Uart_Printf("Touch Screen Test is Finished!!!"); - }
- void
__irq AdcTsAuto(void) - {
int i; U32 saveAdcdly; if(rADCDAT0&0x8000) { //Uart_Printf("Stylus Up!!"); rADCTSC&=0xff; // Set stylus down interrupt bit } //else //Uart_Printf("Stylus Down!!"); rADCTSC=(1<<3)|(1<<2); //Pull-up disable,(在觸發(fā)中斷后,上拉電阻要無效) Seq. X,Y postion measure. saveAdcdly=rADCDLY; //save ADCDLY(啟動延時) rADCDLY=40000; //Normal conversion mode delay about (1/50M)*40000=0.8ms rADCCON|=0x1; //start ADC while(rADCCON & 0x1); //check if Enable_start is low,轉(zhuǎn)換開啟結(jié)束 while(!(rADCCON & 0x8000)); //check if EC(End of Conversion) flag is high, This line is necessary~!! //conversion over while(!(rSRCPND & (BIT_ADC))); //check if ADC is finished with interrupt bit,等待中斷清零? xdata=(rADCDAT0&0x3ff); ydata=(rADCDAT1&0x3ff);//讀取轉(zhuǎn)換結(jié)果,x軸坐標值放入rADCDAT0,y軸坐標值放入ADCDAT1 //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//[0:7]Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En rADCTSC=rADCTSC|(1<<8); // Detect tylus up sinterrupt 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=d XP=d, YP=d", count++, xdata, ydata); //X-position Conversion data rADCDLY=saveAdcdly; //恢復(fù)ADCDLY原值 rADCTSC=rADCTSC&~(1<<8); // Detect stylus Down interrupt signal.檢查觸筆落下中斷(下一次檢測) rSUBSRCPND|=BIT_SUB_TC; rINTSUBMSK=~(BIT_SUB_TC); // Unmask sub interrupt (TC)//使能中斷 ClearPending(BIT_ADC); - }
效果圖:
本文引用地址:http://2s4d.com/article/201611/322378.htm
評論