📄 adcdrv.c
字号:
/*
adcDrv.c
Read ADC value
*/
/*@+relaxquals@*/ //SPLINT avoid detecting each time a char is stored in an int
/*@+charindex@*/ //Only detect if used in a dengirus way
#include "adcDrv.h"
#include <iom88.h>
void acdDrv_init(void)
{
// Enable AD converter and set prescaler to 64 (8M Hz /64 = 125k Hz)
ADCSRA = (unsigned char)0x80 | 6;
//Make first conversation (setup ref voltage)
adcDrv_getAdc(GND);
}
unsigned int adcDrv_getAdc(enum ADCCHANNEL ch)
{
volatile unsigned char temp;
// Enable AD converter and set prescaler to 64 (8M Hz /64 = 125k Hz)
ADCSRA = (unsigned char)0x80 | 6;
//Use Connext VAVCC to ref no left adjust, and select channel
ADMUX = (unsigned char)0x40 | (unsigned char)ch;
//Start AD conversion
ADCSRA_Bit6 =(unsigned char)1;
//Wait for conversation to end
//while(ADCSRA_Bit6){;};
while((temp=ADCSRA_Bit6)!= (unsigned char)0){;};
// for(temp=ADCSRA; (temp&(1<<6))!= (unsigned char)0; temp=ADCSRA){;};
return ADC;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -