微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > S3C2440之触摸屏

S3C2440之触摸屏

时间:11-27 来源:互联网 点击:

  1. {
  2. inti;
  3. U32saveAdcdly;
  4. if(rADCDAT0&0x8000)
  5. {
  6. //Uart_Printf("StylusUp!!");
  7. rADCTSC&=0xff;//Setstylusdowninterruptbit
  8. }
  9. //else
  10. //Uart_Printf("StylusDown!!");
  11. rADCTSC=(1<3)|(1<2);//Pull-updisable,(在触发中断后,上拉电阻要无效)Seq.X,Ypostionmeasure.
  12. saveAdcdly=rADCDLY;//saveADCDLY(启动延时)
  13. rADCDLY=40000;//Normalconversionmodedelayabout(1/50M)*40000=0.8ms
  14. rADCCON|=0x1;//startADC
  15. while(rADCCON&0x1);//checkifEnable_startislow,转换开启结束
  16. while(!(rADCCON&0x8000));//checkifEC(EndofConversion)flagishigh,Thislineisnecessary~!!
  17. //conversionover
  18. while(!(rSRCPND&(BIT_ADC)));//checkifADCisfinishedwithinterruptbit,等待中断清零?
  19. xdata=(rADCDAT0&0x3ff);
  20. ydata=(rADCDAT1&0x3ff);//读取转换结果,x轴坐标值放入rADCDAT0,y轴坐标值放入ADCDAT1
  21. //YH0627,TocheckStylusUpInterrupt.
  22. rSUBSRCPND|=BIT_SUB_TC;
  23. ClearPending(BIT_ADC);//清楚中断标志位
  24. rINTSUBMSK=~(BIT_SUB_TC);//使能中断?
  25. rINTMSK=~(BIT_ADC);
  26. rADCTSC=0xd3;//Waitingforinterrupt//[0:7]Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En
  27. rADCTSC=rADCTSC|(1<8);//Detecttylusupsinterruptsignal.检查触笔抬起中断
  28. while(1)//tocheckPen-upstate
  29. {
  30. if(rSUBSRCPND&(BIT_SUB_TC))//checkifADCisfinishedwithinterruptbit
  31. {
  32. //Uart_Printf("StylusUpInterrupt~!");//触笔抬起!
  33. break;//ifStylusisup(1)state
  34. }
  35. }
  36. Uart_Printf("count=dXP=d,YP=d",count++,xdata,ydata);//X-positionConversiondata
  37. rADCDLY=saveAdcdly;//恢复ADCDLY原值
  38. rADCTSC=rADCTSC&~(1<8);//DetectstylusDowninterruptsignal.检查触笔落下中断(下一次检测)
  39. rSUBSRCPND|=BIT_SUB_TC;
  40. rINTSUBMSK=~(BIT_SUB_TC);//Unmasksubinterrupt(TC)//使能中断
  41. ClearPending(BIT_ADC);
  42. }

效果图:

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top