📄 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"
//==================================================================================
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)|(49<<6)|(ch<<3); //setup channel
if(prevCh!=ch)
{
for(i=0;i<1000;i++); //delay to set up the next channel
prevCh=ch;
}
rADCCON|=0x1; //start ADC
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 adcdata=0; //Initialize variables
Uart_Printf( "\nADC INPUT Test, press ESC key to exit !\n" ) ;
while( Uart_GetKey() != ESC_KEY )
{
adcdata=ReadAdc(ADC_CH);
Uart_Printf( "AIN%d: %04d\n", ADC_CH,adcdata );
Delay( 2000 ) ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -