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

📄 adc.c

📁 CPU 2410 硬件使用实例!该程序包是ADC转换的程序
💻 C
字号:
//====================================================================
// File Name : Adc.c
// Function  : S3C2410 ADC Test 
// Program   : Kang, Weon Tark 
// Date      : May 22, 2002
// Version   : 0.0
// History
//   0.0 : Programming start (March 29,2002) -> KWT
//         ADC Test                          -> May 15, 2002 SOP
//====================================================================

#include "def.h"
#include "2410addr.h"
#include "2410lib.h"
#include "adc.h"

#define LOOP 10000
volatile U32 preScaler;

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

    //(1<<14)--> A/D converter prescaler enable.
    //(preScaler<<6)--> A/D converter prescaler value.
    //(ch<<3)--> Analog input channel select.
    rADCCON = (1<<14)|(preScaler<<6)|(ch<<3);	//setup channel

    if(prevCh!=ch)
    {
	rADCCON = (1<<14)|(preScaler<<6)|(ch<<3);   //setup channel
	for(i=0;i<LOOP;i++);	//delay to set up the next channel
	prevCh=ch;
    }
    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
    
    //Normal ADC conversion data value: 0 ~ 3FF
    return ( (int)rADCDAT0 & 0x3ff );
}


//==================================================================================
void Test_Adc(void) 
{
    int a0=0; //Initialize variables
    U32 rADCCON_save = rADCCON;
    
   	Uart_Printf( "\nADC INPUT Test, press ESC key to exit !\n" ) ;

    preScaler = ADC_FREQ; //ADC_FREQ = 2.5MHz
    Uart_Printf("ADC conv. freq. = %dHz\n",preScaler);
    
    preScaler = 50000000/ADC_FREQ -1;               //PCLK:50.7MHz
    Uart_Printf("PCLK/ADC_FREQ - 1 = %d\n",preScaler);
    
    while( Uart_GetKey() != ESC_KEY )
    {
        a0=ReadAdc(ADC_CH);        
	    Uart_Printf( "AIN%d: %04d \n", ADC_CH,a0);	    	    
		Delay( 2000 ) ;
    }
    
    rADCCON = rADCCON_save;
}

⌨️ 快捷键说明

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