arm9.rar

源代码在线查看: adc.c

软件大小: 5914 K
上传用户: tiantianyuehui
关键词: arm
下载地址: 免注册下载 普通下载 VIP

相关代码

				//====================================================================
				// 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 "config.h"
				#include "board.h"
				#include "utils.h"
				
				#define REQCNT 100              //May 08, 2002 SOP
				
				#define ADC_FREQ 2500000
				
				#define LOOP 10000
				
				volatile U32 preScaler;
				
				//==================================================================================		
				int ReadAdc(int ch)
				{
				    int i;
				    static int prevCh=-1;
				
				    rADCCON = (1				
				    if(prevCh!=ch)
				    {
					rADCCON = (1					for(i=0;i					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
				
				    return ( (int)rADCDAT0 & 0x3ff );
				}
				
				
				//==================================================================================
				void Test_Adc(void) 
				{
				    int a0=0; //Initialize variables
				    U32 rADCCON_save = rADCCON;
				    
				   	printf( "ADC INPUT Test, press ESC key to exit !\n" ) ;
				
				    preScaler = ADC_FREQ;
				    printf("ADC conv. freq. = %dHz\n",preScaler);
				    preScaler = GetMasterClock()/ADC_FREQ -1;               //PCLK:50.7MHz
				    
				    printf("PCLK/ADC_FREQ - 1 = %d\n",preScaler);
				    
				    while( getkey() != ESC_KEY )
				    {
					    a0=ReadAdc(0);
				
					    printf( "AIN0: %04d\n", a0 );
						Delay( 80 ) ;
				    }
				    
				    //rADCCON=(0				    rADCCON = rADCCON_save;
				    printf("\nrADCCON = 0x%x\n", rADCCON);
				}
				
				
				
							

相关资源