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

📄 fft_new_test.lst

📁 在c8051平台上实现的FFT运算
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   FFT_NEW_TEST                                                          07/26/2007 09:57:47 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE FFT_NEW_TEST
OBJECT MODULE PLACED IN FFT_New_Test.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE FFT_New_Test.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /*-------------------------------------------------------------------------------------------------
   2          文件名称:FFT_New_Test.c
   3          创建日期:07.06.12
   4          修改日期:07.06.18
   5                     -整理
   6          文件说明:功能:
   7                     -基于C8051F000系列单片机的FFT试验程序
   8                   参数:
   9                             -通道0的IDT:0x00000100
  10                     -通道0的MSK:0x1FFFFFFF(通道0只能接受IDT为0x00000100的消息)
  11                             -通道1的IDT:0x00000101
  12                             -通道1的MSK:0x1FFFFFFF(通道1只能发送IDT为0x00000101的消息)
  13                             -UartBuffer大小为16字节
  14                             -CanBuffer 大小为16字节
  15          创建人:  李大伟
  16          -------------------------------------------------------------------------------------------------*/
  17          #include <stdio.h>
  18          #include "C8051F000.h"
  19          #include "FFT_Code_Tables.h"
  20          
  21          //ADC0寄存器定义
  22          sfr16 ADC0     =     0xBE;             
  23          
  24          //数据的位数
  25          #define NUM_BITS     16                    
  26          
  27          //外部XRAM数据的起始
  28          #define DATA_BEGIN   0x0000 
  29                     
  30          //外部时钟频率,PLL输出频率=(EXTCLK*9/4)(Hz)
  31          #define EXTCLK       22118400          
  32          #define SYSCLK       49760000         
  33          
  34          //UART0波特率
  35          #define BAUDRATE     115200 
  36                     
  37          //采样频率(Hz)
  38          #define SAMPLE_RATE  10000             
  39          
  40          //为:1,只运行一次
  41          #define RUN_ONCE     1                 
  42          
  43          typedef union IBALONG 
  44          {
  45            long l;
  46            unsigned int  i[2];
  47            unsigned char b[4];
  48          }IBALONG;
  49          
  50          typedef union BAINT 
  51          { 
  52             int i;
  53             unsigned char b[2];
  54          }BAINT;
  55          
C51 COMPILER V7.50   FFT_NEW_TEST                                                          07/26/2007 09:57:47 PAGE 2   

  56          //函数申明
  57          void WindowCalc(int Win_Array[], unsigned char SE_data);
  58          void IntFFT(int ReArray[], int ImArray[]);
  59          void BitReverse(int BR_Array[]);
  60          void ADC0_ISR (void);
  61          
  62          //全局变量
  63          //FFT的XRAM空间=NUM_FFT*4字节(起始于DATA_BEGIN)
  64          int xdata Real[NUM_FFT] _at_  DATA_BEGIN;
  65          int xdata Imag[NUM_FFT] _at_ (DATA_BEGIN+(NUM_FFT*2));
  66          
  67          //NUM_FFT的定义在"FFT_Code_Tables.h"头文件中
  68          #if(NUM_FFT>=256)
  69          unsigned int index,ADC_Index;
  70          #endif
  71          
  72          #if(NUM_FFT<256)
              unsigned char index,ADC_Index;
              #endif
  75          
  76          unsigned int BinNum;            //循环变量
  77          bit Conversion_Set_Complete;//一轮采样结束标志位
  78          /*=================================================================================================
  79          01.名称:main
  80             入口:无
  81             出口:无
  82             功能:系统主函数
  83          =================================================================================================*/
  84          void main()
  85          {
  86   1        WDTCN   = 0xDE;                                          //看门狗
  87   1        WDTCN   = 0xAD;
  88   1        OSCICN  = 0x07;                                          //时钟
  89   1        XBR0    = 0x04;                                          //I/O
  90   1        XBR2    = 0x40;
  91   1        REF0CN  = 0x03;                                          //参考电压
  92   1        CKCON   = 0x10;                                          //定时器
  93   1        TCON    = 0x40;
  94   1        TMOD    = 0x20;
  95   1        TH1     = 0xCC;
  96   1        TMR3CN  = 0x06;
  97   1        TMR3RLL = 0x40;
  98   1        TMR3RLH = 0x01;
  99   1        TMR3L   = 0x40;
 100   1        TMR3H   = 0x01;
 101   1        SCON    = 0x40;                                           //UART
 102   1        ADC0CF  = 0x80;                                               //ADC
 103   1        ADC0CN  = 0x85;
 104   1        IE      = 0x80;                                               //中断使能
 105   1        
 106   1        
 107   1        while(1)
 108   1        {
 109   2              DisOfRuler1=SingleFrqMeasure(1);
*** ERROR C202 IN LINE 109 OF FFT_NEW_TEST.C: 'DisOfRuler1': undefined identifier
 110   2          DisOfRuler2=SingleFrqMeasure(2);
*** ERROR C202 IN LINE 110 OF FFT_NEW_TEST.C: 'DisOfRuler2': undefined identifier
 111   2          DisOfRuler3=SingleFrqMeasure(3);
*** ERROR C202 IN LINE 111 OF FFT_NEW_TEST.C: 'DisOfRuler3': undefined identifier
 112   2        }
 113   1      }
 114          /*=================================================================================================
C51 COMPILER V7.50   FFT_NEW_TEST                                                          07/26/2007 09:57:47 PAGE 3   

 115          01.名  称:SingleFrqMeasure()
 116             功  能:单尺测量过程
 117             参  数:Sel: 0 - 关闭
 118                          1 - 5.9348MHz
 119                                          2 - 593.48KHz
 120                                          3 - 59.348KHz
 121             返  回:对应尺的距离值
 122          =================================================================================================*/
 123          float SingleFrqMeasure(unsigned char SelFrq)
 124          {
 125   1        float PhaseW,PhaseN;
 126   1              
 127   1        //光强检测GetSignalRange();
 128   1      
 129   1        //SelFrq控制CPLD选择相应的频率测距
 130   1      
 131   1        PhaseW=GetPhase(OUT);
*** ERROR C202 IN LINE 131 OF FFT_NEW_TEST.C: 'OUT': undefined identifier
 132   1        PhaseN=GetPhase(IN);
*** ERROR C202 IN LINE 132 OF FFT_NEW_TEST.C: 'IN': undefined identifier
 133   1      
 134   1        //将角度值转化为距离值
 135   1        switch(Sel)
*** ERROR C202 IN LINE 135 OF FFT_NEW_TEST.C: 'Sel': undefined identifier
 136   1        {
 137   2              case 0x01://5.9348MHz
 138   2              break;
 139   2              case 0x02://593.48KHz
 140   2              break;
 141   2              case 0x03://59.348KHz
 142   2              break;
 143   2              case 0x00://00
 144   2              break;
 145   2              default:
 146   2          break;
 147   2        }
 148   1        //距离:
 149   1        return (PhaseW-PhaseN);
 150   1      }
 151          /*=================================================================================================
 152          01.名  称:GetPhase()
 153             功  能:计算距离值
 154             参  数:无
 155             返  回:无
 156          =================================================================================================*/
 157          float GetPhase(unsigned char NW)
 158          {
 159   1        float angle;
 160   1      
 161   1        //NW控制电机打到内或者外光路
 162   1      
 163   1        ADC_Index=0;
 164   1        Conversion_Set_Complete=0;
 165   1        EIE2|=0x02;                         //ADC中断允许
 166   1        while(!Conversion_Set_Complete);
 167   1      
 168   1        //对Real数据进行排序
 169   1        Sort(Real);
 170   1      
 171   1        WindowCalc(Real,1);                 //加窗
 172   1        BitReverse(Real);                   //将输入的数据位反向重排
 173   1        IntFFT(Real,Imag);                  //对输入的数据进行FFT运算
C51 COMPILER V7.50   FFT_NEW_TEST                                                          07/26/2007 09:57:47 PAGE 4   

 174   1      
 175   1        angle=atan(Imag[1]/Real[1]);
 176   1        return ((180/pi)*angle);            //转成距离值
 177   1      }
 178          /*=================================================================================================
 179          02.名称:WindowCalc
 180             入口:
 181                  -Win_Array[]:为0到(NUM_FFT/2)-1的采样数据所对应窗口系数,对于NUM_FFT/2到NUM_FFT-1的采样数据
 182                                       所对应窗口系数可通过0到(NUM_FFT/2)-1的采样数据所对应窗口系数镜像得到。窗口值为
 183                                                   一个小于1的值(WindowFunc[x]/65536),NUM_FFT/2处的值假设为1.0(65536)。
 184                  -SE_data        :为1:
 185                                         -则输入数据被假定为单端信号,那么将他调整为差分信号数据,这样就可以去除直
 186                                          流流偏值。
 187                                                   为0:
 188                                                     -则输入数据被假定为差分信号。
 189             出口:无
 190             功能:使用存储在数组WindowFunc[]中的数值对Win_Array[]数组加窗
 191          =================================================================================================*/
 192          void WindowCalc(int Win_Array[],unsigned char SE_data)
 193          {
 194   1      #if(WINDOW_TYPE!=0)                               //加窗类型
 195   1        IBALONG NewVal;
 196   1      
 197   1        if(SE_data)  Win_Array[0]^=0x8000;              //如果数据时单端的转换为差分的
 198   1        NewVal.l=(long)Win_Array[0]*WindowFunc[0];      //加窗
 199   1        if((NewVal.l<0)&&(NewVal.i[1])) Win_Array[0]=NewVal.i[0]+1;
 200   1        else Win_Array[0]=NewVal.i[0];
 201   1        if(SE_data) Win_Array[NUM_FFT/2]^=0x8000;       //如果数据时单端的转换为差分的
 202   1      
 203   1        for(index=1;index<NUM_FFT/2;index++)
 204   1        {
 205   2          if(SE_data) Win_Array[index]^=0x8000;         //数组的1到(NUM_FFT/2 - 1)
 206   2          NewVal.l=(long)Win_Array[index]*WindowFunc[index];
 207   2          if((NewVal.l<0)&&(NewVal.i[1])) Win_Array [index]=NewVal.i[0]+1;
 208   2          else Win_Array[index]=NewVal.i[0];
 209   2              
 210   2              if(SE_data)     Win_Array[NUM_FFT-index]^=0x8000; //数组的(NUM_FFT/2 + 1)到(NUM_FFT - 1)
 211   2          NewVal.l=(long)Win_Array[NUM_FFT-index]*WindowFunc[index];
 212   2          if((NewVal.l<0)&&(NewVal.i[1])) Win_Array[NUM_FFT-index]=NewVal.i[0]+1;
 213   2          else Win_Array[NUM_FFT-index]=NewVal.i[0];
 214   2        }
 215   1      #endif
 216   1      #if(WINDOW_TYPE==0)                               //不加窗
                if(SE_data)                                     //如果数据时单端的
                {                                               //转换为差分的
                  for(index=0;index<NUM_FFT;index++) Win_Array[index]^=0x8000;//最高位通过和1取异或取反
                }
              #endif
 222   1      } 
 223          /*=================================================================================================

⌨️ 快捷键说明

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