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

📄 f411_vr_dpcm.lst

📁 用c8051f410和FLASH(SPI接口)实现的数字录音机。
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.06   F411_VR_DPCM                                                          02/18/2009 16:30:49 PAGE 1   


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

stmt level    source

   1          //-----------------------------------------------------------------------------
   2          // F411_VR_DPCM.c
   3          //-----------------------------------------------------------------------------
   4          // Copyright 2006 Silicon Laboratories, Inc.
   5          // http://www.silabs.com
   6          //
   7          // Program Description:
   8          //
   9          // This file contains the DPCM encoding and decoding functions.
  10          //
  11          // NOTE: For another reference for DPCM, please see Chipcon's app note an026.
  12          //
  13          // NOTE: The calling function must have the same register context as the DCPM
  14          // functions, so it must either have the keyword "using 2" or all "using 2"
  15          // keywords for the DPCM functions need to be removed
  16          //
  17          // How To Use:    See Readme.txt
  18          //
  19          // FID:            41X000006
  20          // Target:         C8051F411
  21          // Tool chain:     Keil C51 7.50 / Keil EVAL C51
  22          //                 Silicon Laboratories IDE version 2.6
  23          // Project Name:   F411_VR
  24          //
  25          // Release 1.3
  26          //    -All changes by TP
  27          //    -02 Feb 2006
  28          //    -project version updated, no changes to this file
  29          //
  30          // Release 1.2
  31          //    -All changes by TP
  32          //    -21 Nov 2005
  33          //    -expanded the 4-bit codes to 6 bits for the 12-bit ADC
  34          //
  35          // Release 1.1
  36          //    -All changes by TP
  37          //    -16 Aug 2004
  38          //    -project version updated, no changes to this file
  39          //
  40          // Release 1.0
  41          //    -Initial Revision (TP)
  42          //    -15 AUG 2004
  43          //
  44          
  45          //-----------------------------------------------------------------------------
  46          // Includes
  47          //-----------------------------------------------------------------------------
  48          #include <c8051f410.h>                 // SFR declarations
  49          
  50          //-----------------------------------------------------------------------------
  51          // Global CONSTANTS
  52          //-----------------------------------------------------------------------------
  53          
  54          // 12-bit quantization codes (6 bits, so 64 codes total = 31 positive, 31
  55          // negative, and 2 zeroes)
C51 COMPILER V7.06   F411_VR_DPCM                                                          02/18/2009 16:30:49 PAGE 2   

  56          #define quant1       1
  57          #define quant2       2
  58          #define quant3       4
  59          #define quant4       7
  60          #define quant5       11
  61          #define quant6       16
  62          #define quant7       22
  63          #define quant8       29
  64          #define quant9       37
  65          #define quant10      46
  66          #define quant11      56
  67          #define quant12      67
  68          #define quant13      79
  69          #define quant14      92
  70          #define quant15      106
  71          #define quant16      130
  72          #define quant17      146
  73          #define quant18      163
  74          #define quant19      181
  75          #define quant20      200
  76          #define quant21      220
  77          #define quant22      241
  78          #define quant23      263
  79          #define quant24      286
  80          #define quant25      310
  81          #define quant26      335
  82          #define quant27      361
  83          #define quant28      388
  84          #define quant29      416
  85          #define quant30      512
  86          #define quant31      1024
  87          
  88          // the mapping from quantization values to dpcm codes (array index)
  89          xdata short Q_VALUES[64] = {0,               // 0
  90                                     -quant31,         // 1
  91                                     -quant30,         // 2
  92                                     -quant29,         // 3
  93                                     -quant28,         // 4
  94                                     -quant27,         // 5
  95                                     -quant26,         // 6
  96                                     -quant25,         // 7
  97                                     -quant24,         // 8
  98                                     -quant23,         // 9
  99                                     -quant22,         // 10
 100                                     -quant21,         // 11
 101                                     -quant20,         // 12
 102                                     -quant19,         // 13
 103                                     -quant18,         // 14
 104                                     -quant17,         // 15
 105                                     -quant16,         // 16 negative middle
 106                                     -quant15,         // 17
 107                                     -quant14,         // 18
 108                                     -quant13,         // 19
 109                                     -quant12,         // 20
 110                                     -quant11,         // 21
 111                                     -quant10,         // 22
 112                                     -quant9,          // 23
 113                                     -quant8,          // 24
 114                                     -quant7,          // 25
 115                                     -quant6,          // 26
 116                                     -quant5,          // 27
 117                                     -quant4,          // 28
C51 COMPILER V7.06   F411_VR_DPCM                                                          02/18/2009 16:30:49 PAGE 3   

 118                                     -quant3,          // 29
 119                                     -quant2,          // 30
 120                                     -quant1,          // 31
 121                                     0,                // 32
 122                                     quant1,           // 33
 123                                     quant2,           // 34
 124                                     quant3,           // 35
 125                                     quant4,           // 36
 126                                     quant5,           // 37
 127                                     quant6,           // 38
 128                                     quant7,           // 39
 129                                     quant8,           // 40
 130                                     quant9,           // 41
 131                                     quant10,          // 42
 132                                     quant11,          // 43
 133                                     quant12,          // 44
 134                                     quant13,          // 45
 135                                     quant14,          // 46
 136                                     quant15,          // 47
 137                                     quant16,          // 48 positive middle
 138                                     quant17,          // 49
 139                                     quant18,          // 50
 140                                     quant19,          // 51
 141                                     quant20,          // 52
 142                                     quant21,          // 53
 143                                     quant22,          // 54
 144                                     quant23,          // 55
 145                                     quant24,          // 56
 146                                     quant25,          // 57
 147                                     quant26,          // 58
 148                                     quant27,          // 59
 149                                     quant28,          // 60
 150                                     quant29,          // 61
 151                                     quant30,          // 62
 152                                     quant31};         // 63
 153          
 154          //-----------------------------------------------------------------------------
 155          // Function PROTOTYPES
 156          //-----------------------------------------------------------------------------
 157          unsigned char DPCM_Encode (short sample_diff);
 158          short DPCM_Decode (unsigned char dpcm_code);
 159          
 160          //-----------------------------------------------------------------------------
 161          // DPCM_Encode
 162          //-----------------------------------------------------------------------------
 163          //
 164          // Return Value :
 165          //   1)  char dpcm_code - the 6-bit quantized DPCM code
 166          //                      range is positive range of 6-bit value: 0 to 63
 167          // Parameters   :
 168          //   1)  short sample_diff - the difference between the predicted value and
 169          //                      the sample from the ADC
 170          //                      range is: -4096 to 4095 (difference of 12-bit values)
 171          //
 172          // Encode the sample using DPCM compression.
 173          //
 174          // The coding uses the following scheme (0 is unused) for an 8-bit sample:
 175          //
 176          // code:      1   2   3   4   5   6   7   8   9   10  11  12  13  14  15
 177          // q value: -64 -32 -16  -8  -4  -2  -1   0   1    2   4   8  16  32  64
 178          //
 179          // The difference will be rounded down if positive and rounded up if
C51 COMPILER V7.06   F411_VR_DPCM                                                          02/18/2009 16:30:49 PAGE 4   

 180          // negative (i.e. 41 => 32, and -41 => -32).
 181          //
 182          // NOTE: the calling function must have the same register context, so it must
 183          // either have the keyword "using 2" or all "using 2" keywords need to be
 184          // removed
 185          //
 186          unsigned char DPCM_Encode (short sample_diff) using 2
 187          {
 188   1         short sample_diff_us;
 189   1         unsigned char dpcm_code;
 190   1      
 191   1         // determine if the difference is positive or negative
 192   1         if (sample_diff < 0)
 193   1         {
 194   2            sample_diff_us = -sample_diff;   // use the absolute value
 195   2         }
 196   1         else
 197   1         {
 198   2            sample_diff_us = sample_diff;
 199   2         }
 200   1      
 201   1         // narrow down which bits need to be set to use the proper quantization code
 202   1         // using a binary search algorithm (divide in halves)
 203   1         // the sign of the difference no longer matters
 204   1      
 205   1         // first tier
 206   1         if (sample_diff_us >= quant16)
 207   1         {
 208   2            // second tier
 209   2            if (sample_diff_us >= quant24)
 210   2            {
 211   3               // third tier
 212   3               if (sample_diff_us >= quant28)
 213   3               {
 214   4                  // fourth tier
 215   4                  if (sample_diff_us >= quant30)
 216   4                  {
 217   5                     // fifth tier
 218   5                     if (sample_diff_us >= quant31)
 219   5                     {
 220   6                        dpcm_code = 63;
 221   6                     }
 222   5                     // fifth tier
 223   5                     else
 224   5                     {
 225   6                        dpcm_code = 62;
 226   6                     }
 227   5                  }
 228   4                  // fourth tier
 229   4                  else
 230   4                  {
 231   5                     // fifth tier
 232   5                     if (sample_diff_us >= quant29)
 233   5                     {
 234   6                        dpcm_code = 61;
 235   6                     }
 236   5                     // fifth tier
 237   5                     else
 238   5                     {
 239   6                        dpcm_code = 60;
 240   6                     }
 241   5                  }
C51 COMPILER V7.06   F411_VR_DPCM                                                          02/18/2009 16:30:49 PAGE 5   

 242   4               }
 243   3               // third tier
 244   3               else
 245   3               {
 246   4                  // fourth tier
 247   4                  if (sample_diff_us >= quant26)
 248   4                  {
 249   5                     // fifth tier
 250   5                     if (sample_diff_us >= quant27)
 251   5                     {
 252   6                        dpcm_code = 59;
 253   6                     }
 254   5                     // fifth tier
 255   5                     else
 256   5                     {
 257   6                        dpcm_code = 58;
 258   6                     }
 259   5                  }
 260   4                  // fourth tier
 261   4                  else
 262   4                  {
 263   5                     // fifth tier
 264   5                     if (sample_diff_us >= quant25)
 265   5                     {
 266   6                        dpcm_code = 57;
 267   6                     }

⌨️ 快捷键说明

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