#include <ioavr.h>
#include <intrinsics.h>
#include "ADCdouble.h"
/* Initialize ADC */
//端口状态初始化设置函数
void AdcPort_Init()
{
PORTA=0x00;
DDRA=0X00; //ADC通道设置为输入口,高阻态
}
void AD_init()
{
ADMUX|=(1<<MUX2)|(1<<REFS0); //ADC参考电压为AREF,ADC结果右对齐,选择通道ADC1
ADCSRA|=(1<<ADEN)|(1<<ADSC)|(1<<ADATE)|(1<<ADIE);
SFIOR=0X00; //使用自动连续转换
//SREG|=BIT(7);
}
unsigned int AD_getdata()
{
unsigned int x,y;
x=(unsigned int)ADCL;
y=(unsigned int)ADCH;
y=(y<<8)+x;
return y;
}
/*void convert()
{ unsigned int a,b,c,d;
AD_data=(int)((long)AD_getdata()*5010/1024);
a=AD_data/1000;
b=AD_data%1000/100;
c=(AD_data%1000)%100/10;
d=(AD_data%1000)%100%10;
}*/
#pragma vector=ADC_vect
__interrupt void ADC_Server(void)
{
unsigned int buffer[32];
static unsigned int index=0;
buffer[index++]=AD_getdata();
if(index==32)
{
index=0;
unsigned char i;
for(i=0;i<32;i++)
sum+=buffer[i];
sum=sum/32;
sum=sum*5000/1024;
}
}
此帖出自
小平头技术问答
一周热门 更多>