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

📄 adc.c

📁 ICCAVR中所有的库函数源码
💻 C
字号:
/*
**  Purpose:    ADC init & read routines without interrupt.
**
**  Version:    1.0.0, 7:th of October 1999
**
**  Author:     Lars Wictorsson
**              LAWICEL / SWEDEN
**              http://www.lawicel.com   lars@lawicel.com
**
**  History:    1999-10-07  Created
*/

#include <io8535.h>

void InitADC( void)
{
    ADMUX = 0;          // Select channel 0
    ADCSR = 0xC0;       // Enable ADC & start 1:st dummy conversion
}

int ReadADC( unsigned char channel)
{
    int i;

    ADMUX = channel;                        // Select channel
    
    ADCSR |= 0x40;                          // Start conversion
    
    while (!(ADCSR & 0x10));                // Check if converstion is ready
    
    ADCSR |= 0x10;                          // Clear Conversion ready flag by setting the bit

    i = ADCL;                               // Read 8 low bits first (important)
    i += (int)ADCH << 8;                    // Read 2 high bits and multiply with 256

    return i;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -