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

📄 monitor.lst

📁 ADI公司的关于光通讯模块的监控程序,在KEIL FOR ARM 的编译环境编译.程序大小约12K,芯片是ADu7020.
💻 LST
📖 第 1 页 / 共 5 页
字号:
ARM COMPILER V2.32a,  monitor                                                              08/08/05  09:50:21  PAGE 1   


ARM COMPILER V2.32a, COMPILATION OF MODULE monitor
OBJECT MODULE PLACED IN monitor.OBJ
COMPILER INVOKED BY: C:\Keil\ARM\BIN\CA.exe monitor.c THUMB OPTIMIZE(0,SPEED) BROWSE DEBUG TABS(4) 

stmt  level    source

    1          // monitor.c
    2          
    3          /********************************************************************/
    4          /*                                                                  */
    5          /*      Monitor routines                                            */
    6          /*                                                                  */
    7          /********************************************************************/
    8          #include <ADuC7020.h>
    9          #include "common.h"
   10          #include <math.h>
   11          
   12          void monitor(void){
   13   1          
   14   1          #if DEBUG == 1
                   GP4SET = 0x00040000;
                   #endif   
   17   1      
   18   1          
   19   1          temp_monitor();
   20   1          voltage_monitor();
   21   1          tx_bias_monitor();
   22   1          tx_mod_monitor();
   23   1          tx_pow_monitor();
   24   1          rx_pow_monitor();
   25   1          
   26   1          #if DEBUG == 1
                   GP4CLR = 0x00040000;
                   #endif 
   29   1          
   30   1          }
   31          
   32          HALFWORD adc(BYTE adc_ch){
   33   1      
   34   1          BYTE cnt;
   35   1          HALFWORD adcread[4];
   36   1      
   37   1          ADCCP = adc_ch;
   38   1      
   39   1          for(cnt=0; cnt<4; cnt++){
   40   2              ADCCON = 0xA3;              // software start, single-end input
   41   2              while(!ADCSTA){}            // wait for end of conversion
   42   2              adcread[cnt]=(ADCDAT>>16);
   43   2          }
   44   1      
   45   1          // ADC bug fix
   46   1          if(adcread[3] > ADC_HIGH_MAX) adcread[3] = 0;    // limits a highest
   47   1      
   48   1          return adcread[3];
   49   1      
   50   1      }
   51          
   52          
   53          
   54          /********************************************************************/
   55          /*                                                                  */
   56          /*      Temperature Monitor                                         */
   57          /*                                                                  */
   58          /********************************************************************/
   59          void temp_monitor(void)
ARM COMPILER V2.32a,  monitor                                                              08/08/05  09:50:21  PAGE 2   

   60          {
   61   1          volatile HALFWORD adcread, sum=0, adcread_avr;
   62   1          volatile short delta, temp;
   63   1          volatile BYTE cnt;
   64   1          static HALFWORD buf[8] = {0x400,0x400,0x400,0x400,0x400,0x400,0x400,0x400};
   65   1          static BYTE p_buf=0;
   66   1      
   67   1          // secect ADC channel
   68   1          ADCCP = 0x10;                   // select internal temperature sensor
   69   1      
   70   1          // start AD conversion at ADC input channel 0x10
   71   1          adcread = adc(0x10);
   72   1      
   73   1          // averaging
   74   1          buf[p_buf] = adcread;
   75   1          p_buf++;
   76   1          p_buf &= 0x07;                  // reset ring-buffer pointer
   77   1          for(cnt=0; cnt<8; cnt++){
   78   2              sum += buf[cnt];
   79   2          }
   80   1          adcread_avr = sum>>3; 
   81   1           
   82   1          // delta[LSB] = Ref_ADCDAT[LSB] - ADCDAT[LSB]
   83   1          delta = (((REF_ADCDAT_MSB<<8) + REF_ADCDAT_LSB) - adcread_avr);
   84   1      
   85   1          // temperature[degC] = Ref_temperature[degC] + ((delta[LSB] * 610e-6 / 1.3mv) * 256)
   86   1          temp = ((REF_TEMP_MSB<<8) + REF_TEMP_LSB) + delta * T_SLOPE;
   87   1      
   88   1          // save data
   89   1          A2h[96] = (BYTE)(temp>>8);          // write high-byte
   90   1          A2h[97] = (BYTE)(temp & 0x00F0);    // write low-byte, fix low-order data at zero
   91   1      }
   92          
   93          /********************************************************************/
   94          /*                                                                  */
   95          /*      Power Supply Voltage Monitor                                */
   96          /*                                                                  */
   97          /********************************************************************/
   98          void voltage_monitor(void)
   99          {
  100   1          float volt;
  101   1          HALFWORD volt_res;
  102   1          HALFWORD i[2];
  103   1          BYTE cnt;
  104   1      
  105   1          // select ADC channel
  106   1          ADCCP = 0x00;                       // select ADC0 input channel
  107   1      
  108   1          // start A/D conversion
  109   1          for(cnt=0; cnt<2; cnt++){
  110   2          ADCCON = 0xA3;                      // software start, single-end input
  111   2          while (!ADCSTA){}                   // wait for end of conversion
  112   2          i[cnt] = (ADCDAT >> 16);
  113   2          }
  114   1      
  115   1          // Voltage = 2 * ADCDATA * 610uV / 100uV
  116   1          volt = 2 * i[1] * 610e-6 / 100e-6;
  117   1      
  118   1          //volt = 2 * (ADCDAT>>16) * 610e-6 / 100e-6;
  119   1          volt_res = (HALFWORD)volt;
  120   1      
  121   1          // save data
  122   1          A2h[98] = (BYTE)(volt_res>>8);          // write high-byte
  123   1          A2h[99] = (BYTE)(volt_res & 0x00F0);    // write low-byte, fix low-order data at zero
  124   1      }
  125          
ARM COMPILER V2.32a,  monitor                                                              08/08/05  09:50:21  PAGE 3   

  126          /********************************************************************/
  127          /*                                                                  */
  128          /*      TX Bias Current Monitor                                     */
  129          /*                                                                  */
  130          /********************************************************************/
  131          void tx_bias_monitor(void)
  132          {
  133   1          float bias;
  134   1          HALFWORD bias_res;
  135   1          HALFWORD i[4];
  136   1          BYTE cnt;
  137   1          static HALFWORD buf[8];
  138   1          static BYTE p_buf=0;
  139   1          HALFWORD dat=0;
  140   1      
  141   1          // select ADC channel
  142   1          ADCCP = 0x01;                       // select ADC1 input channel
  143   1      
  144   1          // start A/D conversion
  145   1          for(cnt=0; cnt<4; cnt++){
  146   2              ADCCON=0xA3;                    // software start, single-end input
  147   2            while(!ADCSTA){}                  // wait for end of conversion
  148   2              i[cnt]=(ADCDAT>>16);
  149   2          }
  150   1      
  151   1          // ADC bug fix
  152   1          if(i[3] > ADC_HIGH_MAX) i[3] = 0;    // limits a highest
  153   1      
  154   1          // averaging
  155   1          buf[p_buf] = i[3];
  156   1          p_buf++;
  157   1          p_buf &= 0x07;                      // reset ring-buffer pointer
  158   1          for(cnt=0; cnt<8; cnt++){
  159   2              dat += buf[cnt];
  160   2          }
  161   1          dat = dat>>3;                       // delta/8;
  162   1          
  163   1          // Ibias[A] = Ibmon[A] * 100
  164   1          // Ibmon[A] = ADCDATA * 610[uV] / 1000ohm
  165   1          bias = (dat * 610e-6 / 1e3) * 100;
  166   1      
  167   1          // Ibias[A] : 1LSB = 0.2[uA]
  168   1          bias /= 2e-6;
  169   1          bias_res = (HALFWORD)bias;
  170   1      
  171   1          // save data
  172   1          A2h[100] = (BYTE)(bias_res>>8);         // write high-byte
  173   1          A2h[101] = (BYTE)(bias_res & 0x00F0);   // write low-byte, fix low-order 4-bit at zero
  174   1      }
  175          
  176          /********************************************************************/
  177          /*                                                                  */
  178          /*      TX Modulation Current Monitor                               */
  179          /*                                                                  */
  180          /********************************************************************/
  181          void tx_mod_monitor(void)
  182          {
  183   1          float mod;
  184   1          HALFWORD mod_res;
  185   1          HALFWORD i[4];
  186   1          BYTE cnt;
  187   1          static HALFWORD buf[8];
  188   1          static BYTE p_buf=0;
  189   1          HALFWORD dat=0;
  190   1      
  191   1          // select ADC channel
ARM COMPILER V2.32a,  monitor                                                              08/08/05  09:50:21  PAGE 4   

  192   1          ADCCP = 0x02;                   // select ADC2 input channel
  193   1      
  194   1          // start A/D conversion
  195   1          for(cnt=0; cnt<4; cnt++){
  196   2              ADCCON=0xA3;                // software start, single-end input
  197   2              while(!ADCSTA){}            // wait for end of conversion
  198   2              i[cnt]=(ADCDAT>>16);
  199   2          }
  200   1      
  201   1          // ADC bug fix
  202   1          if(i[3] > ADC_HIGH_MAX) i[3] = 0;    // limits a highest
  203   1      
  204   1          // averaging
  205   1          buf[p_buf] = i[3];
  206   1          p_buf++;
  207   1          p_buf &= 0x07;                  // reset ring-buffer pointer
  208   1          for(cnt=0; cnt<8; cnt++){
  209   2              dat += buf[cnt];
  210   2          }
  211   1          dat = dat>>3;                   // delta/8;
  212   1          
  213   1          // Imod[A] = Immon[A] * 50
  214   1          // Immon[A] = ADCdat * 610e-6 / 470ohm
  215   1           mod = (dat * 610e-6 / 470) * 50;
  216   1      
  217   1          // Imod[A] : 1LSB = 0.2[uA]
  218   1          mod /= 2e-6;
  219   1          mod_res = (HALFWORD)mod;
  220   1      
  221   1          // save data
  222   1          TXMOD_MSB = (BYTE)(mod_res>>8);          // write high-byte
  223   1          TXMOD_LSB = (BYTE)(mod_res & 0x00F0);    // write low-byte, fix low-order 4-bit at zero
  224   1          // save raw adc data for ER compensation control
  225   1          TXMOD_RAWDAT_MSB = dat>>8;               // write high-byte
  226   1          TXMOD_RAWDAT_LSB = (dat & 0x00FF);
  227   1      
  228   1      }
  229          
  230          /********************************************************************/
  231          /*                                                                  */
  232          /*      TX Output Power Monitor                                     */
  233          /*                                                                  */
  234          /********************************************************************/
  235          void tx_pow_monitor(void)
  236          {
  237   1          float pow;
  238   1          HALFWORD pow_res;
  239   1          HALFWORD i[4];
  240   1          BYTE cnt;
  241   1          static HALFWORD buf[8];
  242   1          static BYTE p_buf=0;
  243   1          HALFWORD dat=0;
  244   1      
  245   1          // select ADC channel
  246   1          ADCCP = 0x0F;                   // ADC15 bufferred input
  247   1                                          // kernel update and 100pF on DAC3 required
  248   1      
  249   1      
  250   1          // start A/D conversion
  251   1          for(cnt=0; cnt<4; cnt++){
  252   2              ADCCON=0xA3;                // software start, single-end input
  253   2              while(!ADCSTA){}            // wait for end of conversion
  254   2              i[cnt]=(ADCDAT>>16);
  255   2          }
  256   1      
  257   1          // averaging
ARM COMPILER V2.32a,  monitor                                                              08/08/05  09:50:21  PAGE 5   

  258   1          buf[p_buf] = i[3];
  259   1          p_buf++;
  260   1          p_buf &= 0x07;                  // reset ring-buffer pointer
  261   1          for(cnt=0; cnt<8; cnt++){
  262   2              dat += buf[cnt];

⌨️ 快捷键说明

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