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

📄 t2cal31x.lst

📁 C8051F310单片机应用程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   T2CAL31X                                                              06/09/2006 10:47:26 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE T2CAL31X
OBJECT MODULE PLACED IN T2Cal31x.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\c51.exe T2Cal31x.c DB OE

line level    source

   1          //-----------------------------------------------------------------------------
   2          // T2Cal31x.c
   3          //-----------------------------------------------------------------------------
   4          // Copyright (C) 2004 Silicon Laboratories, Inc.
   5          //
   6          // AUTH: PD
   7          // DATE: 24 OCT 02
   8          //
   9          // This program is used to measure the temperature sensor on an 'F31x
  10          // device.  It uses 1-point calibration and stores the offset value
  11          // in FLASH memory.  The program outputs temperature values in 100ths
  12          // of a degree Celsius with UART.
  13          // Target: C8051F31x
  14          // Tool chain: KEIL C51 6.03 / KEIL EVAL C51
  15          //
  16          
  17          //-----------------------------------------------------------------------------
  18          // Includes
  19          //-----------------------------------------------------------------------------
  20          
  21          #include <c8051f310.h>                 // SFR declarations
  22          #include <intrins.h>
  23          #include <stdio.h>
  24          
  25          //-----------------------------------------------------------------------------
  26          // 16-bit SFR Definitions for 'F31x
  27          //-----------------------------------------------------------------------------
  28          
  29          sfr16 DP       = 0x82;                 // data pointer
  30          sfr16 TMR2RL   = 0xca;                 // Timer2 reload value
  31          sfr16 TMR2     = 0xcc;                 // Timer2 counter
  32          sfr16 TMR3     = 0x94;                 // Timer3 counter
  33          sfr16 TMR3RL   = 0x92;                 // Timer3 reload value
  34          sfr16 PCA0CP0  = 0xfb;                 // PCA0 Module 0 Capture/Compare
  35          sfr16 PCA0CP1  = 0xe9;                 // PCA0 Module 1 Capture/Compare
  36          sfr16 PCA0CP2  = 0xeb;                 // PCA0 Module 2 Capture/Compare
  37          sfr16 PCA0CP3  = 0xed;                 // PCA0 Module 3 Capture/Compare
  38          sfr16 PCA0CP4  = 0xfd;                 // PCA0 Module 4 Capture/Compare
  39          sfr16 PCA0     = 0xf9;                 // PCA0 counter
  40          sfr16 ADC0     = 0xbd;                 // ADC Data Word Register
  41          sfr16 ADC0GT   = 0xc3;                 // ADC0 Greater-Than
  42          sfr16 ADC0LT   = 0xc5;                 // ADC0 Less-Than
  43          //-----------------------------------------------------------------------------
  44          // Temperature Sensor Calibration PARAMETERS
  45          //-----------------------------------------------------------------------------
  46          
  47          //-----------------------------------------------------------------------------
  48          // Global CONSTANTS
  49          //-----------------------------------------------------------------------------
  50          
  51          #define SYSCLK      24500000           // SYSCLK frequency in Hz
  52          #define BAUDRATE        9600           // Baud rate of UART in bps
  53          #define TIMER2_RATE     1000           // Timer 2 overflow rate in Hz
  54          
  55          
C51 COMPILER V7.50   T2CAL31X                                                              06/09/2006 10:47:26 PAGE 2   

  56          sbit LED = P3^3;                       // LED='1' means ON
  57          //-----------------------------------------------------------------------------
  58          // Temperature Sensor Calibration PARAMETERS
  59          //-----------------------------------------------------------------------------
  60          #define AMB_TEMP           25          // Ambient Calibration Temperature 
  61                                                 // (degC)
  62          
  63          #define TEMP_SENSOR_GAIN   3300        // Temp Sensor Gain in (uV / degC)
  64          
  65          #define VREF               3300        // ADC Voltage Reference (mV)
  66          
  67          #define SOAK_TIME          15          // Soak Time in Seconds
  68          
  69          
  70          //-----------------------------------------------------------------------------
  71          // Global VARIABLES
  72          //-----------------------------------------------------------------------------
  73          
  74          // TEMP_OFFSET allocates two bytes of code memory space in FLASH
  75          // that will be used to store the calibrated temperature value
  76          unsigned int code TEMP_OFFSET = 0xFFFF;
  77          
  78          //-----------------------------------------------------------------------------
  79          // Function PROTOTYPES
  80          //-----------------------------------------------------------------------------
  81          
  82          void SYSCLK_Init (void);
  83          void ADC0_Init (void);
  84          void UART0_Init (void);
  85          void PORT_Init (void);
  86          void Timer2_Init (int);
  87          void Write_CHAR(unsigned char yjchar);
  88          void YJ_Init(void);
  89          
  90          int get_temp (void);
  91          void calibrate(void);
  92          unsigned int measure(void);
  93          void wait_one_second (void);
  94          unsigned char xdata NCDdata[6]={0x30,0x30,0x30,0x2e,0x30,0x30};
  95          
  96          //-----------------------------------------------------------------------------
  97          // MAIN Routine
  98          //-----------------------------------------------------------------------------
  99          
 100          void main (void) {
 101   1      
 102   1         unsigned temperature;
 103   1         int i;
 104   1         int temp_int, temp_frac;
 105   1         // Disable Watchdog timer
 106   1         PCA0MD &= ~0x40;                    // WDTE = 0 (clear watchdog timer 
 107   1                                             // enable)
 108   1         PORT_Init();                        // Initialize Port I/O
 109   1         SYSCLK_Init ();                     // Initialize Oscillator
 110   1      
 111   1         ADC0_Init ();                       // Init ADC0
 112   1         Timer2_Init(SYSCLK/TIMER2_RATE);    // Init Timer 2 
 113   1         UART0_Init();
 114   1      
 115   1         AD0EN = 1;                          // Enable ADC0
 116   1      
 117   1         if (TEMP_OFFSET == 0xFFFF) {        // TRUE if first-time to execute
C51 COMPILER V7.50   T2CAL31X                                                              06/09/2006 10:47:26 PAGE 3   

 118   2            printf ("Calibrating...\n");
 119   2            calibrate ();                    // execute calibration sequence
 120   2         } else {
 121   2            printf ("Not calibrating.\n");
 122   2         }
 123   1      
 124   1         while (1) {
 125   2            // example of how to read the temperature
 126   2                 PORT_Init(); 
 127   2            LED = 1;
 128   2            temperature = get_temp ();
 129   2            LED = 0;
 130   2                temp_int = temperature / 100;
 131   2            temp_frac = temperature - (temp_int * 100);
 132   2            printf ("Temperature = %+02d hundredths degrees C\n", temperature);
 133   2      
 134   2      
 135   2                NCDdata[0]=temp_int/100+0x30;NCDdata[1]=(temp_int%100)/10+0x30;NCDdata[2]=(temp_int%100)%10+0x30;
 136   2                NCDdata[4]=temp_frac/10+0x30;NCDdata[5]=temp_frac%10+0x30;
 137   2            YJ_Init();
 138   2                for(i=0;i<6;i++)
 139   2                {
 140   3               Write_CHAR(NCDdata[i]);}
 141   2         }
 142   1      }
 143          
 144          //-----------------------------------------------------------------------------
 145          // Initialization Subroutines
 146          //-----------------------------------------------------------------------------
 147          
 148          //-----------------------------------------------------------------------------
 149          // PORT_Init
 150          //-----------------------------------------------------------------------------
 151          //
 152          // Configure the Crossbar and GPIO ports.
 153          //
 154          // P0.4 - UART TX
 155          // P0.5 - UART RX
 156          // P3.3 - LED
 157          
 158          void PORT_Init (void)
 159          {
 160   1         XBR0    = 0x01;                     // Enable UART on P0.4(RX) and P0.5(TX)                     
 161   1         XBR1    = 0x40;                     // Enable crossbar and enable 
 162   1                                             // weak pull-ups
 163   1         P0MDOUT |= 0x10;                    // enable UTX as push-pull output
 164   1         P3MDOUT |= 0x08;                    // enable LED as push-pull output
 165   1      }
 166          
 167          //-----------------------------------------------------------------------------
 168          // SYSCLK_Init
 169          //-----------------------------------------------------------------------------
 170          //
 171          // This routine initializes the system clock to use the internal oscillator
 172          // at its maximum frequency.
 173          // Also enables the Missing Clock Detector.
 174          //
 175          
 176          void SYSCLK_Init (void)
 177          {
 178   1         OSCICN |= 0x03;                     // Configure internal oscillator for
 179   1                                             // its maximum frequency
C51 COMPILER V7.50   T2CAL31X                                                              06/09/2006 10:47:26 PAGE 4   

 180   1         RSTSRC = 0x04;                      // Enable missing clock detector
 181   1      
 182   1      }
 183          
 184          //-----------------------------------------------------------------------------
 185          // ADC0_Init ADBUSY, LP tracking, no Interrupt, ADC disabled
 186          //-----------------------------------------------------------------------------
 187          //
 188          // Configure ADC0 to use ADBUSY as conversion source, and to sense the output 
 189          // of the temp sensor.  Disables ADC end of conversion interrupt. Leaves ADC 
 190          // disabled.
 191          //
 192          void ADC0_Init (void)
 193          {
 194   1         ADC0CN = 0x40;                      // ADC0 disabled; LP tracking
 195   1                                             // mode; ADC0 conversions are initiated 
 196   1                                             // on a write to ADBusy
 197   1         AMX0P  = 0x1E;                      // Temp sensor selected at + input
 198   1         AMX0N  = 0x1F;                      // Single-ended mode
 199   1      
 200   1         ADC0CF = (SYSCLK/3000000) << 3;     // ADC conversion clock <= 3MHz   
 201   1      
 202   1         ADC0CF &= ~0x04;                    // Make ADC0 right-justified
 203   1         REF0CN = 0x0e;                      // enable temp sensor, VREF = VDD, bias
 204   1                                             // generator is on.
 205   1      
 206   1         EIE1 &= ~0x08;                      // Disable ADC0 EOC interrupt
 207   1      }
 208          
 209          //-----------------------------------------------------------------------------
 210          // UART0_Init

⌨️ 快捷键说明

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