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

📄 temp_3.lst

📁 工业以太网测控板资料FX04核心编程模块
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.02   TEMP_3                                                                03/14/2008 17:50:21 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE TEMP_3
OBJECT MODULE PLACED IN Temp_3.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\c51.exe Temp_3.c DB OE

line level    source

   1          //-----------------------------------------------------------------------------
   2          // Includes
   3          //-----------------------------------------------------------------------------
   4          
   5          #include <c8051f040.h>                 // SFR declarations
   6          #include <stdio.h>
   7          
   8          //-----------------------------------------------------------------------------
   9          // 16-bit SFR Definitions for 'F04x
  10          //-----------------------------------------------------------------------------
  11          
  12          sfr16 DP       = 0x82;                 // data pointer
  13          sfr16 RCAP2    = 0xCA;                 // Timer2 reload/capture value
  14          sfr16 RCAP3    = 0xCA;                 // Timer3 reload/capture value
  15          sfr16 RCAP4    = 0xCA;                 // Timer4 reload/capture value
  16          sfr16 TMR2     = 0xCC;                 // Timer2 counter/timer
  17          sfr16 TMR3     = 0xCC;                 // Timer3 counter/timer
  18          sfr16 TMR4     = 0xCC;                 // Timer4 counter/timer
  19          sfr16 ADC0     = 0xBE;                 // ADC0 data
  20          sfr16 ADC0GT   = 0xC4;                 // ADC0 greater than window
  21          sfr16 ADC0LT   = 0xC6;                 // ADC0 less than window
  22          sfr16 DAC0     = 0xD2;                 // DAC0 data
  23          sfr16 DAC1     = 0xD2;                 // DAC1 data
  24          sfr16 CAN0DAT  = 0xD8;                 // CAN data window
  25          
  26          //-----------------------------------------------------------------------------
  27          // Global CONSTANTS
  28          //-----------------------------------------------------------------------------
  29          
  30          #define BAUDRATE     115200            // Baud rate of UART in bps
  31          #define SYSCLK       24500000          // Internal oscillator frequency in Hz
  32          #define SAMPLE_RATE  50000             // Sample frequency in Hz
  33          #define INT_DEC      256               // integrate and decimate ratio
  34          
  35          sbit LED = P1^6;                       // LED='1' means ON
  36          sbit SW1 = P3^7;                       // SW1='0' means switch pressed
  37          
  38          //-----------------------------------------------------------------------------
  39          // Function PROTOTYPES
  40          //-----------------------------------------------------------------------------
  41          
  42          void SYSCLK_Init (void);
  43          void PORT_Init (void);
  44          void UART1_Init (void);
  45          void ADC0_Init (void);
  46          void Timer3_Init (int counts);
  47          void ADC0_ISR (void);
  48          void wait_ms (int ms);
  49          //-----------------------------------------------------------------------------
  50          // Global VARIABLES
  51          //-----------------------------------------------------------------------------
  52          
  53          long result;                           // ADC0 decimated value
  54          
  55          //-----------------------------------------------------------------------------
C51 COMPILER V8.02   TEMP_3                                                                03/14/2008 17:50:21 PAGE 2   

  56          // MAIN Routine
  57          //-----------------------------------------------------------------------------
  58          
  59          void main (void) {
  60   1         long temperature;                   // temperature in hundredths of a
  61   1                                             // degree C
  62   1         int temp_int, temp_frac;            // integer and fractional portions of
  63   1                                             // temperature
  64   1      
  65   1         WDTCN = 0xde;                       // disable watchdog timer
  66   1         WDTCN = 0xad;
  67   1      
  68   1         SYSCLK_Init ();                     // initialize oscillator
  69   1         PORT_Init ();                       // initialize crossbar and GPIO
  70   1         UART1_Init ();                      // initialize UART1
  71   1         Timer3_Init (SYSCLK/SAMPLE_RATE);   // initialize Timer3 to overflow at
  72   1                                             // sample rate
  73   1      
  74   1         ADC0_Init ();                       // init ADC
  75   1      
  76   1         SFRPAGE = ADC0_PAGE;
  77   1         AD0EN = 1;                          // enable ADC
  78   1      
  79   1         EA = 1;                             // Enable global interrupts
  80   1      
  81   1         while (1) {
  82   2            EA = 0;                          // disable interrupts
  83   2            temperature = result;
  84   2            EA = 1;                          // re-enable interrupts
  85   2      
  86   2            // calculate temperature in hundredths of a degree
  87   2            temperature = temperature - 42380;
  88   2            temperature = (temperature * 100L) / 156;
  89   2            temp_int = temperature / 100;
  90   2            temp_frac = temperature - (temp_int * 100);
  91   2      
  92   2            SFRPAGE = UART1_PAGE;
  93   2            printf ("Temperature is %+02d.%02d\n", temp_int, temp_frac);
  94   2      
  95   2            SFRPAGE = CONFIG_PAGE;
  96   2            LED = ~SW1;                      // LED reflects state of switch
  97   2      
  98   2            wait_ms(50);                     // wait 50 milliseconds
  99   2         }
 100   1      }
 101          
 102          //-----------------------------------------------------------------------------
 103          // Support Subroutines
 104          //-----------------------------------------------------------------------------
 105          
 106          //-----------------------------------------------------------------------------
 107          // wait_ms
 108          //-----------------------------------------------------------------------------
 109          //
 110          // This routine inserts a delay of <ms> milliseconds.
 111          //
 112          void wait_ms (int ms)
 113          {
 114   1         char SFRPAGE_SAVE = SFRPAGE;        // Save Current SFR page
 115   1      
 116   1         SFRPAGE = TMR2_PAGE;
 117   1      
C51 COMPILER V8.02   TEMP_3                                                                03/14/2008 17:50:21 PAGE 3   

 118   1         TMR2CN = 0x00;                      // Stop Timer3; Clear TF3;
 119   1         TMR2CF = 0x00;                      // use SYSCLK/12 as timebase
 120   1      
 121   1         RCAP2 = -(SYSCLK/1000/12);          // Timer 2 overflows at 1 kHz
 122   1         TMR2 = RCAP2;
 123   1      
 124   1         ET2 = 0;                            // Disable Timer 2 interrupts
 125   1      
 126   1         TR2 = 1;                            // Start Timer 2
 127   1      
 128   1         while(ms){
 129   2            TF2 = 0;
 130   2            while(!TF2);                     // wait until timer overflows
 131   2            ms--;                            // decrement ms
 132   2         }
 133   1      
 134   1         TR2 = 0;                            // Stop Timer 2
 135   1      
 136   1         SFRPAGE = SFRPAGE_SAVE;             // Restore SFRPAGE
 137   1      }
 138          
 139          //-----------------------------------------------------------------------------
 140          // Initialization Subroutines
 141          //-----------------------------------------------------------------------------
 142          
 143          //-----------------------------------------------------------------------------
 144          // SYSCLK_Init
 145          //-----------------------------------------------------------------------------
 146          //
 147          // This routine initializes the system clock to use the internal oscillator
 148          // at 24.5 MHz.
 149          //
 150          void SYSCLK_Init (void)
 151          {
 152   1         char SFRPAGE_SAVE = SFRPAGE;        // Save Current SFR page
 153   1      
 154   1         SFRPAGE = CONFIG_PAGE;              // set SFR page
 155   1      
 156   1         OSCICN = 0x83;                      // set internal oscillator to run
 157   1                                             // at its maximum frequency
 158   1      
 159   1         CLKSEL = 0x00;                      // Select the internal osc. as
 160   1                                             // the SYSCLK source
 161   1      
 162   1         SFRPAGE = SFRPAGE_SAVE;             // Restore SFR page
 163   1      }

⌨️ 快捷键说明

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