今天搞了下触摸屏的程序,基本上能用了,分析一下源代码
有什么不对的地方,请指正。
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触摸屏中断信号
}
文章评论(0条评论)
登录后参与讨论