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

📄 adc0_init.c

📁 基于8051F单片机,实现1024点的FFT 用C 语言实现的.效果与FPGA实现相同.
💻 C
字号:

#include "common.h"
#include "ADC0.h"
#include "int_fft.h"

unsigned int index, ADC_Index;

//-----------------------------------------------------------------------------
// TIMER3_Init
//-----------------------------------------------------------------------------
//
// Configure Timer3 to auto-reload at interval specified by <counts> (no
// interrupt generated) using SYSCLK as its time base.
//
void TIMER3_Init (int counts)
{
   char old_SFRPAGE = SFRPAGE;      // Save Current SFR page

   SFRPAGE = TMR3_PAGE;             // Switch to Timer3 Setup Page

   TMR3CN = 0x00;                   // Stop Timer3; Clear TF3
   TMR3CF = 0x08;                   // use SYSCLK as timebase

   RCAP3  = -counts;                // Init reload values
   TMR3    = 0xffff;                // set to reload immediately
   EIE2   &= ~0x01;                 // disable Timer3 interrupts
   TR3 = 0x01;                      // start Timer3

   SFRPAGE = old_SFRPAGE;           // restore SFRPAGE
}


//-----------------------------------------------------------------------------
// ADC0_Init
//-----------------------------------------------------------------------------
//
// Configure ADC0 to use Timer3 overflows as conversion source, to
// generate an interrupt on conversion complete, and to use left-justified
// output mode.  Enables ADC0 end of conversion interrupt. Enables ADC0.
//
void ADC0_Init (void)
{
   char old_SFRPAGE = SFRPAGE;      // Store current SFRPAGE

   SFRPAGE = ADC0_PAGE;             // Switch to ADC0 Setup Page
   ADC0CN = 0x05;                   // ADC disabled; normal tracking
                                    // mode; ADC conversions are initiated
                                    // on overflow of Timer3, left-justify

   REF0CN = 0x03;                   // enable on-chip VREF and output buffer

   AMX0CF = 0x00;                   // Single-ended AIN0.0 input
   AMX0SL = 0x00;

   ADC0CF = (SYSCLK/(2*2500000)) << 3;  // ADC conversion clock <= 2.5MHz
   ADC0CF |= 0x00;                  // PGA gain = 1

   AD0EN = 1;                       // enable ADC0

   SFRPAGE = old_SFRPAGE;           // restore SFRPAGE
}


//-----------------------------------------------------------------------------
// Interrupt Service Routines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// ADC0_ISR
//-----------------------------------------------------------------------------
//
// ADC end-of-conversion ISR
// The ADC sample is stored in memory, and an index variable is incremented.
// If enough samples have been taken to process the FFT, then a flag is set,
// and ADC interrupts are disabled until the next set is requested.
//
void ADC0_ISR (void) interrupt 15 using 3
{
  AD0INT = 0;                      // clear ADC conversion complete
                                    // flag

   Real[ADC_Index] = ADC0;          // store ADC value

   ADC_Index++;                     // Increment the index into memory
  
   if (ADC_Index >= NUM_FFT)        // If enough samples have been collected
   {
      Conversion_Set_Complete = 1;  // Tell the Main Routine and...
      EIE2 = ~0x02;                // disable ADC interrupts
   	  EIE2 &=EIE2;
   }
   
}

⌨️ 快捷键说明

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