blinky.lst

来自「使用KeilC51开发环境,C8051F330单片,一个简单的Hello Wor」· LST 代码 · 共 158 行

LST
158
字号
C51 COMPILER V7.50   BLINKY                                                                03/23/2007 16:06:59 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE BLINKY
OBJECT MODULE PLACED IN Blinky.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Blinky.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          //-----------------------------------------------------------------------------
   2          // Blinky.c
   3          //-----------------------------------------------------------------------------
   4          // Copyright (C) 2005 Silicon Laboratories, Inc.
   5          //
   6          // AUTH: HF
   7          // DATE: 04 FEB 2003
   8          //
   9          // This program flashes the green LED on the C8051F33x target board about 
  10          // five times a second using the interrupt handler for Timer2.
  11          //
  12          // Target: C8051F33x
  13          //
  14          // Tool chain: KEIL Eval 'c'
  15          //
  16          
  17          //-----------------------------------------------------------------------------
  18          // Includes
  19          //-----------------------------------------------------------------------------
  20          #include <c8051f330.h>                    // SFR declarations
  21          
  22          //-----------------------------------------------------------------------------
  23          // 16-bit SFR Definitions for 'F33x
  24          //-----------------------------------------------------------------------------
  25          
  26          sfr16 TMR2RL   = 0xca;                    // Timer2 reload value
  27          sfr16 TMR2     = 0xcc;                    // Timer2 counter
  28          
  29          //-----------------------------------------------------------------------------
  30          // Global CONSTANTS
  31          //-----------------------------------------------------------------------------
  32          
  33          #define SYSCLK       24500000 / 8         // SYSCLK frequency in Hz
  34          
  35          sbit LED = P1^3;                          // LED='1' means ON
  36          sbit SW2 = P0^7;                          // SW2='0' means switch pressed
  37          
  38          //-----------------------------------------------------------------------------
  39          // Function PROTOTYPES
  40          //-----------------------------------------------------------------------------
  41          void SYSCLK_Init (void);
  42          void PORT_Init (void);
  43          void Timer2_Init (int counts);
  44          void Timer2_ISR (void);
  45          
  46          //-----------------------------------------------------------------------------
  47          // MAIN Routine
  48          //-----------------------------------------------------------------------------
  49          void main (void) {
  50   1      
  51   1         // disable watchdog timer
  52   1         PCA0MD &= ~0x40;                       // WDTE = 0 (clear watchdog timer 
  53   1                                                // enable)
  54   1      
  55   1         SYSCLK_Init ();                        // Initialize system clock to 
C51 COMPILER V7.50   BLINKY                                                                03/23/2007 16:06:59 PAGE 2   

  56   1                                                // 24.5MHz
  57   1         PORT_Init ();                          // Initialize crossbar and GPIO
  58   1         Timer2_Init (SYSCLK / 12 / 10);        // Init Timer2 to generate 
  59   1                                                // interrupts at a 10Hz rate.
  60   1      
  61   1         EA = 1;                                                            // enable global interrupts
  62   1      
  63   1         while (1) {                            // spin forever
  64   2         }
  65   1      }
  66          
  67          //-----------------------------------------------------------------------------
  68          // SYSCLK_Init
  69          //-----------------------------------------------------------------------------
  70          //
  71          // This routine initializes the system clock to use the internal 24.5MHz / 8 
  72          // oscillator as its clock source.  Also enables missing clock detector reset.
  73          //
  74          void SYSCLK_Init (void)
  75          {
  76   1      
  77   1         OSCICN = 0x80;                         // configure internal oscillator for
  78   1                                                // its lowest frequency
  79   1         RSTSRC = 0x04;                         // enable missing clock detector
  80   1      }
  81          
  82          //-----------------------------------------------------------------------------
  83          // PORT_Init
  84          //-----------------------------------------------------------------------------
  85          //
  86          // Configure the Crossbar and GPIO ports.
  87          // P3.3 - LED (push-pull)
  88          //
  89          void PORT_Init (void)
  90          {
  91   1      
  92   1         XBR0     = 0x00;                       // no digital peripherals selected
  93   1         XBR1     = 0x40;                       // Enable crossbar and weak pull-ups
  94   1         P1MDOUT |= 0x08;                       // enable LED as a push-pull output
  95   1      }
  96          
  97          //-----------------------------------------------------------------------------
  98          // Timer2_Init
  99          //-----------------------------------------------------------------------------
 100          //
 101          // Configure Timer2 to 16-bit auto-reload and generate an interrupt at 
 102          // interval specified by <counts> using SYSCLK/48 as its time base.
 103          //
 104          void Timer2_Init (int counts)
 105          {
 106   1         TMR2CN  = 0x00;                        // Stop Timer2; Clear TF2;
 107   1                                                // use SYSCLK/12 as timebase
 108   1         CKCON  &= ~0x60;                       // Timer2 clocked based on T2XCLK;
 109   1      
 110   1         TMR2RL  = -counts;                     // Init reload values
 111   1         TMR2    = 0xffff;                      // set to reload immediately
 112   1         ET2     = 1;                           // enable Timer2 interrupts
 113   1         TR2     = 1;                           // start Timer2
 114   1      }
 115          
 116          //-----------------------------------------------------------------------------
 117          // Interrupt Service Routines
C51 COMPILER V7.50   BLINKY                                                                03/23/2007 16:06:59 PAGE 3   

 118          //-----------------------------------------------------------------------------
 119          
 120          //-----------------------------------------------------------------------------
 121          // Timer2_ISR
 122          //-----------------------------------------------------------------------------
 123          // This routine changes the state of the LED whenever Timer2 overflows.
 124          //
 125          void Timer2_ISR (void) interrupt 5
 126          {
 127   1         TF2H = 0;                              // clear Timer2 interrupt flag
 128   1         LED = ~LED;                            // change state of LED
 129   1      }
 130          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =     68    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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