📄 adcts.c
字号:
while(rADCCON & 0x1); //check if Enable_start is low
while(!(rADCCON & 0x8000)); //check if EC(End of Conversion) flag is high
return (rADCDAT0&0x3ff);
}
#if 0
void __irq AdcTsAuto(void)
{
int i;
unsigned int saveAdcdly;
if(rADCDAT0&0x8000)
{
printf("\nStylus Up!!\n");
rADCTSC&=0xff; // Set stylus down interrupt bit
}
else
printf("\nStylus Down!!\n");
rADCTSC=(1<<3)|(1<<2); //XP Pull-up disable, Auto Seq. X,Y postion conversion mode
saveAdcdly=rADCDLY;
rADCDLY=40000; //Normal conversion mode delay about (1/50M)*40000=0.8ms
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
//printf("\nrSRCPND:0x%x\n", rSRCPND);
xdata=(rADCDAT0&0x3ff);
ydata=(rADCDAT1&0x3ff);
//YH 0627, To check Stylus Up Interrupt.
rSUBSRCPND|=BIT_SUB_TC;
ClearPending(BIT_ADC);
rINTSUBMSK=~(BIT_SUB_TC);
rINTMSK=~(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
{
printf("Stylus Up Interrupt~!\n");
break; //if Stylus is up(1) state
}
}
printf("ADCcount=%d XP=%04d, YP=%04d\n", ADCcount++, xdata, ydata); //X-position Conversion data
rADCDLY=saveAdcdly;
rADCTSC=rADCTSC&~(1<<8); // Detect stylus Down interrupt signal.
rSUBSRCPND|=BIT_SUB_TC;
rINTSUBMSK=~(BIT_SUB_TC); // Unmask sub interrupt (TC)
ClearPending(BIT_ADC);
}
#else
void __irq AdcTsAuto(void)
{
int i;
U32 saveAdcdly;
rINTMSK |= BIT_ADC; //ADC Touch Screen Mask bit clear
rINTSUBMSK |= (BIT_SUB_ADC | BIT_SUB_TC);
//printf("ISR\n");
if(rSUBSRCPND & (0x1<<10))// After ADC is complete,
{
while(!(rADCCON & 0x8000)); //check if EC(End of Conversion) flag is high, This line is necessary~!!
rSUBSRCPND |= BIT_SUB_ADC;
xdata=(rADCDAT0&0x3ff);
ydata=(rADCDAT1&0x3ff);
printf("\ncount=%d XP=%04d, YP=%04d\n", ADCcount++, xdata, ydata); //X-position Conversion data
rADCTSC &= ~(0x1ff);
rADCTSC |= 0xd3; // Waiting for interrupt
rADCTSC |= (1<<8); // To detect Stylus-up
}
else if(rSUBSRCPND & (0x1<<9))//TC interrupt
{
if(rADCUPDN == 0x1) //Stylus Down Int.
{
printf("\n\nADCTSC(@0x58000004): 0x%x", rADCTSC);
printf("\nStylus Down(@0x58000014): 0x%x \n", rADCUPDN);
rADCUPDN &= ~(0x1);
rSUBSRCPND |= BIT_SUB_TC;
rADCDLY=40000;
rADCTSC = (rADCTSC&~(0xf))|(6<<4)|(1<<3)|(1<<2);
printf("ADCTSC(@0x58000004): 0x%x\n", rADCTSC);
rADCCON |= 0x1; //A/D Conversion Start
while(rADCCON & 0x1); //check if Enable_start is low (this bit is cleared after the start-up)
}
else if(rADCUPDN == 0x2) //Stylus Up Int.
{
printf("\nADCTSC(@0x58000004): 0x%x", rADCTSC);
printf("\nStylus Up(@0x58000014): 0x%x \n\n", rADCUPDN);
rADCUPDN &= ~(0x1<<1);
rSUBSRCPND |= BIT_SUB_TC;
rADCTSC &= ~(0x1ff);
//rADCTSC |= (0<<8); // Stylus down detect
rADCTSC |= 0xd3; //Waiting for interrupt and Stylus down detect
}
}
ClearPending(BIT_ADC);
rSUBSRCPND |= BIT_SUB_ADC | BIT_SUB_TC;
rINTMSK &= ~BIT_ADC; //ADC Touch Screen Mask bit clear
rINTSUBMSK &= ~(BIT_SUB_ADC | BIT_SUB_TC);
}
#endif
void __irq AdcTsSepar(void)
{
int i;
U32 saveAdcdly;
rINTMSK |= BIT_ADC; //ADC Touch Screen Mask bit clear
rINTSUBMSK |= (BIT_SUB_ADC | BIT_SUB_TC);
//printf("ISR\n");
ClearPending(BIT_ADC);
if(rSUBSRCPND & (0x1<<9))//TC interrupt
{
if(rADCUPDN == 0x1) //Stylus Down Int.
{
printf("\n\nADCTSC(@0x58000004): 0x%x", rADCTSC);
printf("\nStylus Down(@0x58000014): 0x%x \n", rADCUPDN);
rADCUPDN &= ~(0x1);
rSUBSRCPND |= BIT_SUB_TC;
rADCTSC=(rADCTSC&~(0xff))|SepXPos; //Separate X,Y postion measure.
rADCDLY=40000; //Normal conversion mode delay about (1/50M)*40000=0.8ms
rADCCON|=0x1; //start ADC
while(rADCCON & 0x1); //check if Enable_start is low
}
else if(rADCUPDN == 0x2) //Stylus Up Int.
{
printf("\nADCTSC(@0x58000004): 0x%x", rADCTSC);
printf("\nStylus Up(@0x58000014): 0x%x \n\n", rADCUPDN);
rADCUPDN &= ~(0x1<<1);
rSUBSRCPND |= BIT_SUB_TC;
rADCTSC &= ~(0x1ff);
//rADCTSC |= (0<<8); // Stylus down detect
rADCTSC |= 0xd3; //Waiting for interrupt and Stylus down detect
}
}
else if(rSUBSRCPND & (0x1<<10))//ADC interrupt
{
if((rADCDAT0&0x1000)==0x1000)
{
rSUBSRCPND |= BIT_SUB_ADC;
while(!(rADCCON & 0x8000)); //check if EC(End of Conversion) flag is high, This line is necessary~!!
xdata=(rADCDAT0&0x3ff);
printf("\ncount=%d XP=%04d", ADCcount++, xdata); //X,Y position Conversion data
//printf("\nADCDAT0=0x%x", rADCDAT0); //X,Y position Conversion data
rADCTSC=(rADCTSC&~(0xff))|SepYPos; //Separate X,Y postion measure.
rADCCON|=0x1; //start ADC
while(rADCCON & 0x1); //check if Enable_start is low
}
else
{
rSUBSRCPND |= BIT_SUB_ADC;
while(!(rADCCON & 0x8000)); //check if EC(End of Conversion) flag is high, This line is necessary~!!
ydata=(rADCDAT1&0x3ff);
printf("\ncount=%d YP=%04d\n", ADCcount++, ydata); //X,Y position Conversion data
//printf("\nADCDAT0=0x%x", rADCDAT0); //X,Y position Conversion data
rADCTSC &= ~(0x1ff);
rADCTSC |= 0xd3; // Waiting for interrupt
rADCTSC |= (1<<8); // To detect Stylus-up
}
}
rINTMSK &= ~BIT_ADC; //ADC Touch Screen Mask bit clear
rINTSUBMSK &= ~(BIT_SUB_ADC | BIT_SUB_TC);
}
/*
#if 1
void Test_AdcWavIn_bak(void)
{
int i;
volatile int* a0;
a0 = (volatile int*)(_NONCACHE_STARTADDRESS);
printf("The ADC_IN are adjusted to the following values.\n");
printf("Push any key to exit!!!\n");
printf("ADC conv. freq.=%d(Hz)\n",(int)(PCLK/(PRSCVL +1.))); // ADC Freq. = PCLK/(ADCPSR+1), ADC conversion time = 5CYCLES*(1/(ADC Freq.))
printf("Are you ready, press any key & go\n");
getchar();
printf("Capturing\n");
rDISRC0 = _NONCACHE_STARTADDRESS;
rDISRCC0 = (0<<1)|(1); // AHB, Fixed
rDIDST0 = _NONCACHE_STARTADDRESS + 0x100;
rDIDSTC0 = (0<<1)|(0); // AHB, INC
rDCON0 = (1<<31)|(1<<30)|(1<<29)|(0<<28)|(0<<27)|(1<<22)|(2<<20)|(0x2ff);
rDMASKTRIG0 = (1<<1);
rDMAREQSEL0 = 0;
pISR_DMA0=(int)DDone;
rINTMSK&=~(BIT_DMA0);
rADCCON=(1<<14)|(PRSCVL<<6)|(0<<3); //setup channel, PRSCVL, AIN[0]
rADCTSC = rADCTSC & 0xfb; //Normal ADC conversion & No TS operation
dDone=0;
while(dDone==0)
{
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
*a0=(rADCDAT0&0x3ff);
rDMASKTRIG0 |= (1<<0); // DMA Request;
}
for(i=0;i<0x2ff;i++)
printf("%d\n",(*(volatile int *)(_NONCACHE_STARTADDRESS+0x100+i*4)));
rADCCON=(0<<14)+(19<<6)+(7<<3)+(1<<2); //stand by mode to reduce power consumption
printf("rADCCON = 0x%x\n", rADCCON);
}
void __irq DDone(void)
{
ClearPending(BIT_DMA0);
dDone=1;
}
#else
void Test_AdcWavIn(void)
{
int i;
volatile int* a0;
a0 = (volatile int*)(_NONCACHE_STARTADDRESS);
printf("The ADC_IN are adjusted to the following values.\n");
printf("Push any key to exit!!!\n");
printf("ADC conv. freq.=%d(Hz)\n",(int)(PCLK/(PRSCVL+1.))); // ADC Freq. = PCLK/(ADCPSR+1), ADC conversion time = 5CYCLES*(1/(ADC Freq.))
printf("Are you ready, press any key & go\n");
getchar();
printf("Capturing\n");
rADCCON=(1<<14)|(PRSCVL<<6)|(0<<3); //setup channel, PRSCVL, AIN[0]
rADCTSC = rADCTSC & 0xfb; //Normal ADC conversion & No TS operation
while(1)
{
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
*a0++=(rADCDAT0&0x3ff);
if(a0>(volatile int*)(_NONCACHE_STARTADDRESS+0xff)) break;
}
for(i=0;i<0xff;i++)
printf("%d\n",(*(volatile int *)(_NONCACHE_STARTADDRESS+i*4)));
rADCCON=(0<<14)+(19<<6)+(7<<3)+(1<<2); //stand by mode to reduce power consumption
printf("rADCCON = 0x%x\n", rADCCON);
}
#endif
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -