📄 adc.h
字号:
//ICC-AVR application builder : 2007-4-3 10:53:29
// Target : M8
// Crystal: 8.0000Mhz
#ifndef __ADC__H
#define __ADC__H
void Init_Adc(void);
int Read_Adc(unsigned char channel);
void Init_Adc(void)
{
ACSR = 0x80;//will zhao modify:07/04/12
//ADMUX = 0x47;//0100 0111 AREF=AVCC
ADMUX = 0xc7;//1100 0111 AREF=2.56v
ADCSRA= 0xC7;//Enable ADC & start 1:st dummy conversion
}
int Read_Adc(unsigned char channel)//channel=0x0e 时接测试电压1.23
{
int i;
ADMUX = (ADMUX&0xf0)|(0x0F&channel); // Select channel
ADCSRA|= 0x47; // Start conversion
while (!(ADCSRA & 0x10)); // Check if converstion is ready
ADCSRA |= 0x17; // Clear Conversion ready flag by setting the bit
i = ADCL; // Read 8 low bits first (important)
i |= (int)ADCH << 8; // Read 2 high bits and multiply with 256
return i;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -