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,(在触发中断后,上拉电阻要无效) 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,转换开启结束 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);//读取转换结果,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; //恢复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); - }
效果图:
本文引用地址:https://www.eepw.com.cn/article/201611/322378.htm
评论