原理图
(原文件名:350.jpg)
程序
///////////////////////////////////////////////////////////////////////////////////////////////////
//
//
// FILE NAME : adc.c
// TARGET DEVICE : c8051f350
// IDE VER : KEIL C51V900
// CREATED ON : 10-09-09
// CREATED BY : BILLTIAN
//
//
///////////////////////////////////////////////////////////////////////////////////////////////////
#define _IN_adc_C_
///////////////////////////////////////////////////////////////////////////////////////////////////
// Includes
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "main.h"
//-----------------------------------------------------------------------------
// ADC0_Init extVREF Bipolar AIN0.1-AIN0.0
//-----------------------------------------------------------------------------
//
// This function initializes the ADC to measure across AIN0.1 and AIN0.0
// on the Target Board (Differential measurements, Bipolar codes)
void ADC0_Init (void)
{
unsigned ADC0_decimation;
REF0CN &= ~0x01; // disable internal vref
//REF0CN |= 0x01; // (enable if using internal vref)
ADC0CN = 0x00; // unipolar output codes, GAIN=1
//ADC0CN = 0x10; // Bipolar output codes, GAIN=1
//ADC0CF = 0x00; // interrupts upon SINC3 filter output and uses internal VREF
ADC0CF = 0x04; // interrupts upon SINC3 filter output and uses external VREF
ADC0CLK = (SYS_CLK_FREQ/MDCLK)-1; // Ideally, MDCLK = 2.4576 MHz Generate MDCLK for modulator.
// program decimation rate for desired OWR
ADC0_decimation = SYS_CLK_FREQ/OWR/(ADC0CLK+1)/128;
ADC0_decimation--;
ADC0DEC = ADC0_decimation;
ADC0BUF = 0x00; // ¹Ø±ÕÊäÈ뻺³å
ADC0MD = 0x81; // ÍêÈ«ÄÚ²¿Ð£×¼
while (!AD0CALC); // µÈ´ýת»»Íê³É
ADC0MD &= ~0x07;
// ADC0MUX = 0x37; // ²î·ÖÊäÈë
ADC0MUX = 0x07; // ²î·ÖÊäÈë
//ADC0MD |= 0x80; // ʹÄÜ(IDLE Mode)
ADC0MD |= 0x83; // Æô¶¯Á¬Ðøת»»
EIE1 |= 0x08; // ʹÄÜ ADC0 ÖжÏ
ucADCFlag = 0;
ucADCStat = 0;
uiADCResult[0] = 0;
uiADCResult[1] = 0;
uiADCResult[2] = 0;
uiADCResult[3] = 0;
}
void ADC0INT(void) interrupt 10
{
AD0INT = 0; //Çå AD0 ÖжϱêÖ¾
uiADCResult[ucADCStat] = (ADC0H<<8) + ADC0M;
if(MAX_CH == ucADCStat)
{
ucADCStat = 0;
ADC0MUX = 0x07;
ucADCFlag = 1;
}
else
{
ucADCStat++;
ADC0MUX = (ucADCStat<<4)|0x07;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// Functions
///////////////////////////////////////////////////////////////////////////////////////////////////
一周热门 更多>