www.pudn.com > s3c2443_test_code.zip > Adcts.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