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

📄 main.lst

📁 新一代功能比较齐全的c8051f020单片机的串行通信c程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V6.23a  MAIN                                                                  12/19/2002 16:23:32 PAGE 1   


C51 COMPILER V6.23a, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE main.c DB OE

stmt level    source

   1          //-----------------------------------------------------------------------------
   2          // Temp_3.c
   3          //-----------------------------------------------------------------------------
   4          // Copyright 2001 Cygnal Integrated Products, Inc.
   5          //
   6          // AUTH: BW
   7          // DATE: 19 JUL 01
   8          //
   9          // This program prints the C8051F020 die temperature out the hardware 
  10          // UART at 9600bps. Assumes an 22.1184MHz crystal is attached between 
  11          // XTAL1 and XTAL2.
  12          //
  13          // The ADC is configured to look at the on-chip temp sensor.  The sampling
  14          // rate of the ADC is determined by the constant <SAMPLE_RATE>, which is given
  15          // in Hz.
  16          // 
  17          // The ADC0 End of Conversion Interrupt Handler retrieves the sample
  18          // from the ADC and adds it to a running accumulator.  Every <INT_DEC> 
  19          // samples, the ADC updates and stores its result in the global variable
  20          // <temperature>, which holds the current temperature in hundredths of a
  21          // degree.  The sampling technique of adding a set of values and
  22          // decimating them (posting results every (n)th sample) is called 'integrate
  23          // and dump.'  It is easy to implement and requires very few resources.
  24          //
  25          // For each power of 4 of <INT_DEC>, you gain 1 bit of effective resolution.
  26          // For example, <INT_DEC> = 256 gain you 4 bits of resolution: 4^4 = 256.
  27          //
  28          // Also note that the ADC0 is configured for 'LEFT' justified mode.  In this
  29          // mode, the MSB of the ADC word is located in the MSB position of the ADC0
  30          // high byte.  Using the data in this way makes the magnitude of the resulting
  31          // code independent of the number of bits in the ADC (12- and 10-bits behave
  32          // the same).
  33          //
  34          // Target: C8051F02x
  35          // Tool chain: KEIL C51 6.03 / KEIL EVAL C51
  36          //
  37          
  38          //-----------------------------------------------------------------------------
  39          // Includes
  40          //-----------------------------------------------------------------------------
  41          
  42          #include <c8051f020.h>                 // SFR declarations
  43          #include <stdio.h>
  44          
  45          //-----------------------------------------------------------------------------
  46          // 16-bit SFR Definitions for 'F02x
  47          //-----------------------------------------------------------------------------
  48          
  49          sfr16 DP       = 0x82;                 // data pointer
  50          sfr16 TMR3RL   = 0x92;                 // Timer3 reload value
  51          sfr16 TMR3     = 0x94;                 // Timer3 counter
  52          sfr16 ADC0     = 0xbe;                 // ADC0 data
  53          sfr16 ADC0GT   = 0xc4;                 // ADC0 greater than window
  54          sfr16 ADC0LT   = 0xc6;                 // ADC0 less than window
  55          sfr16 RCAP2    = 0xca;                 // Timer2 capture/reload
C51 COMPILER V6.23a  MAIN                                                                  12/19/2002 16:23:32 PAGE 2   

  56          sfr16 T2       = 0xcc;                 // Timer2
  57          sfr16 RCAP4    = 0xe4;                 // Timer4 capture/reload
  58          sfr16 T4       = 0xf4;                 // Timer4
  59          sfr16 DAC0     = 0xd2;                 // DAC0 data
  60          sfr16 DAC1     = 0xd5;                 // DAC1 data
  61          
  62          //-----------------------------------------------------------------------------
  63          // Global CONSTANTS
  64          //-----------------------------------------------------------------------------
  65          
  66          #define BAUDRATE     115200            // Baud rate of UART in bps
  67          #define SYSCLK       11059200          // SYSCLK frequency in Hz
  68          #define SAMPLE_RATE  50000             // Sample frequency in Hz
  69          #define INT_DEC      256               // integrate and decimate ratio
  70          
  71          sbit LED = P1^6;                       // LED='1' means ON
  72          sbit SW1 = P3^7;                       // SW1='0' means switch pressed
  73          
  74          //-----------------------------------------------------------------------------
  75          // Function PROTOTYPES
  76          //-----------------------------------------------------------------------------
  77          
  78          void SYSCLK_Init (void);
  79          void PORT_Init (void);
  80          void UART0_Init (void);
  81          void ADC0_Init (void);
  82          void Timer3_Init (int counts);
  83          void ADC0_ISR (void);
  84          
  85          //-----------------------------------------------------------------------------
  86          // Global VARIABLES
  87          //-----------------------------------------------------------------------------
  88          
  89          long result;                           // ADC0 decimated value
  90          
  91          //-----------------------------------------------------------------------------
  92          // MAIN Routine
  93          //-----------------------------------------------------------------------------
  94          
  95          void main (void) {
  96   1              unsigned int ii;
  97   1         long temperature;                   // temperature in hundredths of a
  98   1                                                     // degree C
  99   1         int temp_int, temp_frac;            // integer and fractional portions of
 100   1                                             // temperature
 101   1      
 102   1         WDTCN = 0xde;                       // disable watchdog timer
 103   1         WDTCN = 0xad;
 104   1      
 105   1         SYSCLK_Init ();                     // initialize oscillator
 106   1         PORT_Init ();                       // initialize crossbar and GPIO
 107   1         UART0_Init ();                      // initialize UART0
 108   1         Timer3_Init (SYSCLK/SAMPLE_RATE);   // initialize Timer3 to overflow at
 109   1                                             // sample rate
 110   1      
 111   1         ADC0_Init ();                       // init ADC
 112   1      
 113   1              AD0EN = 1;                          // enable ADC
 114   1      
 115   1         EA = 1;                             // Enable global interrupts
 116   1      
 117   1              while (1) {
C51 COMPILER V6.23a  MAIN                                                                  12/19/2002 16:23:32 PAGE 3   

 118   2            EA = 0;                          // disable interrupts
 119   2            temperature = result;
 120   2            EA = 1;                          // re-enable interrupts
 121   2      
 122   2            // calculate temperature in hundredths of a degree
 123   2            temperature = temperature - 42380;
 124   2            temperature = (temperature * 100L) / 156;
 125   2            temp_int = temperature / 100;
 126   2            temp_frac = temperature - (temp_int * 100);
 127   2                 printf ("Temperature is %+02d.%02d\n", temp_int, temp_frac);
 128   2                for (ii=0;ii<60000;ii++)
 129   2                {
 130   3      
 131   3                }
 132   2      
 133   2            LED = ~SW1;                      // LED reflects state of switch
 134   2              }
 135   1      }
 136          
 137          //-----------------------------------------------------------------------------
 138          // Initialization Subroutines

⌨️ 快捷键说明

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