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

📄 main.lst

📁 51单片机C语言常用模块与综合系统设计实例精讲
💻 LST
字号:
C51 COMPILER V7.06   MAIN                                                                  10/23/2006 20:25:38 PAGE 1   


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

stmt level    source

   1          #include <stdio.h>
   2          #include <absacc.h>
   3          #include <intrins.h>
   4          #include <./Atmel/at89x52.h>
   5          #include "source.h"
   6          main()
   7          {
   8   1          filter_1();
   9   1              filter_2();
  10   1              filter_3();
  11   1              filter_4();
  12   1          filter_5();
  13   1              filter_6();
  14   1              filter_7();
  15   1              filter_8();
  16   1          filter_9();
  17   1              filter_10();
  18   1      }
  19          unsigned char get_ad(void){
  20   1              static unsigned char i;
  21   1              return i++;
  22   1      }
  23          void delay(void){
  24   1              unsigned char i=0;
  25   1              while(1){
  26   2                      i++;
  27   2                      if(i>20) return;
  28   2              }
  29   1      }
  30          /***限幅滤波**/
  31          #define A 10 //设置两次采样允许的最大偏差值
  32          char value;  //上次采用后的有效值变量
  33          char filter_1(void){
  34   1          char  new_value;  //本次采样值变量
  35   1          new_value=get_ad();  //读入本次采样值
  36   1          if((new_value-value>A)||(value-new_value>A)) //比较是否超出最大偏差值
  37   1              return  value; //如果超出,返回上次的有效值作为本次的有效值
  38   1          return  new_value;// 如果没有超出,返回本次的采样值作为本次的有效值
  39   1      }
  40          /***中位值滤波法***/
  41          #define N 11 //设置连续采样的次数
  42          
  43          char filter_2(void){
  44   1          char  value_buf[N]; //缓存N次采样值的存储变量
  45   1          char  count,i,j,temp; //i,j是冒泡排序的下标变量,count是采样数据读入的下标变量
  46   1                            //temp是临时变量
  47   1          for(count=0;count<N;count++) //连续读入N个采样值
  48   1          {
  49   2            value_buf[count]=get_ad();
  50   2            delay();
  51   2          }
  52   1          for(j=0;j<N;j++) //气泡排序,由小到大
  53   1          {
  54   2              for(i=0;i<N-j;i++)
  55   2              {
C51 COMPILER V7.06   MAIN                                                                  10/23/2006 20:25:38 PAGE 2   

  56   3                 if(value_buf[i]>value_buf[i+1])
  57   3               {
  58   4                 temp=value_buf[i];
  59   4                 value_buf[i]=value_buf[i+1];
  60   4                 value_buf[i+1]=temp;
  61   4                 }
  62   3               }
  63   2           }
  64   1           return value_buf[(N-1)/2]; //将排序后N个采样值的中间值作为最后结果返回
  65   1      }
  66          /**算数平均滤波法**/
  67          /* N为进行平均运算的每组采样值的数量,依据实际情况可以改变*/
  68          #undef N
  69          #define N 12 //设置每组参与平均运算的采样值个数
  70          
  71          char filter_3(){
  72   1          int  sum=0; //求和变量,用于存储采样值的累加值
  73   1          char count;//采样数据读入的下标变量
  74   1          for(count=0;count<N;count++) //连续读入N个采样值,并累加
  75   1          {
  76   2            sum+=get_ad();
  77   2            delay();
  78   2          }
  79   1          return (char)(sum/N); //讲累加值进行平均计算作为返回值
  80   1      }
  81          /**递推平均滤波法**/
  82          #undef N
  83          #define N 12 //设置FIFO队列的长度
  84          char  value_buf[N];//FIFO队列变量
  85          char  i=0; //队列的下标变量
  86          
  87          char filter_4(){
  88   1          char count;
  89   1              int  sum=0;
  90   1              value_buf[i++]=get_ad();
  91   1              if(i==N)  i=0;
  92   1          for(count=0;count<N;count++)
  93   1            sum+=value_buf[count];
  94   1          return(char)(sum/N);
  95   1      }
  96          /**中位值平均滤波法**/
  97          /* 采样值N为每组采样值的数量,依据实际情况可以改变*/
  98          #undef N
  99          #define N 12 //设置每组采样值的数量
 100          char filter_5()
 101          {
 102   1         char count,i,j,temp; //i,j是冒泡排序的下标变量,count是采样数据读入的下标变量
 103   1         char value_buf[N]; // 缓冲N个采样值的存储变量
 104   1         int  sum=0; //求和变量,用于存储采样值的累加值
 105   1         for  (count=0;count<N;count++) //连续读入N个采样值
 106   1         {
 107   2            value_buf[count] = get_ad();
 108   2            delay();
 109   2         }
 110   1         for (j=0;j<N-1;j++) //气泡排序,由小到大
 111   1         {
 112   2            for (i=0;i<N-j;i++)
 113   2            {
 114   3               if ( value_buf[i]>value_buf[i+1] )
 115   3               {
 116   4                  temp = value_buf[i];
 117   4                  value_buf[i] = value_buf[i+1];
C51 COMPILER V7.06   MAIN                                                                  10/23/2006 20:25:38 PAGE 3   

 118   4                   value_buf[i+1] = temp;
 119   4               }
 120   3            }
 121   2         }
 122   1         for(count=1;count<N-1;count++)
 123   1          sum += value_buf[count]; //去掉两端的最小和最大采样值,对中间的N-2个采样值求和
 124   1         return (char)(sum/(N-2));// 返回中间N-2个采样值的平均值
 125   1      }
 126          /**限幅平均滤波法**/
 127          /* A值可以根据实际情况调整,value为上次采样的有效值,new_value为当前采样值 */
 128          /* N为进行平均运算的每组采样值的数量,依据实际情况可以改变*/
 129          #undef A
 130          #undef N
 131          #define A 10 //设置两次采样允许的最大偏差值
 132          #define N 12 //设置每组参与平均运算的采样值个数
 133          char value;  //上次采用后的有效值变量
 134          
 135          char filter_6()
 136          {
 137   1          char  new_value;  //本次采样值变量
 138   1          int  sum=0; //求和变量,用于存储采样值的累加值
 139   1          char count;//采样数据读入的下标变量
 140   1              for(count=0;count<N;count++)
 141   1          {
 142   2                      new_value=get_ad();  //读入本次采样值
 143   2              if((new_value-value>A)||(value-new_value>A)) //比较是否超出最大偏差值
 144   2                      new_value=value; //如果超出,返回上次的有效值作为本次的有效值
 145   2              sum+=new_value; //累加采样的有效值
 146   2              value=new_value;
 147   2              delay();
 148   2          }
 149   1          return (char)(sum/N); //将累加值进行平均计算作为返回值
 150   1      }
 151          /**一阶滞后滤波法**/
 152          /* 为加快程序处理速度假定基数为100,a=0~100 */
 153          #define COE 50 //定义加权系数
 154          char value; //上一个采样值变量
 155          char filter_7()
 156          {
 157   1         char  new_value; //本次采样值变量
 158   1         new_value = get_ad();
 159   1         return (100-COE)*value + COE*new_value; //返回的本次滤波结果
 160   1      }
 161          
 162          
 163          /**加权递推平均滤波法**/
 164          /* coe数组为加权系数表,存在程序存储区。*/
 165          #undef N
 166          #define N 12  //设置FIFO队列的长度
 167          
 168          char code coe[N] = {1,2,3,4,5,6,7,8,9,10,11,12}; //加权系数
 169          char code sum_coe = 1+2+3+4+5+6+7+8+9+10+11+12;
 170          char filter_8()
 171          {
 172   1         char count; //采样数据读入的下标变量
 173   1         char value_buf[N]; //缓存N个采样值的存储变量
 174   1         int  sum=0; //求和变量,用于存储采样值的累加值
 175   1         for (count=0;count<N;count++)
 176   1         {
 177   2            value_buf[count] = get_ad(); //读入采样值
 178   2            delay();
 179   2         }
C51 COMPILER V7.06   MAIN                                                                  10/23/2006 20:25:38 PAGE 4   

 180   1         for (count=0;count<N;count++)
 181   1            sum += value_buf[count]*coe[count]; //累加采样值和系数的乘积
 182   1         return (char)(sum/sum_coe); //累加值与系数和相除作为返回结果
 183   1      }
 184          
 185          /**消抖滤波法**/
 186          #undef N
 187          #define N 12 //设置计数器溢出值
 188          char filter_9()
 189          {
 190   1         char count=0; //计数变量
 191   1         char new_value; //本次采样值变量
 192   1         new_value = get_ad(); //读入本次采样值
 193   1         while (value !=new_value);
 194   1         {
 195   2            count++; //计数器加1
 196   2            if (count>=N)   return new_value; //如果本次采样值与当前有效值不相等,
 197   2      //且计数器溢出,返回本次采样值
 198   2             delay();
 199   2            new_value = get_ad();
 200   2         }
 201   1         return value; //如果本次采样值与当前有效值相等,则返回当前有效值
 202   1      }
 203          
 204          
 205          /**限幅消抖滤波法**/
 206          
 207          /* A值可以根据实际情况调整,value为上次采样的有效值,new_value为当前采样值 */
 208          /* N为计数器的溢出值*/
 209          #undef A
 210          #undef N
 211          #define A 10 //设置两次采样允许的最大偏差值
 212          #define N 12 //设置计数器溢出值
 213          char value;  //有效值变量
 214          
 215          char filter_10()
 216          {
 217   1         char count=0; //计数变量
 218   1         char new_value; //本次采样值变量
 219   1         new_value = get_ad(); //读入本次采样值
 220   1              if((new_value-value>A)||(value-new_value>A)) //比较是否超出最大偏差值
 221   1                      new_value=value; //如果超出,返回有效值作为本次的采样有效值
 222   1         while (value !=new_value);
 223   1         {
 224   2            count++; //计数器加1
 225   2            if (count>=N)   return new_value; //如果本次采样值与当前有效值不相等,
 226   2                                                                                      //且计数器溢出,返回本次采样值
 227   2             delay();
 228   2            new_value = get_ad();
 229   2         }
 230   1         return value; //如果本次采样值与当前有效值相等,则返回当前有效值
 231   1      }
 232          
 233          
 234          
 235          
 236          
 237          
 238          
 239          
 240          
 241          
C51 COMPILER V7.06   MAIN                                                                  10/23/2006 20:25:38 PAGE 5   

 242          
 243          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    617    ----
   CONSTANT SIZE    =     13    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     15      37
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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