原创 ARM9裸机开发系列(10):触摸屏(中断方式)【ARM9+ADS1.2入门】.rar

2009-12-7 09:55 3930 7 7 分类: MCU/ 嵌入式

今天搞了下触摸屏的程序,基本上能用了,分析一下源代码


有什么不对的地方,请指正。


void __irq AdcTsAuto(void); //中断程序


int count="0";
volatile int xdata, ydata; //x、y坐标


初始化函数主要完成工作模式设定,中断入口


void ToutchScreenInit(void)
{
 rADCDLY=50000; //ADC延时寄存器 //Normal conversion mode delay about (1/3.6864M)*50000=13.56ms
 rADCCON=(1<<14)+(ADCPRS<<6);//预分频:PCLK/10,分频位使能
 rADCTSC=0xd3;  //Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En
 pISR_ADC = (int)AdcTsAuto; 
 rINTMSK= rINTMSK & (~(BIT_ADC));  //ADC中断屏蔽位无效 
 rINTSUBMSK = rINTSUBMSK & (~(BIT_SUB_TC));


void __irq AdcTsAuto(void)


 if(rADCDAT0&0x8000)
    {
  rADCTSC &= 0xff;   //这个地方不明白//Set stylus down interrupt bit
    }
      
 rADCTSC=(1<<3)|(1<<2);       //上拉无效,自动连续测量X、Y轴  //Pull-up disable, Seq. X,Y postion measure.
 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~!!
 while(!(rSRCPND & (BIT_ADC))); //等待中断标志位置位 //check if ADC is finished with interrupt bit


 xdata=(rADCDAT0&0x3ff);//读取x轴
 ydata=(rADCDAT1&0x3ff);//读取y轴
 
 rSUBSRCPND |= BIT_SUB_TC;
 ClearPending(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
   break;
 } 
 
 Uart0Printf("count=%03d  XP=%04d, YP=%04d\r\n", count++, xdata, ydata);
 
 rADCTSC    =  rADCTSC&~(1<<8);//等待光标按下中断 // Detect stylus Down interrupt signal.
    rSUBSRCPND |= BIT_SUB_TC;
 ClearPending(BIT_ADC);//清除ADC触摸屏中断信号


}


 


 


整个工程文件,编译环境:ADS1.2

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
我要评论
0
7
关闭 站长推荐上一条 /3 下一条