www.pudn.com > Source_program.rar > Adc.c


#include  
#include "..\Target\44b.h" 
#include "..\Target\44blib.h" 
#include "adc.h" 
 
void __irq BDMA1_Done(void); 
 
int ReadAdc(int ch); 
 
void Test_Adc(void) 
{ 
    int a0=0,a1=0,a2=0,a3=0,a4=0,a5=0,a6=0,a7=0; 
    int adcpsr; 
 
    Uart_Printf("The ADC_IN are adjusted to the following values.\n");	       
    Uart_Printf("Push any key to exit!!!\n");	  
 
    rCLKCON=0x7ff8;	 
    rADCCON=0x1|(0<<2);		//Enable ADC 
    Delay(100);				//delay for 10ms for ADC reference voltage stabilization. 
 
    //Uart_Printf("Input ADCPSR value:"); 
    //adcpsr=Uart_GetIntNum(); 
    adcpsr=255; 
    rADCPSR=adcpsr; 
    Uart_Printf("ADC conv. freq.=%d(Hz)\n",(int)(MCLK/(2.*(adcpsr+1.))/16.) ); 
     
    while(Uart_GetKey()==0) 
    { 
	SoftDelay(10000); 
	a0=ReadAdc(0); 
	a1=ReadAdc(1); 
	a2=ReadAdc(2); 
	//a3=ReadAdc(3); 
	//a4=ReadAdc(4); 
	//a5=ReadAdc(5); 
	//a6=ReadAdc(6); 
	//a7=ReadAdc(7); 
	 
	Uart_Printf("0:%04d 1:%04d 2:%04d \n",/*3:%04d 4:%04d 5:%04d 6:%04d 7:%04d\n",*/ 
		a0,a1,a2,a3,a4,a5,a6,a7); 
    } 
} 
 
int ReadAdc(int ch) 
{ 
    int i; 
    static int prevCh=-1; 
 
    if(prevCh!=ch) 
    { 
    	rADCCON=0x0|(ch<<2);	//setup channel. 
    	for(i=0;i<150;i++);	//min. 15us 
    } 
    rADCCON=0x1|(ch<<2);	//Start A/D conversion 
    while(rADCCON &0x1);	//To avoid The first FLAG error case. 
				//(The START bit is cleared in one ADC clock.) 
    while(!(rADCCON & 0x40)); 
    for(i=0;i