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

📄 main.c

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

//-----------------------------------------------------------------------------
// IntFFT_BRIN.c
//-----------------------------------------------------------------------------
// Copyright 2003 Cygnal Integrated Products, Inc.
//
// AUTH: BD
// DATE: 30 JAN 03
//
// This program collects data using ADC0 at <SAMPLE_RATE> Hz and performs
// an FFT on the data.  The Real and Imaginary parts of the results are then
// sent to the UART peripheral at <BAUDRATE> bps, where they can be displayed
// or captured using a terminal program.
//
// Note that the FFT performed in this software is optimized for storage space
// (RAM).  The resulting Frequency-domain data is not suitable for analyzing
// Signal-to-noise or distortion performance.
//
// This program uses a 22.1184 MHz crystal oscillator multiplied by (9/4)
// for an effective SYSCLK of 49.7664 Mhz. This program also initializes and
// uses UART0 at <BAUDRATE> bits per second.
//
// Target: C8051F12x
// Tool chain: KEIL C51 6.03
//
#include "common.h"
#include "Int_FFT.h"
#include "ADC0.h"


bit  Conversion_Set_Complete=0;
unsigned int BinNum=0;
unsigned int index=0, ADC_Index=0;

void main()
{

   // disable watchdog timer
   WDTCN = 0xde;
   WDTCN = 0xad;


   SYSCLK_Init();                      // initialize external clock and PLL
   PORT_Init ();                       // set up Port I/O
   UART0_Init ();                      // initialize UART0
   TIMER3_Init (SYSCLK/SAMPLE_RATE);   // initialize Timer3 to overflow at
                                       // <SAMPLE_RATE>
   ADC0_Init ();                       // init ADC0

   EA = 1;                             // globally enable interrupts

   while (1)
   {
      ADC_Index = 0;
      Conversion_Set_Complete = 0;

      EIE2 |= 0x02;                    // enable ADC interrupts

      SFRPAGE = LEGACY_PAGE;

      while(!Conversion_Set_Complete);


      SFRPAGE = UART0_PAGE;
      printf("\nCollected Data\nSample\tValue\n");
      for (BinNum = 0; BinNum < NUM_FFT; BinNum++)
      {
         // Print Data in the format: Sample <tab> Value <tab>
         printf("%d\t%u\n", BinNum, Real[BinNum]);
      }

      WindowCalc(Real, 1);             // Window Real Data, and convert to
                                       // differential if it is single-ended

      Bit_Reverse(Real);               // Sort Real (Input) Data in bit-reverse
                                       // order
      Int_FFT(Real, Imag);             // Perform FFT on data

      SFRPAGE = UART0_PAGE;

      printf("\nBin\tReal\tImag\n");

      // Output the FFT data to the UART
      for (BinNum = 0; BinNum < NUM_FFT; BinNum++)
      {
         // Print Data in the format: Bin <tab> Real <tab> Imaginary
         printf("%d\t%d\t%d\n", BinNum, Real[BinNum], Imag[BinNum]);
      }

     if (RUN_ONCE)
         while(1);

   }
}

⌨️ 快捷键说明

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