-
void Init_Touchpanel(void)
-
{
-
ClearPending(BIT_ADC);
-
rSUBSRCPND|=BIT_SUB_TC ;
-
//清adc中断 触摸屏中断
-
-
rADCDLY=40000; //ADC转换间隔 (1/3.6864M)*50000=13.56ms
-
//Normal conversion mode:ADC Start or interval delay 0~65535
-
-
rADCCON=(1<<14)+(ADCPRS<<6); //ADCPRS En, ADCPRS Value
-
//使能预分频器 预分频值 ADCPRS(9) AD转换器频率=gclk / (9+1)
-
-
rADCTSC=0xd3; //Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En
-
//ADC触摸屏控制寄存器 检测手写笔按下的中断信号 YM输出驱动有效 YP输出无效 XM输出禁止 XP输出驱动禁止
-
// XP上啦使能 adc正常转换模式 等待中断模式
-
-
pISR_ADC = (int)AdcTsAuto;
-
//指定adc中断服务程序
-
-
rINTMSK=~BIT_ADC; //ADC Touch Screen Mask bit clear
-
rINTSUBMSK=~(BIT_SUB_TC);
-
//使能中断 当触摸笔按下时 触发INT_TC中断
-
}
-
-
//触摸屏中断函数
-
void __irq AdcTsAuto(void)
-
{
-
//ADCDAT0[15]==1 触摸笔未按下
-
//ADCDAT0[15]==0 触摸笔按下
-
if(rADCDAT0&0X8000)
-
return ;
-
rINTMSK |= (BIT_ADC);
-
//禁止adc中断
-
rSUBSRCPND|=BIT_SUB_TC ;
-
//禁止adc的子中断
-
-
rADCTSC=(1<<3)|(1<<2); //Pull-up disable, Seq. X,Y postion measure.
-
//xp上拉禁止 自动顺序测量x y位置
-
-
rADCCON|=0x1; //start ADC
-
-
while(rADCCON & 0x1); //check if Enable_start is low
-
//adc一旦开始 将自动使ADCCON[0]=0
-
-
while(!(rADCCON & 0x8000)); //check if EC(End of Conversion) flag is high, This line is necessary~!!
-
//adc结束时,ADCCON[15]==1
-
-
while(!(rSRCPND & (BIT_ADC))); //check if ADC is finished with interrupt bit
-
//等待ADC结束(不管后级中断是否传递 adc完成后 此处应该被置位)
-
-
point.x = (rADCDAT0&0x3ff);
-
point.y = (rADCDAT1&0x3ff);
-
//获取x y方向的adc值 更新坐标点
-
-
Uart_Printf("XP=%04d, YP=%04dn",point.x, point.y); //X-position Conversion data
-
-
ClearPending(BIT_ADC);
-
rSUBSRCPND|=BIT_SUB_TC ;
-
//清adc中断
-
-
Init_Touchpanel();
-
//重新初始化触摸屏
-
}
用户1476573 2016-3-9 11:16
用户1476573 2016-3-9 11:13
哈哈你绝对值得拥有
用户1476573 2016-3-9 11:12
用户164119 2016-3-8 09:09
用户1871598 2016-3-7 09:49
用户1871543 2016-3-3 16:26
用户1871547 2016-3-3 09:57
用户1871561 2016-3-3 09:43
用户1831649 2015-3-12 20:43