📄 adc_no_i.c
字号:
#include <io.h>
#include <sig-avr.h>
/**********************************************************************
Title : adcnv_avg
Purpose : Gets an ADC Conversion Value and Returns it.
Maximum number of averages = 64.
In : Number of averages to take when converting.
Out : 16-Bit word containing current ADC conversion value
Rev : 1.2
Mod History : 1.0 - Original Version
: 1.1 - Result is now the average of four samples.
: 1.2 - User supplies number of averages.
**********************************************************************/
unsigned int adcnv_avg (unsigned char AVG_Number)
{
unsigned char ADCSR_data,ADCH_data,ADCL_data,i; // ADC Register Variables
unsigned int ADC_16; // Variable that holds 16 bit ADC Value
ADC_16 = 0; // Initialise this variable to zero.
for(i=0;i<AVG_Number;i++) // Were taking the average AVG_Number samples.
{
outp((BV(ADEN)|BV(ADSC)|0x07),ADCSR); // Start a conversion
do ADCSR_data = inp(ADCSR); while( (BV(ADIF) & ADCSR_data) != 0x10); // Get the ADC Value
outp(BV(ADIF)|ADCSR_data,ADCSR); // Clear the ADC conv interupt bit
ADCL_data= inp(ADCL); // Read the Low Byte
ADCH_data= inp(ADCH); // Read the High Byte
ADC_16 = ((ADCH_data * 0x100) + ADCL_data) + ADC_16; // Convert the two 8-bit bytes into a 16 bit word
}
ADC_16 = ADC_16 / AVG_Number; // We are taking the average of AVG_Number samples.
return(ADC_16); // Return the 16-Bit Word
}
/*unsigned int adcs()
{
unsigned int data_com,temp1,temp2,data_disp,data_record;
unsigned char i;
data_com = 0;
for (i=0;i<3;i++)
{
temp1=adcnv_avg(8);
// WDR();
while (temp1!=temp2) //以相邻两次想等为准
{
temp2 = temp1;
temp1= adcnv_avg(8);
};
data_com += temp1; //连续做3次
};
data_record += data_com/3; //data_record全局变量或静态变量
data_disp = data_record/3; //第二求平均
data_record -= data_disp; //纪录中减少一次,以备下一次用
return(data_disp);
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -