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

📄 adc.c

📁 前两年在一家模型公司开发的
💻 C
字号:

/********************************************************************************/
//		
// 		builder : 2007-04-10
// 		Target  : ATMEAG 48V
// 		Crystal : 内部 8.00 MHz
//
//		ADC 转换模块
		
/********************************************************************************/


#include <iom48v.h>
#include <macros.h>



void adc_int(void)
{
	 ADMUX	= 0x40;		//set adc power avcc and the ref is Avref
 	 ADCSRA	= 0xC7; 	//enable adc and the div parame is 8	 
}


/*---------------------------------------------------------------
   			ADC 
----------------------------------------------------------------*/

unsigned int AD_CH(unsigned char CHn)
{
	union	
	{	
		unsigned int	temp;
		unsigned char  	datas[2];		
	}AD;
	

	ADMUX = (ADMUX & 0xF0) | CHn;
	
	ADCSRA = ADCSRA|(1<<ADSC);			   //start the adc
	while(ADCSRA&(1<<ADSC));			   //wait for the adc finish
 		
 	ADCSRA = ADCSRA|(1<<ADSC);			   //start the adc
	while(ADCSRA&(1<<ADSC));			   //wait for the adc finish
		
		
	AD.datas[0] = ADCL;
	AD.datas[1] = ADCH;
		
	return(AD.temp);
}


/******************************************************************************/


⌨️ 快捷键说明

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