📄 adc.c
字号:
/********************************************************************************/
//
// builder : 2007-04-10
// Target : ATMEAG 48V
// Crystal : 内部 8.00 MHz
//
// ADC 转换模块
/********************************************************************************/
#include <avr/io.h>
#include <avr/delay.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#define uchar unsigned char
#define uint unsigned int
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
----------------------------------------------------------------*/
uint adc_colect(uchar chanal)
{
uchar i;
uint ad_add;
uint temp,temp1;
uint adh;
ADMUX = ADMUX & 0xf0 | chanal;
ad_add = 0;
for(i=0;i<16;i++)
{
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
temp1 = ADCL;
temp = (ADCH&0x03)<<8;
temp += temp1;
ad_add += temp;
}
adh = ad_add>>4;
return(adh);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -