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

📄 2_01_12s.lst

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


C51 COMPILER V6.10, COMPILATION OF MODULE 2_01_12S
OBJECT MODULE PLACED IN .\2_01_12s.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE .\2_01_12s.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /*------------------------------------------------------------------*-
   2          
   3             2_01_12s.C (v1.00) 
   4          
   5            ------------------------------------------------------------------
   6          
   7             *** THIS IS A STABLE SCHEDULER FOR STANDARD 8051 / 8052 ***
   8          
   9             *** Uses T2 for timing, 16-bit auto reload ***
  10             *** 12 MHz oscillator -> 1 ms (precise) tick interval ***
  11          
  12             *** Assumes DS1621 temperature sensor available ***
  13          
  14          
  15             COPYRIGHT
  16             ---------
  17          
  18             This code is from the book:
  19          
  20             PATTERNS FOR TIME-TRIGGERED EMBEDDED SYSTEMS by Michael J. Pont 
  21             [Pearson Education, 2001; ISBN: 0-201-33138-1].
  22          
  23             This code is copyright (c) 2000 by Michael J. Pont.
  24           
  25             See book for copyright details and other information.
  26          
  27          -*------------------------------------------------------------------*/
  28          
  29          #include "2_01_12s.h"
  30          #include "I2C_1621.h"
  31          
  32          // ------ Public variable definitions ------------------------------
  33          
  34          // The current temperature, recorded every hour
  35          tByte Temperature_G;
  36          
  37          // ------ Public variable declarations -----------------------------
  38          
  39          // The array of tasks (see Sch51.C)
  40          extern sTask SCH_tasks_G[SCH_MAX_TASKS];
  41          
  42          // The error code variable
  43          //
  44          // See Port.H for port on which error codes are displayed
  45          // and for details of error codes
  46          extern tByte Error_code_G;
  47          
  48          // Running total / average temperature (calculated every 24 hours)
  49          static int Temperature_average_G = 0;
  50          
  51          // Called every minute: only take reading once an hour
  52          // (calling every hour requires changes to scheduler,
  53          // increasing the required memory for EVERY task).
  54          static tByte Minute_G;
  55          static tByte Hour_G;
C51 COMPILER V6.10  2_01_12S                                                               04/10/2001 11:27:55 PAGE 2   

  56          
  57          // The temperature compensation data
  58          // 
  59          // The Timer 2 reload values (low and high bytes) are varied depending 
  60          // on the current average temperature.
  61          // 
  62          // NOTE (1):
  63          // Only temperature values from 10 - 30 celsius are considered 
  64          // in this version
  65          //
  66          // NOTE (2):
  67          // Adjust these values to match your hardware!
  68          tByte code T2_reload_L[21] = 
  69                     // 10   11   12   13   14   15   16   17   18   19
  70                     {0xBA,0xB9,0xB8,0xB7,0xB6,0xB5,0xB4,0xB3,0xB2,0xB1,
  71                     // 20   21   22   23   24   25   26   27   28   29   30
  72                      0xB0,0xAF,0xAE,0xAD,0xAC,0xAB,0xAA,0xA9,0xA8,0xA7,0xA6};
  73          
  74          tByte code T2_reload_H[21] = 
  75                     // 10   11   12   13   14   15   16   17   18   19
  76                     {0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,
  77                     // 20   21   22   23   24   25   26   27   28   29   30
  78                      0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C};
  79          
  80          /*------------------------------------------------------------------*-
  81          
  82            SCH_Init_T2()
  83          
  84            Scheduler initialisation function.  Prepares scheduler
  85            data structures and sets up timer interrupts at required rate.
  86            Must call this function before using the scheduler.  
  87          
  88          -*------------------------------------------------------------------*/
  89          void SCH_Init_T2(void) 
  90             {
  91   1         tByte i;
  92   1      
  93   1         for (i = 0; i < SCH_MAX_TASKS; i++) 
  94   1            {
  95   2            SCH_Delete_Task(i);
  96   2            }
  97   1      
  98   1         // Reset the global error variable
  99   1         // - SCH_Delete_Task() will generate an error code, 
 100   1         //   (because the task array is empty)
 101   1         Error_code_G = 0;  
 102   1      
 103   1         // Now set up Timer 2
 104   1         // 16-bit timer function with automatic reload
 105   1      
 106   1         // Crystal is assumed to be 12 MHz
 107   1         // The Timer 2 resolution is 0.000001 seconds (1 祍)
 108   1         // The required Timer 2 overflow is 0.001 seconds (1 ms)
 109   1         // - this takes 1000 timer ticks
 110   1         // Reload value is 65536 - 1000 = 64536 (dec) = 0xFC18
 111   1      
 112   1         T2CON = 0x04;   // load Timer 2 control register
 113   1         T2MOD = 0x00;   // load Timer 2 mode register
 114   1      
 115   1         TH2    = 0xFC;  // load timer 2 high byte
 116   1         RCAP2H = 0xFC;  // load timer 2 reload capture reg, high byte
 117   1         TL2    = 0x18;  // load timer 2 low byte
C51 COMPILER V6.10  2_01_12S                                                               04/10/2001 11:27:55 PAGE 3   

 118   1         RCAP2L = 0x18;  // load timer 2 reload capture reg, low byte
 119   1         
 120   1         ET2   = 1;  // Timer 2 interrupt is enabled
 121   1      
 122   1         TR2   = 1;  // Start Timer 2
 123   1         }
 124          
 125          
 126          /*------------------------------------------------------------------*-
 127          
 128            SCH_Start()
 129          
 130            Starts the scheduler, by enabling interrupts.
 131          
 132            NOTE: Usually called after all regular tasks are added,
 133            to keep the tasks synchronised.
 134          
 135            NOTE: ONLY THE SCHEDULER INTERRUPT SHOULD BE ENABLED!!! 
 136          
 137          -*------------------------------------------------------------------*/
 138          void SCH_Start(void) 
 139             {
 140   1         EA = 1;
 141   1         }
 142          
 143          /*------------------------------------------------------------------*-
 144          
 145            SCH_Update()
 146          
 147            This is the scheduler ISR.  It is called at a rate 
 148            determined by the timer settings in the 'init' function.
 149          
 150            This version is triggered by Timer 2 interrupts:
 151            timer is automatically reloaded.
 152          
 153          -*------------------------------------------------------------------*/
 154          void SCH_Update(void) interrupt INTERRUPT_Timer_2_Overflow  
 155             {
 156   1         tByte Index;
 157   1      
 158   1         TF2 = 0; // Have to manually clear this. 
 159   1      
 160   1         // NOTE: calculations are in *TICKS* (not milliseconds)
 161   1         for (Index = 0; Index < SCH_MAX_TASKS; Index++)
 162   1            {
 163   2            // Check if there is a task at this location
 164   2            if (SCH_tasks_G[Index].pTask)
 165   2               {
 166   3               if (SCH_tasks_G[Index].Delay == 0)
 167   3                  {
 168   4                  // The task is due to run
 169   4                  SCH_tasks_G[Index].RunMe += 1;  // Inc. the 'RunMe' flag
 170   4      
 171   4                  if (SCH_tasks_G[Index].Period)
 172   4                     {
 173   5                     // Schedule this regular task to run again
 174   5                     SCH_tasks_G[Index].Delay = SCH_tasks_G[Index].Period;
 175   5                     }
 176   4                  }
 177   3               else
 178   3                  {
 179   4                  // Not yet ready to run: just decrement the delay 
C51 COMPILER V6.10  2_01_12S                                                               04/10/2001 11:27:55 PAGE 4   

 180   4                  SCH_tasks_G[Index].Delay -= 1;
 181   4                  }
 182   3               }         
 183   2            }
 184   1         }   
 185          
 186          /*------------------------------------------------------------------*-
 187          
 188            SCH_Calculate_Ave_Temp_DS1621()
 189          
 190            This function should be scheduled once per minute.
 191          
 192            Based on 1 measurement per hour,
 193            this function updates a variable Temperature_average_G) 
 194            with the average temperature over the last 24 hours.
 195          
 196            The updates are carried out every 24 hours.
 197          
 198          -*------------------------------------------------------------------*/
 199          void SCH_Calculate_Ave_Temp_DS1621(void)
 200             {
 201   1         if (++Minute_G == 60)
 202   1            {
 203   2            Minute_G = 0;
 204   2      
 205   2            // An hour has elapsed - take temperature reading
 206   2            I2C_Read_Temperature_DS1621();
 207   2      
 208   2            // Add current reading to running total
 209   2            Temperature_average_G += Temperature_G;
 210   2      
 211   2            if (++Hour_G == 24)
 212   2               {
 213   3               // 24 hours have elapsed - get average temperature
 214   3               Hour_G = 0;
 215   3               Temperature_average_G /= 24;
 216   3      
 217   3               // Update the scheduler
 218   3               SCH_Perform_Temperature_Adjustment();  
 219   3               }
 220   2            }
 221   1         }
 222          
 223          /*------------------------------------------------------------------*-
 224          
 225            SCH_Perform_Temperature_Adjustment()
 226          
 227            This scheduler adjusts its timing to take into account
 228            changes in ambient temperature.
 229          
 230          -*------------------------------------------------------------------*/
 231          void SCH_Perform_Temperature_Adjustment(void)
 232             {
 233   1         static int Previous_temperature_average_G;
 234   1      
 235   1         if ((Previous_temperature_average_G - Temperature_average_G) != 0)
 236   1            {
 237   2            // Only consider temperatures in range 10 - 30 Celsius in this 
 238   2            // version (easily adjusted)
 239   2            if (Temperature_average_G < 10)
 240   2               {
 241   3               Temperature_average_G = 10;
C51 COMPILER V6.10  2_01_12S                                                               04/10/2001 11:27:55 PAGE 5   

 242   3               }
 243   2            else
 244   2               {
 245   3               if (Temperature_average_G > 30)
 246   3                  {
 247   4                  Temperature_average_G = 30;
 248   4                  }
 249   3               }
 250   2      
 251   2            ET2 = 0;  // Disable interrupt
 252   2            TR2 = 0;  // Stop T2
 253   2      
 254   2            // Reload the timer 
 255   2            TL2     = T2_reload_L[Temperature_average_G-10];   
 256   2            RCAP2L  = T2_reload_L[Temperature_average_G-10];   
 257   2            TH2     = T2_reload_H[Temperature_average_G-10];   
 258   2            RCAP2H  = T2_reload_H[Temperature_average_G-10];   
 259   2      
 260   2            ET2   = 1;      
 261   2            TR2   = 1;     
 262   2            }
 263   1      
 264   1         Previous_temperature_average_G = Temperature_average_G;
 265   1      
 266   1         Temperature_average_G = 0;
 267   1         }
 268          
 269          /*------------------------------------------------------------------*-
 270            ---- END OF FILE -------------------------------------------------
 271          -*------------------------------------------------------------------*/


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    315    ----
   CONSTANT SIZE    =     42    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      7       1
   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 + -