⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adcts.c

📁 三星2443芯片
💻 C
字号:
/*****************************************
  NAME: Adcts.c
  DESC: ADC & Touch screen test
  HISTORY:
  2006.12.18:GOM: draft ver 1.0
 *****************************************/

#include "system.h"
#include "adcts.h"

#define REQCNT 30
#define ADCPRS 9	//YH 0627
#define LOOP 1

int ReadAdc(int ch);    //Return type is int, Declare Prototype function
void __irq AdcTsAuto(void);

int count=0;
volatile int xdata, ydata;

void * func_adc_test[][2]=
{	
	(void *)Test_Adc,   			"ADC test                                  ",
	(void *)Test_AdcTs,   			"ADC TS test                              ",
	0,0
};

void Test_ADC(void)
{  
	int i;

	while(1)
	{
		i=0;
		printf("\n\n");
		while(1)
		{   //display menu
	   		printf("%2d:%s",i,func_adc_test[i][1]);
	    	i++;
	    	if((int)(func_adc_test[i][0])==0)
	    	{
				printf("\n");
				break;
	    	}
	    	if((i%3)==0)
	    	printf("\n");
		}

		printf("\nSelect (\"-1\" to exit) : ");
		i = GetIntNum();
		if(i==-1) 
	   		break;		// return.
		if( (i<((sizeof(func_adc_test)-1)/8)) )	// select and execute...
	    	( (void (*)(void)) (func_adc_test[i][0]) )();
	}
	
}

void Test_Adc(void)
{
	int a0=0,a1=0,a2=0,a3=0,a4=0; //Initialize variables
	int a5=0,a6=0,a7=0, a8=0, a9=0; //Initialize variables

	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/(ADCPRS+1.))); // ADC Freq. = PCLK/(ADCPSR+1), ADC conversion time = 5CYCLES*(1/(ADC Freq.))

	while(Uart_GetKey()==0)
	{
	a0=ReadAdc(0);
	a1=ReadAdc(1);
	a2=ReadAdc(2);
	a3=ReadAdc(3);
	a4=ReadAdc(4);    
	a5=ReadAdc(5);
	a6=ReadAdc(6);
	a7=ReadAdc(7);    
	a8=ReadAdc(8);
	a9=ReadAdc(9);

	printf("AIN0: %04d AIN1: %04d AIN2: %04d AIN3: %04d, AIN4: %04d", a0,a1,a2,a3,a4);
	printf("AIN5: %04d AIN6: %04d AIN7: %04d AIN8: %04d, AIN9: %04d \n", a5,a6,a7,a8,a9);
	}

	rADCCON |= (0<<14) | (19<<6) | (7<<3) | (1<<2);     //stand by mode to reduce power consumption 
	printf("rADCCON = 0x%x\n", rADCCON);
}

int ReadAdc(int ch)
{
	int i;
	static int prevCh=-1;

	if(prevCh!=ch)
	{
		rADCCON |= (1<<14) | (ADCPRS<<6);   //setup channel, ADCPRS
		rADCMUX = ch;
		for(i=0;i<LOOP;i++);    //delay to set up the next channel
		prevCh=ch;
	}
	rADCCON = (1<<14) | (ADCPRS<<6);   //setup channel, ADCPRS
	rADCMUX = ch;
	rADCTSC = rADCTSC & 0xfb;     //Normal ADC conversion & No TS operation
	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
	return (rADCDAT0&0x3ff);
}

void Test_AdcTs(void)
{
   
	rADCDLY=50000;                  //Normal conversion mode delay about (1/3.6864M)*50000=13.56ms
	rADCCON = rADCCON & ~(0xffff) | (1<<14) | (ADCPRS<<6) | (0<<2);

	printf("[ADC touch screen test.]\n");

	printf("rADCCON = %x\n",rADCCON);

	rADCTSC = 0xd3;  //Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En

	pISR_ADC = (int)AdcTsAuto;
	rINTMSK &=~BIT_ADC;       //ADC Touch Screen Mask bit clear
	rINTSUBMSK &=~(BIT_SUB_ADC | BIT_SUB_TC);

	printf("\nType any key to exit!!!\n");
	printf("\nStylus Down, please...... \n\n");
	
	Uart_getc();

	rINTSUBMSK|=BIT_SUB_TC;
	rINTMSK|=(U32)BIT_ADC;
	printf("[Touch Screen Test.]\n");
}

void __irq AdcTsAuto(void)
{
	
	rINTMSK |= (U32)BIT_ADC;       //ADC Touch Screen Mask bit clear
	rINTSUBMSK |= (BIT_SUB_ADC | BIT_SUB_TC);

	if(rSUBSRCPND & (0x1<<10))// ADC interrupt
		{
		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("count=%d XP=%04d, YP=%04d\n", count++, xdata, ydata);    //X-position Conversion data            		

		rADCTSC &= ~(0x1ff);
		rADCTSC |= 0xd3;	// Waiting for interrupt
		rADCTSC |= (1<<8);	// Stylus up detect
		}
	else if(rSUBSRCPND & (0x1<<9))//TC interrupt
		{
		if(rADCUPDN == 0x1)// Stylus Up
			{
			rADCUPDN &= ~(0x1);
			rSUBSRCPND |= BIT_SUB_TC;
			printf("Stylus Down\n");
			rADCDLY=40000;
			rADCTSC = (rADCTSC&~(0xf))|(6<<4)|(1<<3)|(1<<2);
			rADCCON |= 0x1;
			while(rADCCON & 0x1);		//check if Enable_start is low
			}
		else if(rADCUPDN == 0x2)// Stylus Down
			{
			rADCUPDN &= ~(0x1<<1);
			printf("Stylus Up\n\n");
			rADCTSC &= ~(0x1ff);
			rADCTSC |= (0<<8);	// Stylus down detect
			rADCTSC |= 0xd3;    //Waiting for interrupt and Stylus down detect
			}
		}

	ClearPending((U32)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);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -