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

📄 adc.c

📁 arm7 AD0804 test source code
💻 C
字号:

//***************************************************************************
#include "..\inc\ADC.h"
#include "..\inc\led.h"
/*
#include "def.h"
#include "option.h"
#include "utils.h"*/

/****************************************************************************
【功能说明】模数转换初始化
****************************************************************************/

void ADC_Init(void)
{
	rCLKCON = rCLKCON | (1<<12);		//控制系统主时钟进入ADC单元模块
	rADCCON = 0x1|(0<<2);		
	sysUtilsUSecDelay(100);		//延时若干个100us
	rADCPSR = 10;

}
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转换值
}

void ADC_Test(void)
{
    int a0=0,a1=0;
    float b0=0,b1=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某一通道进行转换,返回转换的数据
		//printf("ADC0-7 OUTPUT : %4d %4d \n",a0,a1);
		b1=a0*2.500/1024;
		b0=a1*2.500/1024;
		Show_Led(0,b0,1);sysUtilsUSecDelay(2000);
		Show_Led(1,((U16)(b0*10)%10),0);sysUtilsUSecDelay(2000);
		Show_Led(2,((U16)(b0*100)%10),0);sysUtilsUSecDelay(2000);
		
		Show_Led(3,b1,1);sysUtilsUSecDelay(2000);
		Show_Led(4,((U16)(b1*10)%10),0);sysUtilsUSecDelay(2000);
		Show_Led(5,((U16)(b1*100)%10),0);sysUtilsUSecDelay(2000);
    }
}
//***************************************************************************

⌨️ 快捷键说明

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