默认情况下,输入通道已被接到触摸屏上
nXPON |
Plus X-axis on-off control signal |
x轴正极开关控制信号 |
XMON |
Minus X-axis on-off control signal |
x轴负极开关控制信号 |
nYPON |
Plus Y-axis on-off control signal |
y轴正极开关控制信号 |
YMON |
Minus Y-axis on-off control signal |
y轴负极开关控制信号 |
/*触摸屏初始化*/
void Test_Touchpanel(void)
{
rADCDLY=50000; //ADC启动延时 (1/3.6864M)*50000=13.56ms
/*设置AD转频率*/
preScaler = ADC_FREQ;
preScaler = 50000000/ADC_FREQ - 1; //PCLK=50M
rADCCON = (1<<14)|(preScaler<<6); //使能分频, 分频值PRSCVL=19
//转换频率=50MHz/(19+1)=2.5HMz
//转换时间=1/(2.5MHz/5)=2×10^(-6)秒
//一秒钟转换5×10^5次
/*设置触摸屏为等待中断模式,等待触摸笔被按下*/
rADCTSC=0xd3; //Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En
//11010011 来自2440手册
/*clear irq*/
rSRCPND = 0x80000000; //清除挂起状态
rINTPND = 0x80000000;
ClearSubPending(BIT_SUB_TC);
pISR_ADC = (U32)AdcTsAuto; //中断服务函数
/*enable INT_TC irq*/
rINTMSK = 0x7fffffff; //打开屏蔽
EnableSubIrq(BIT_SUB_TC);
}
static void __irq AdcTsAuto(void) //中断服务函数
{
U32 saveAdcdly;
/****************stylus down************************/
/*检测子中断源,判断是否是INT_TC中断,且触摸笔按下*/
if(rSUBSRCPND & (BIT_SUB_TC))
{
if( !(rADCDAT0&0x8000)) //是否落下状态
Uart_Printf("\nStylus down\n");
else
Uart_Printf("\nStylus up\n");
}
saveAdcdly=rADCDLY;
rADCDLY=40000; //ADC启动延迟 (1/50M)*40000=0.8ms
rADCCON|=0x1; //开始ADC
while(rADCCON & 0x1); //转换是否开始
while(!(rADCCON & 0x8000)); //转换是否结束
while(!(rSRCPND & 0x80000000)); //检测是否产生INT_ADC中断
/*获取X,Y坐标*/
xdata=(rADCDAT0&0x3ff); //[9:0]存储X值
ydata=(rADCDAT1&0x3ff); //[9:0]存储Y值
Uart_Printf("count=%03d XP=%04d, YP=%04d\n", count++, xdata, ydata);
/*3个PND 2个MSK*/
ClearSubPending(BIT_SUB_TC);
rSRCPND = 0x80000000;
rINTPND = 0x80000000;
EnableSubIrq(BIT_SUB_TC);
rINTMSK = 0x7fffffff;
/****************stylus down************************/
}