📄 adc.c
字号:
/****************************************************************************
【文 件 名 称】ADC.c
【功 能 描 述】三星S3C44B0X板demo程序代码
【程 序 版 本】2.0
【创建人及创建日期】龚俊//2003-07-02 15:27
【修改人及修改日期】龚俊//2004-2-12 9:18
****************************************************************************/
//***************************************************************************
#include "44b.h"
#include "def.h"
#include "option.h"
#include "utils.h"
/****************************************************************************
【功能说明】模数转换初始化
****************************************************************************/
void ADC_Init(void)
{
rCLKCON = rCLKCON | (1<<12); //控制系统主时钟进入ADC单元模块
rADCCON = 0x1|(0<<2); //ADC转换使能,选择AIN7
Delay(100); //延时若干个100us
rADCPSR = 10; //ADC转换频率为:(int)(MCLK/(2*(rADCPSR+1))/16)
//printf("ADC Feq = %d(Hz)\n\n",(int)(MCLK_D/(2.*(10+1.))/16.) );
}
//***************************************************************************
/****************************************************************************
【功能说明】ADC某一通道进行转换,返回转换的数据
****************************************************************************/
unsigned short Read_Adc(unsigned char ch)
{
int i;
static int prevCh=-1;
if(prevCh!=ch)
{
rADCCON = 0x1|(ch<<2); //设置AD转换通道
for(i=0;i<150;i++); //最小15uS
}
rADCCON=0x1|(ch<<2); //开始AD转换
while(rADCCON & 0x1); //避免标志FLAG错误
while(!(rADCCON & 0x40)); //等待AD转换结束
for(i = 0; i < rADCPSR; i++); //避免第二次标志FLAG错误
prevCh=ch;
return rADCDAT; //返回AD转换值
}
//***************************************************************************
/****************************************************************************
【功能说明】ADC Test
****************************************************************************/
void ADC_Test(void)
{
int a0=0,a1=0,a2=0,a3=0,a4=0,a5=0,a6=0,a7=0;
printf( "\nADC Test\n" ) ;
printf( "Please change R1 and see what happen\n" ) ;
printf( "Press ESC key to exit!\n\n" ) ;
ADC_Init() ; //模数转换初始化
while( !( kbhit && (getkey()==ESC_KEY) ) )
{
a0 = Read_Adc(0); //ADC某一通道进行转换,返回转换的数据
a1 = Read_Adc(1); //ADC某一通道进行转换,返回转换的数据
a2 = Read_Adc(2); //ADC某一通道进行转换,返回转换的数据
a3 = Read_Adc(3); //ADC某一通道进行转换,返回转换的数据
a4 = Read_Adc(4); //ADC某一通道进行转换,返回转换的数据
a5 = Read_Adc(5); //ADC某一通道进行转换,返回转换的数据
a6 = Read_Adc(6); //ADC某一通道进行转换,返回转换的数据
a7 = Read_Adc(7); //ADC某一通道进行转换,返回转换的数据
printf("ADC0-7 OUTPUT : (%4d) %4d %4d %4d %4d %4d %4d %4d\n",a0,a1,a2,a3,a4,a5,a6,a7);
Delay(400); //延时
}
printf( "\n" ) ;
}
//***************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -