⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adc.c

📁 is about the 51 and the LCD
💻 C
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -