?? adc.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 + -