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

📄 adc2.lst

📁 Cygnal公司的著名产品C8051f系列单片机
💻 LST
字号:
C51 COMPILER V7.01  ADC2                                                                   05/04/2004 11:25:47 PAGE 1   


C51 COMPILER V7.01, COMPILATION OF MODULE ADC2
OBJECT MODULE PLACED IN ADC2.OBJ
COMPILER INVOKED BY: C:\keil7\C51\BIN\C51.EXE ADC2.c DB OE

stmt level    source

   1          /////////ADC2调试程序,p1.2口单端输入/////////////////
   2          /////////T2定时采样,ADC2监控中断/////////////////////
   3          /////////ADC2.c////////////////////////////////////////
   4          #include "lcd.h"
*** WARNING C258 IN LINE 29 OF LCD.H: 'num': mspace on parameter ignored
*** WARNING C258 IN LINE 29 OF LCD.H: 'line': mspace on parameter ignored
*** WARNING C258 IN LINE 30 OF LCD.H: 'num': mspace on parameter ignored
*** WARNING C258 IN LINE 30 OF LCD.H: 'str': mspace on parameter ignored
*** WARNING C258 IN LINE 31 OF LCD.H: 'inum': mspace on parameter ignored
*** WARNING C258 IN LINE 39 OF LCD.H: 'num': mspace on parameter ignored
*** WARNING C258 IN LINE 39 OF LCD.H: 'fbit': mspace on parameter ignored
*** WARNING C258 IN LINE 39 OF LCD.H: 'line': mspace on parameter ignored
*** WARNING C235 IN LINE 48 OF LCD.H: parameter 1: different types
*** WARNING C258 IN LINE 126 OF LCD.H: 'inum': mspace on parameter ignored
*** WARNING C258 IN LINE 207 OF LCD.H: 'num': mspace on parameter ignored
*** WARNING C258 IN LINE 207 OF LCD.H: 'fbit': mspace on parameter ignored
*** WARNING C258 IN LINE 207 OF LCD.H: 'line': mspace on parameter ignored
*** WARNING C258 IN LINE 212 OF LCD.H: 'num': mspace on parameter ignored
*** WARNING C258 IN LINE 212 OF LCD.H: 'line': mspace on parameter ignored
*** WARNING C258 IN LINE 216 OF LCD.H: 'inum': mspace on parameter ignored
*** WARNING C258 IN LINE 216 OF LCD.H: 'str': mspace on parameter ignored
*** WARNING C258 IN LINE 216 OF LCD.H: 'page': mspace on parameter ignored
*** WARNING C236 IN LINE 216 OF LCD.H: '_showintmes': different length of parameter lists
   5          #define ADC0START temppage=SFRPAGE;SFRPAGE=0x00;AD0BUSY=1;SFRPAGE=temppage
   6          #define ADJRATEDIF 260L
   7          #define ADJRATESE 130L
   8          sfr16 RCAP2=0xca;
   9          sfr16 RCAP3=0xca;
  10          sfr16 RCAP4=0xca;
  11          sfr16 TMR4=0xcc;
  12          sfr16 TMR3=0xcc;
  13          sfr16 TMR2=0xcc;
  14          sfr16 PCA0CP0=0xfb;
  15          sfr16 PCA0CP1=0xfd;
  16          sfr16 PCA0CP2=0xe9;
  17          sfr16 PCA0CP3=0xeb;
  18          sfr16 PCA0CP4=0xed;
  19          sfr16 PCA0CP5=0xe1;
  20          sfr16 ADC0VAL=0xbe;
  21          sfr16 ADC0GT=0xc4;
  22          sfr16 ADC0LT=0xc6;
  23          uchar temppage;
  24          bit isnewdata;
  25          bit adc_is_capture;
  26          uchar kk;
  27          long realvol;
  28          void adc2_mux(uchar type,uchar source);
  29          void adc2_source(uchar source);
  30          void anologPort_ini(uchar port);
  31          void adc2_ini();
  32          void config();
  33          void t2_ini();
  34          void t2_baud(uint t2reload);
  35          void t2_ini(){
  36   1              SFRPAGE = 0x00;
C51 COMPILER V7.01  ADC2                                                                   05/04/2004 11:25:47 PAGE 2   

  37   1              TMR2CF = 0x08;  // T2时钟为系统时钟
  38   1              TMR2CN = 0x04;  // 开启T2定时器
  39   1      }
  40          void t2_baud(uint t2reload){
  41   1              SFRPAGE = 0x00;
  42   1              RCAP2=~t2reload+1;
  43   1              TMR2=RCAP2;
  44   1      }
  45          void adc2_mux(uchar type,uchar source){//type 配置测量方式为差动还是单端输入
  46   1      //source 为ADC2通道选择(共有8个通道)
  47   1              SFRPAGE=0x02;
  48   1              AMX2CF=type;
  49   1              AMX2SL=source;
  50   1      }
  51          void adc2_source(uchar source){//ADC2通道选择
  52   1              SFRPAGE=0x02;
  53   1              AMX2SL=source;
  54   1      }
  55          void anologPort_ini(uchar port){//配置p1口模拟输入管脚
  56   1              SFRPAGE=0x0f;
  57   1              P1MDIN&=~port;//将相应管脚配置成模拟输入口
  58   1      }
  59          void adc2_ini(){
  60   1              SFRPAGE=0x02;
  61   1              ADC2CF=0x09;//ADC2时钟为系统时钟2分频,PGA增益为1
  62   1              ADC2CN=0x86;//AD2TM=0,ADC2为连续跟踪模式由T2溢出率启动ADC2
  63   1              SFRPAGE=0x00;
  64   1              REF0CN|=0x0b;//采用AV+作为参考电压
  65   1              /*BIASE=1,偏移产生器工作,注意若AD启动此位必须置1,不管是否采用内部参考电平
  66   1              REFBE=1,内部参考电平工作,电路部分须将VREF参考输出(C8051F40的第12管脚)与
  67   1              VREF2(C8051F040的17管脚)相连,并最好并联一个4.7uF和0.1uF的旁路电容以电平滤波*/
  68   1              anologPort_ini(0x0f);//将P1.0-P1.3配置到AMUX2  0-3通道上,pdf文件上p2是错误的。
  69   1              adc2_mux(0x01,2);
  70   1              /* 0,1通道为差动输入模式,其他为单端输入模式,选择2通道单端输入进入AD转化*/
  71   1              EIE2|= 0x08;        //开ADC2中断
  72   1              t2_ini();
  73   1              t2_baud(6000);//设置6000个T2时钟为采样周期
  74   1              SFRPAGE=0x00;
  75   1              TR2=1;
  76   1      }
  77          void adc2_capture(uchar greater,uchar less){
  78   1              SFRPAGE=0x02;
  79   1              ADC2GT=greater;
  80   1              ADC2LT=less;
  81   1              AD2WINT=0;
  82   1              EIE2|=0x10;
  83   1      }
  84          void config (void) {
  85   1      //看门狗禁止
  86   1          WDTCN = 0x07;       
  87   1          WDTCN = 0xDE;   
  88   1          WDTCN = 0xAD;
  89   1          SFRPAGE = 0x0F;
  90   1          XBR0 = 0x00;        
  91   1          XBR1 = 0x00;        
  92   1          XBR2 = 0x40;        //交叉开关使能,使得P0-P3口能输出
  93   1          XBR3 = 0x00;    
  94   1          SFRPAGE = 0x0F;
  95   1          P0MDOUT = 0x00; //端口配置,P0-P3,P6-P7口为开漏输出
  96   1          P1MDOUT = 0x00; 
  97   1          P2MDOUT = 0x00; 
  98   1          P3MDOUT = 0x00; 
C51 COMPILER V7.01  ADC2                                                                   05/04/2004 11:25:47 PAGE 3   

  99   1          P4MDOUT = 0x00; //P4口为开漏,若为推挽式则无法读取LCD数据
 100   1          P5MDOUT = 0x07; 
 101   1          P6MDOUT = 0x00; 
 102   1          P7MDOUT = 0x00; 
 103   1          P1MDIN = 0xFF;  //所有端口为数字输入,没有模拟输入端口
 104   1          P2MDIN = 0xFF;  
 105   1          P3MDIN = 0xFF; 
 106   1          SFRPAGE = 0x0F;
 107   1          CLKSEL = 0x00;  
 108   1          OSCXCN = 0x00;      
 109   1          OSCICN = 0x84;      
 110   1          //采用内部晶振,为24.5MHZ8分频
 111   1      }  
 112          void main(){
 113   1              uchar i;
 114   1              config();
 115   1              dispini();
 116   1              adc2_ini();
 117   1              i=0;
 118   1              kk=0;
 119   1              isnewdata=0;
 120   1              adc_is_capture=0;
 121   1              adc2_capture(64,128);//当电压在0.83-1.65之内发生ADC2中断
 122   1              EA=1;
 123   1              while(1){
 124   2                      if(isnewdata){
 125   3                              i++;
 126   3                              if(i>40){
 127   4                                      i=0;
 128   4                                      showline("AIN1.2 VAL",0);
 129   4                                      showf(realvol,4,1);
 130   4                                      }
 131   3                              isnewdata=0;
 132   3                      }
 133   2                      if(adc_is_capture){ //ADC2监控条件测试
 134   3                              adc_is_capture=0;
 135   3                              showline("ADC2 CAPTURE",0);
 136   3                              showf(realvol,4,1);
 137   3                              delay1ms(100);
 138   3                              EIE2|=0x10;//开ADC2监控中断
 139   3      
 140   3                              }
 141   2              }
 142   1      }
 143          
 144          void ADC2_WIN_ISR() interrupt 17{//ADC2监控中断程序
 145   1      //只要ADC转化值在此监视范围内,则一直处于此中断
 146   1              adc_is_capture=1;
 147   1              SFRPAGE=0x02;
 148   1              AD2WINT=0;
 149   1              EIE2&=~0x10;//关ADC2监控中断
 150   1      /*
 151   1      注意c8051f040.h头文件定义错误
 152   1      原定义为:
 153   1      sbit AD2WINT = ADC2CN ^ 3;         
 154   1      sbit AD2CM2  = ADC2CN ^ 2;         
 155   1      sbit AD2CM1  = ADC2CN ^ 1;         
 156   1      sbit AD2CM0  = ADC2CN ^ 0;   
 157   1      改为:
 158   1      sbit AD2WINT = ADC2CN ^ 0;         
 159   1      sbit AD2CM2  = ADC2CN ^ 3;         
 160   1      sbit AD2CM1  = ADC2CN ^ 2;         
C51 COMPILER V7.01  ADC2                                                                   05/04/2004 11:25:47 PAGE 4   

 161   1      sbit AD2CM0  = ADC2CN ^ 1;         
 162   1      */
 163   1              
 164   1      }
 165          void ADC2_ISR() interrupt 18{//ADC2转化完毕中断程序
 166   1              AD2INT=0;
 167   1              kk=ADC2;
 168   1              realvol=(long)kk;
 169   1              realvol*=ADJRATESE;//realvol为真实电压值的1.0e4倍
 170   1              isnewdata=1;
 171   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   3038    ----
   CONSTANT SIZE    =     87    ----
   XDATA SIZE       =     32       4
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      6      40
   IDATA SIZE       =   ----      11
   BIT SIZE         =      2       6
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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