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

📄 adc0mode1.lst

📁 c8051f020温度采集程序,利用内部温度传感器进行温度采集
💻 LST
字号:
C51 COMPILER V7.00  ADC0MODE1                                                              04/11/2005 20:29:37 PAGE 1   


C51 COMPILER V7.00, COMPILATION OF MODULE ADC0MODE1
OBJECT MODULE PLACED IN ADC0mode1.OBJ
COMPILER INVOKED BY: E:\Keil\C51\BIN\c51.exe ADC0mode1.c DB OE

stmt level    source

   1          #include <c8051F020.h>
   2          #include <intrins.h>
   3          
   4          typedef unsigned char tByte;
   5          typedef unsigned int  tWord;
   6          typedef unsigned long tLong;
   7          
   8          sbit CS1=P3^6;
   9          #define SYSCLK                  11059200
  10          #define ADCFrequency   10000     //ADC frequency is 10K
  11          // Define Timer 0 reload values for ~1 msec delay
  12          #define PRELOAD01  (65536 - (unsigned int)(SYSCLK / (12 * 1000)))    
  13          #define PRELOAD01H (PRELOAD01 / 256)
  14          #define PRELOAD01L (PRELOAD01 % 256)
  15          
  16          sfr16 ADC0 = 0xbe;   //define 16 bits SFR for ADC0
  17          
  18          void SYSCLK_Init (void);
  19          void PORT_Init (void);
  20          void TIMER0_Init(void);
  21          void ADC0_Init(void);
  22          void LCD_Init(void);
  23          void LCD_Update(void);
  24          void Timer0update(void);
  25          void delay(void);
  26          void Delay_n_ms(unsigned int n);
  27          
  28          
  29          //grobal varibles
  30          tByte first = 0;
  31          tByte second = 0;
  32          tByte third = 0;
  33          tByte forth = 0;
  34          
  35          tWord temperature;
  36          tWord result;  //grobal variable ,the result of AD convertion
  37          
  38          //---------------************************-----------------//
  39          void main(void)
  40          { 
  41   1        tWord temp_int,temp_frac;
  42   1        tWord temp_differ;
  43   1        tByte i;
  44   1        tByte tempint,tempfrac;
  45   1        tWord temp[10];
  46   1        WDTCN = 0xde; 
  47   1        WDTCN = 0xad;                        // disable the Watchdog
  48   1        SYSCLK_Init ();                     // initialize oscillator
  49   1        PORT_Init ();                       // initialize crossbar and GPIO
  50   1        LCD_Init();                         //initialize the display of LCD
  51   1        TIMER0_Init();                      // initialize TIMER01
  52   1        ADC0_Init();
  53   1        EA=0;                            //disnable all interrupt
  54   1        AD0INT = 0;
  55   1        Delay_n_ms(1);
C51 COMPILER V7.00  ADC0MODE1                                                              04/11/2005 20:29:37 PAGE 2   

  56   1        AD0BUSY =1;                       //sample of the temperature of surrounding
  57   1        while(AD0INT == 0);
  58   1        temperature = ADC0&0x0FFF;
  59   1        for(i=0;i<5;i++) Delay_n_ms(60000);       //wait five minutes
  60   1        AD0INT = 0;
  61   1        AD0BUSY =1;
  62   1        while(AD0INT == 0);                  //sample the temperature of internal 
  63   1        temp_differ = (ADC0&0x0FFF) - temperature;    //obtain the differance between the temperature of surroun
             -ding and internal
  64   1        
  65   1        while(1)
  66   1          { 
  67   2                temperature = 0;
  68   2                for(i=0;i<10;i++)
  69   2                  {
  70   3                        AD0INT = 0;
  71   3                AD0BUSY =1;
  72   3                while(AD0INT == 0);                  //sample the temperature of internal 
  73   3                temp[i] = ADC0;
  74   3                        Delay_n_ms(1);
  75   3                        temperature += temp[i];
  76   3                       }
  77   2             temperature = temperature/10;
  78   2                 temperature = (temperature-temp_differ)- 2582;
  79   2                 temperature = (temperature*100)/9;
  80   2                 temp_int = temperature/100;
  81   2                 temp_frac = temperature - temp_int*100;
  82   2                 tempint = (unsigned char)temp_int;
  83   2                 tempfrac = (unsigned char)temp_frac;
  84   2                 forth = tempint/10;
  85   2                 third = tempint - forth*10;
  86   2                 second = tempfrac/10;
  87   2                 first = tempfrac - second*10;
  88   2                 LCD_Update();
  89   2                 Delay_n_ms(50);      
  90   2                 
  91   2               }
  92   1      }
  93          
  94          
  95          
  96          //--------***************************---------------------------//
  97          
  98          void SYSCLK_Init(void)
  99          {
 100   1          tWord n;
 101   1              OSCXCN = 0x67;  // EXTERNAL Oscillator Control Register
 102   1                              //use the Crystal Oscillator, Frequency is 11.0592MHz   
 103   1          for (n = 0; n < 255; n++) ;            // wait for osc to start
 104   1          while ( !(OSCXCN & 0x80));        // wait for xtal to stabilize
 105   1              OSCICN = 0x88;  // Internal Oscillator Control Register
 106   1                              //disable the Internal Oscillator, enable the Oscillator Checker
 107   1      }
 108          
 109          void PORT_Init(void)
 110          {
 111   1              XBR0 = 0x00;    // XBAR0: Initial Reset Value
 112   1              XBR1 = 0x00;    // XBAR1: Initial Reset Value
 113   1              XBR2 = 0x40;    // XBAR2:  Enable crossbar
 114   1              //P0~P3 only are GPIO ports
 115   1              P0MDOUT = 0x00; // Output configuration for P0 
 116   1          P1MDOUT = 0x00; // Output configuration for P1 
C51 COMPILER V7.00  ADC0MODE1                                                              04/11/2005 20:29:37 PAGE 3   

 117   1          P2MDOUT = 0x00; // Output configuration for P2 
 118   1          P3MDOUT = 0x00; // Output configuration for P3 
 119   1          P74OUT = 0x00;  // Output configuration for P4-7
 120   1              //every pin of P0~P7 is Open-Drain Output/Input(Digital)
 121   1          P1MDIN = 0xFF;  // Input configuration for P1    
 122   1      }
 123          
 124          void ADC0_Init(void)
 125          {
 126   1        REF0CN = 0x03;     //tempture sensor opened, Internal VREF enable 
 127   1        AMX0CF = 0x00;        // AMUX Configuration Register
 128   1        AMX0SL = 0x02;        // AMUX Channel Select Register //  select temp sensor
 129   1        ADC0CF = 0x48;        // ADC Configuration Register  //10 sysclk; PGA is 2
 130   1        ADC0CN = 0x80;        // ADC Control Register  //enable ADC0, start source of ADC is AD0BUSY
 131   1       
 132   1      }
 133          
 134          void TIMER0_Init(void)
 135          {
 136   1          TMOD = 0x01;    // Timer Mode Register 
 137   1              TH0=PRELOAD01H;
 138   1          TL0=PRELOAD01L;
 139   1              TR0 =0;
 140   1      }
 141          
 142          void LCD_Init(void)   //LCD display "0000"
 143          {
 144   1        P3 = 0x00;
 145   1        CS1 = 1;
 146   1        delay();
 147   1        CS1 = 0;
 148   1        P3 = 0x10;
 149   1        CS1 = 1;
 150   1        delay();
 151   1        CS1 = 0;
 152   1        P3 = 0x20;
 153   1        CS1 = 1;
 154   1        delay();
 155   1        CS1 = 0;
 156   1        P3 = 0x30;
 157   1        CS1 = 1;
 158   1        delay();
 159   1        CS1 = 0;
 160   1      }
 161          
 162          
 163          void LCD_Update(void)
 164          {
 165   1           P3 = (0x00|first);
 166   1           CS1=1;
 167   1           delay();
 168   1           CS1=0;
 169   1           P3 = (0x10|second);
 170   1           CS1=1;
 171   1               delay();
 172   1           CS1=0;
 173   1           P3 = (0x20|third);
 174   1           CS1=1;
 175   1               delay();
 176   1           CS1=0;
 177   1           P3 = (0x30|forth);
 178   1           CS1=1;
C51 COMPILER V7.00  ADC0MODE1                                                              04/11/2005 20:29:37 PAGE 4   

 179   1               delay();
 180   1           CS1=0;    
 181   1      } 
 182          
 183          
 184          void Timer0update(void)
 185          {
 186   1        TF0=0;
 187   1        TR0=0;
 188   1        TH0=PRELOAD01H;
 189   1        TL0=PRELOAD01L;
 190   1      }
 191          
 192          void Delay_n_ms(unsigned int n)
 193          {
 194   1        while(n--)
 195   1        {
 196   2          TR0=1;
 197   2              while(TF0==0);
 198   2              Timer0update();
 199   2        }
 200   1      }
 201          
 202          void delay(void)
 203           {
 204   1        _nop_();
 205   1        _nop_();
 206   1      
 207   1       }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    481    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      8      29
   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 + -