adc.c
来自「is about the 51 and the LCD」· C语言 代码 · 共 29 行
C
29 行
#ifndef __ADC_C__
#define __ADC_C__
//#include <iom16v.h>
void adc_init(void);
uint adc_read(uchar channel);
//---------------------------------------------------------------------------
void adc_init(void)
{
ADCSR = 0x00; //disable adc
ADMUX = 0xc0; //select adc input 0
ACSR = 0x80;
ADCSR = 0x87;
}
//--------------------------------------------------------------------------
uint adc_read(uchar channel)
{
uint temp;
channel |=0xc0;
ADMUX = channel; // Select channel
ADCSR |= 0x40; // Start conversion
while (!(ADCSR & 0x10)); // Check if converstion is ready
ADCSR |= 0x10;
temp = ADCL;
temp += (int)ADCH << 8;
return(temp);
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?