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

📄 main.lst

📁 时间触发嵌入式系统设计模式:使用8051系列微控制器开发可靠应用
💻 LST
字号:
C51 COMPILER V6.10  MAIN                                                                   04/19/2001 12:10:20 PAGE 1   


C51 COMPILER V6.10, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN .\MAIN.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE .\MAIN.C OPTIMIZE(6,SPEED) BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /*------------------------------------------------------------------*-
   2          
   3             Main.c (v1.00)
   4          
   5            ------------------------------------------------------------------
   6          
   7             One-task scheduler demonstration program
   8           
   9             - See Chapter 36 for details.
  10          
  11          
  12             COPYRIGHT
  13             ---------
  14          
  15             This code is from the book:
  16          
  17             PATTERNS FOR TIME-TRIGGERED EMBEDDED SYSTEMS by Michael J. Pont 
  18             [Pearson Education, 2001; ISBN: 0-201-33138-1].
  19          
  20             This code is copyright (c) 2001 by Michael J. Pont.
  21           
  22             See book for copyright details and other information.
  23          
  24          -*------------------------------------------------------------------*/
  25          
  26          #include "Main.H"
  27          #include "Port.H"
  28          
  29          #define INTERRUPT_Timer_2_Overflow 5
  30          
  31          // Global variable
  32          static tByte LED_state_G;
  33          
  34          // Function prototypes
  35          // NOTE: ISR is not explictly called and does not require a prototype
  36          void Timer_2_Init(void);
  37          void LED_Flash_Init(void);
  38          void Go_To_Sleep(void);
  39          
  40          /* --------------------------------------------------------------- */
  41          
  42          void main(void)
  43             {
  44   1         Timer_2_Init();    // Set up Timer 2
  45   1      
  46   1         LED_Flash_Init();  // Prepare to flash LED
  47   1      
  48   1         EA = 1;            // Globally enable interrupts
  49   1         
  50   1         while(1)           // Super Loop
  51   1            {
  52   2            Go_To_Sleep();  // Enter idle mode to save power
  53   2            }
  54   1         }
  55          
C51 COMPILER V6.10  MAIN                                                                   04/19/2001 12:10:20 PAGE 2   

  56          /* --------------------------------------------------------------- */
  57          
  58          void Timer_2_Init(void)
  59             {
  60   1         // Timer 2 is configured as a 16-bit timer,
  61   1         // which is automatically reloaded when it overflows
  62   1         //
  63   1         // This code (generic 8051/52) assumes a 12 MHz system osc.  
  64   1         // The Timer 2 resolution is then 1.000 祍
  65   1         // (see Chapter 11 for details)
  66   1         //
  67   1         // Reload value is FC18 (hex) = 64536 (decimal)
  68   1         // Timer (16-bit) overflows when it reaches 65536 (decimal)
  69   1         // Thus, with these setting, timer will overflow every 1 ms
  70   1         T2CON   = 0x04;   // Load Timer 2 control register
  71   1         T2MOD   = 0x00;   // Load Timer 2 mode register
  72   1      
  73   1         TH2     = 0xFC;   // Load Timer 2 high byte
  74   1         RCAP2H  = 0xFC;   // Load Timer 2 reload capt. reg. high byte
  75   1         TL2     = 0x18;   // Load Timer 2 low byte
  76   1         RCAP2L  = 0x18;   // Load Timer 2 reload capt. reg. low byte
  77   1      
  78   1         // Timer 2 interrupt is enabled, and ISR will be called 
  79   1         // whenever the timer overflows - see below.
  80   1         ET2     = 1;
  81   1      
  82   1         // Start Timer 2 running
  83   1         TR2   = 1;        
  84   1         }
  85          
  86          /*------------------------------------------------------------------*-
  87          
  88            LED_Flash_Init()
  89          
  90            - See below.
  91          
  92          -*------------------------------------------------------------------*/
  93          void LED_Flash_Init(void)
  94             {
  95   1         LED_state_G = 0;
  96   1         }
  97          
  98          
  99          /*------------------------------------------------------------------*-
 100          
 101            LED_Flash_Update()
 102          
 103            Flashes an LED (or pulses a buzzer, etc) on a specified port pin.
 104          
 105            Code assumes this function will called every 1 ms.
 106            The LED will flash at 0.5Hz (on for 1 second, off for 1 second)
 107          
 108          -*------------------------------------------------------------------*/
 109          void LED_Flash_Update(void) interrupt INTERRUPT_Timer_2_Overflow
 110             {
 111   1         // This ISR is called every 1 ms
 112   1         // - only want to update the LED every second
 113   1         static data tWord Call_count;
 114   1      
 115   1         TF2 = 0;  // Reset the T2 flag   
 116   1      
 117   1         if (++Call_count < 1000)
C51 COMPILER V6.10  MAIN                                                                   04/19/2001 12:10:20 PAGE 3   

 118   1            {
 119   2            return;
 120   2            }
 121   1      
 122   1         Call_count = 0;
 123   1      
 124   1         // Change the LED from OFF to ON (or vice versa)
 125   1         // (Do this every second)
 126   1         if (LED_state_G == 1)
 127   1            {
 128   2            LED_state_G = 0;
 129   2            LED_pin = 0;
 130   2            }
 131   1         else
 132   1            {
 133   2            LED_state_G = 1;
 134   2            LED_pin = 1;
 135   2            }
 136   1         }
 137          
 138          /*------------------------------------------------------------------*-
 139            
 140            Go_To_Sleep()
 141          
 142            This one-task scheduler enters 'idle mode' between clock ticks
 143            to save power.  The next clock tick will return the processor
 144            to the normal operating state.
 145          
 146            Note: a slight performance improvement is possible if this
 147            function is implemented as a macro, or if the code here is simply 
 148            pasted into the 'dispatch' function.  
 149          
 150            However, by making this a function call, it becomes easier 
 151            - during development - to assess the performance of the 
 152            scheduler, using the 'performance analyser' in the Keil 
 153            hardware simulator. See Chapter 14 for examples for this. 
 154          
 155            *** May wish to disable this if using a watchdog ***
 156          
 157            *** ADAPT AS REQUIRED FOR YOUR HARDWARE ***
 158          
 159          -*------------------------------------------------------------------*/
 160          void Go_To_Sleep(void)
 161             {
 162   1         PCON |= 0x01;    // Enter idle mode (generic 8051 version)
 163   1      
 164   1         // Entering idle mode requires TWO consecutive instructions 
 165   1         // on 80c515 / 80c505 - to avoid accidental triggering
 166   1         //PCON |= 0x01;    // Enter idle mode (#1)
 167   1         //PCON |= 0x20;    // Enter idle mode (#2)
 168   1         }
 169          
 170          
 171          /*------------------------------------------------------------------*-
 172            ---- END OF FILE -------------------------------------------------
 173          -*------------------------------------------------------------------*/


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =     96    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
C51 COMPILER V6.10  MAIN                                                                   04/19/2001 12:10:20 PAGE 4   

   PDATA SIZE       =   ----    ----
   DATA SIZE        =      3    ----
   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 + -