AVR单片机ADC转换程序
#defineAD_ref_vref0x00//基准Vref
#defineAD_ref_avcc0x40//基准AVCC
#defineAD_ref_vref_in0xc0//基准内部Vref
#defineAD_refAD_ref_vref
//常量定义
//单端通道,不放大
#define AD_SE_ADC0 0x00//ADC0
#define AD_SE_ADC1 0x01//ADC1
#define AD_SE_ADC2 0x02//ADC2
#define AD_SE_ADC3 0x03//ADC3
#define AD_SE_ADC4 0x04//ADC4
#define AD_SE_ADC5 0x05//ADC5
#define AD_SE_ADC6 0x06//ADC6
#define AD_SE_ADC7 0x07//ADC7
//定义AD端口变量
#define AD_TEMPAD_SE_ADC0//ADC0
#define AD_VOUTAD_SE_ADC1//ADC1
#define AD_KEYINAD_SE_ADC2//ADC2
#defineAD_VINAD_SE_ADC3//ADC3
#define AD_IOUTAD_SE_ADC4//ADC4
#define AD_6BATAD_SE_ADC5//ADC5
#defineBAT_SE_PORTPORTB
#defineBAT_EN_PORTPORTB
#defineBAT_EN_PIN0X03
void adc_init(void)
{
DDRA=0x00;
ADCSRA=(1
//ADMUX=(1 //DIDR0=(1 } unsigned int read_adc(unsigned char adc_input,unsigned char i)//查询方式读取ADC单端通道 { unsigned charx; unsigned inty=0; ADC=0; ADMUX=(AD_ref|adc_input);//adc_input:单端通道 0x00~0x07,0x1E,0x1F //0xc0:选择内部2.56V参考电压 delay_nus(100); for(x=0;x { ADCSRA|=(1 loop_until_bit_is_set(ADCSRA,ADIF);//方法1 等待AD转换结束 //while ((ADCSRA&(1 //loop_until_bit_is_clear(ADCSRA,ADSC);//方法2 检测ADSC=0也行 ADCSRA|=(1 y += ADC;//ADC=ADCH:ADCL } return y; }
AVR单片机ADC转 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)