ile(!(rSRCPND&0x80000000));//checkifADCisfinishedwithinterruptbit
xdata=(rADCDAT0&0x3ff);
ydata=(rADCDAT1&0x3ff);
7、对几个寄存器写1清零,防止反复发生中断(这里的中断是笔尖按下中断)
ClearSubPending(BIT_SUB_TC);
ClearPending(BIT_ADC);
/rSRCPND=0x80000000;rINTPND=0x80000000;也可以
8、再次允许中断
允许触摸笔被弹起的中断
EnableSubIrq(BIT_SUB_TC);
EnableIrq(BIT_ADC);//rINTMSK=0x7fffffff;
二)触摸笔抬起中断
9、设置触摸屏即可为等待中断模式,等待触摸笔抬起(ADCTSC,关键是要设置触摸笔抬起中断信号)
rADCTSC=0xd3;//Waitingforinterrupt
rADCTSC=rADCTSC|(1<8);//Detectstylusupinterruptsignal.
10、如果发生中断,不做任何操作,只打印出一句触摸笔抬起中断信息
while(1)//tocheckPen-upstate
{
if(rSUBSRCPND&(BIT_SUB_TC))//checkifADCisfinishedwithinterruptbit
{
Uart_Printf("StylusUpInterrupt~!");
break;//ifStylusisup(1)state
}
}
Uart_Printf("count=dXP=d,YP=d",count++,xdata,ydata);
11、触摸笔抬起之后,把得到的x,y坐标值发送给PC机,显示出具体数值
三)再次设置触摸屏为等待中断模式,等待下次触摸屏被按下
rADCTSC=0xd3;//Waitingforinterrupt
ClearSubPending(BIT_SUB_TC);
ClearPending(BIT_ADC);
EnableSubIrq(BIT_SUB_TC);
EnableIrq(BIT_ADC);
示例程序如下:
#defineGLOBAL_CLK1
#include
#include
#include"def.h"
#include"option.h"
#include"2440addr.h"
#include"2440lib.h"
#include"2440slib.h"
#include"mmu.h"
#include"profile.h"
#include"memtest.h"
#defineADC_FREQ2500000
intcount=0;
volatileU32preScaler;
intxdata,ydata;
voidTest_Touchpanel(void);
staticvoid__irqAdcTsAuto(void);
staticvoidcal_cpu_bus_clk(void);
voidSet_Clk(void);
voiddelay(inttimes)
{
inti,j;
for(i=0;i
for(j=0;j<400;j++);
}
intMain(void)
{
intScom=0;
Set_Clk();
Uart_Init(0,115200);
Uart_Select(Scom);
Test_Touchpanel();
while(1);
return0;
}
voidTest_Touchpanel(void)
{
rADCDLY=50000;//Normalconversionmodedelayabout(1/3.6864M)*50000=13.56ms
preScaler=ADC_FREQ;
preScaler=50000000/ADC_FREQ-1;//PCLK=50M
rADCCON=(1<14)|(preScaler<6);//ADCPRSEn,PRSCVL
rADCTSC=0xd3;//Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En
rSRCPND=0x80000000;
rINTPND=0x80000000;
ClearSubPending(BIT_SUB_TC);
pISR_ADC=(U32)AdcTsAuto;
rINTMSK=0x7fffffff;
EnableSubIrq(BIT_SUB_TC);
}
staticvoid__irqAdcTsAuto(void)
{
U32saveAdcdly;
if(rSUBSRCPND&(BIT_SUB_TC))
{
if(!(rADCDAT0&0x8000))
Uart_Printf("Stylusdown");
else
Uart_Printf("Stylusup");
}
rADCTSC=(1<3)|(1<2);
saveAdcdly=rADCDLY;
rADCDLY=40000;//Normalconversionmodedelayabout(1/50M)*40000=0.8ms
rADCCON|=0x1;//startADC
while(rADCCON&0x1);//checkifEnable_startislow
while(!(rADCCON&0x8000));//checkifEC(EndofConversion)flagishigh,Thislineisnecessary~!!
while(!(rSRCPND&0x80000000));//checkifADCisfinishedwithinterruptbit
xdata=(rADCDAT0&0x3ff);
ydata=(rADCDAT1&0x3ff);
ClearSubPending(BIT_SUB_TC);
//ClearPending(BIT_ADC);
rSRCPND=0x80000000;
rINTPND=0x80000000;
EnableSubIrq(BIT_SUB_TC);
//EnableIrq(BIT_ADC);
rINTMSK=0x7fffffff;
rADCTSC=0xd3;//Waitingforinterrupt
rADCTSC=rADCTSC|(1<8);//Detectstylusupinterruptsignal.
while(1)//tocheckPen-upstate
{
if(rSUBSRCPND&(BIT_SUB_TC))//checkifADCisfinishedwithinterruptbit
{
Uart_Printf("StylusUpInterrupt~!");
break;//ifStylusisup(1)state
}
}
Uart_Printf("count=dXP=d,YP=d",count++,xdata,ydata);
rADCDLY=saveAdcdly;
rADCTSC=0xd3;//Waitingforinterrupt
ClearSubPending(BIT_SUB_TC);
//ClearPending(BIT_ADC);
rSRCPND=0x80000000;
rINTPND=0x80000000;
EnableSubIrq(BIT_SUB_TC);
//EnableIrq(BIT_ADC);
rINTMSK=0x7fffffff;
}
voidSet_Clk(void)
{
inti;
U8key;
U32mpll_val=0;
i=2;//dontuse100M!
//boot_params.cpu_clk.val=3;
switch(i){
case0://200
key=12;
mpll_val=(92<12)|(4<4)|(1);
break;
case1://300
key=13;
mpll_val=(67<12)|(1<4)|(1);
break;
case2://400
key=14;
mpll_val=(92<12)|(1<4)|(1);
break;
case3://440!!!
key=14;
mpll_val=(102<12)|(1<4)|(1);
break;
default:
key=14;
mpll_val=(92<12)|(1<4)|(1);
break;
}
//initFCLK=400M,sochangeMPLLfirst
ChangeMPllValue((mpll_val>>12)&0xff,(mpll_val>>4)&0x3f,mpll_val&3);//settheregister--rMPLLCON
ChangeClockDivider(key,12);//theresultofrCLKdivN[0:1:0:1]3-0bit