adc.c

来自「前两年在一家模型公司开发的」· C语言 代码 · 共 57 行

C
57
字号

/********************************************************************************/
//		
// 		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 + =
减小字号Ctrl + -
显示快捷键?