?? adc.c
字號:
#include <iom128v.h>
#include <macros.h>
#include "stdtypes.h"
#include "adc.h"
#define ADC_END ADCSRA&0x10
int adc0_value;
int adc1_value;
UNS8 channel;
UNS8 adc_couter;
UNS8 adc_flag;
//ADC initialize
// Conversion time: 416uS
void adc_init(void)
{
ADCSRA = 0x00; //disable adc
ADMUX = 0x40; //select adc input 0
ACSR = 0x80;
ADCSRA = 0x07;//00101111 分頻128 不是連續轉換 中斷使能
adc0_value=0;
adc1_value=0;
channel=0;
adc_couter=0;
adc_flag=0;
}
int read_adc_value(void)
{
int value;
//CLI();
if(ADC_END)
{
ADCSRA=ADCSRA&(1<<ADIF);
value=ADCL; //Read 8 low bits first (important)
value|=(int)ADCH << 8; //read 2 high bits and shift into top byte
//SEI(); //re-enable interrupts
}
return value;
}
void system_protect(void)
{
/*改變采集通道*/
if(adc_couter==1)
{
if(ADC0==channel)
{
ADMUX=0x41;//select adc input 1
channel=1;
}
else if (ADC1==channel)
{
ADMUX = 0x40; //select adc input 0
channel=0;
}
adc_couter=0;
ADCSRA|=(1<<ADEN)|(1<<ADSC);//開始轉換
}
else
{
adc_couter++;
if(ADC0==channel)
{
adc0_value=read_adc_value();
}
else if (ADC1==channel)
{
adc1_value=read_adc_value();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -