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

📄 sch51.lst

📁 时间触发式单片机最小系统
💻 LST
字号:
C51 COMPILER V7.20   SCH51                                                                 05/25/2005 03:08:55 PAGE 1   


C51 COMPILER V7.20, COMPILATION OF MODULE SCH51
OBJECT MODULE PLACED IN SCH51.OBJ
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE SCH51.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /*------------------------------------------------------
   2           SCHd51.c
   3           simple embedded operation system(s_EOS)
   4           Based on the sheduler
   5          ------------------------------------------------------*/
   6          #include"SCH51.h"
   7          #include"main.h"
   8          #include"mytask.h"
   9          
  10          bit Error_code_G=0;
  11          
  12          /* Store in DATA area, if possible, for rapid access
  13          Total memory per task is 7 bytes */
  14          typedef data struct
  15          {
  16              /* Pointer to the task (must be a 'void (void)' function) */
  17              void (code * pTask)(void);
  18              /* Delay (ticks) until the function will (next) be run
  19              - see SCH_Add_Task() for further details */
  20              uint Delay;
  21              /* Interval (ticks) between subsequent runs.
  22              - see SCH_Add_Task() for further details */
  23              uint Period;
  24          
  25              /* Incremented (by scheduler) when task is due to execute */
  26              uchar RunMe;
  27          } sTask;
  28            /* The array of tasks */
  29            sTask SCH_tasks_G[SCH_MAX_TASKS];
  30          ////////////////////////////////////////////////////////////
  31          
  32          void SCH_Init_T0(void)
  33          {
  34   1         uchar i;
  35   1         for (i = 0; i < SCH_MAX_TASKS;i++)
  36   1            {
  37   2               SCH_Delete_Task(i);
  38   2            }
  39   1      /* SCH_Delete_Task() will generate an error code,
  40   1      because the task array is empty.
  41   1      -> reset the global error variable. */
  42   1      
  43   1      /* Now set up Timer 0
  44   1      16-bit timer function with automatic reload
  45   1      Crystal is assumed to be 12 MHz
  46   1      The Timer 2 resolution is 0.000001 seconds (1 μs)
  47   1      The required Timer 0 overflow is 0.001 seconds (1 ms)
  48   1      - this takes 1000 timer ticks
  49   1      Reload value is 65536 - 1000 = 64536 (dec) = 0xFC18 */
  50   1            TCON = 0x04; /* Load Timer 0 control register */
  51   1            TMOD = 0x01; /* Load Timer 0 mode register */
  52   1            TH0 = 0xd8; /* Load Timer 0 high byte */
  53   1            //RCAP2H = 0xFC; /* Load Timer 0 reload capture reg, high byte */
  54   1            TL0 = 0xf0; /* Load Timer 0 low byte */
  55   1            //RCAP2L = 0x18; /* Load Timer 0 reload capture reg, low byte */
C51 COMPILER V7.20   SCH51                                                                 05/25/2005 03:08:55 PAGE 2   

  56   1            ET0 = 1; /* Timer 0 interrupt is enabled */
  57   1            TR0 = 1; /* Start Timer 0 */
  58   1      }
  59          //////////////////////////////////////////////////////////////
  60          /*--------------------------------------------------------*/
  61          void SCH_Update(void) interrupt INT_T0_Overflow
  62          {
  63   1            uchar Index;
  64   1            TF0 = 0; /* Have to manually clear this. */
  65   1            /* NOTE: calculations are in *TICKS* (not milliseconds) */
  66   1            for (Index = 0; Index < SCH_MAX_TASKS; Index++)
  67   1               {
  68   2                  /* Check if there is a task at this location */
  69   2                  if (SCH_tasks_G[Index].pTask)
  70   2                     {
  71   3                       if (--SCH_tasks_G[Index].Delay == 0)
  72   3                         {
  73   4                           /* The task is due to run */
  74   4                           SCH_tasks_G[Index].RunMe += 1; /* Inc. 'RunMe' flag */
  75   4                           if (SCH_tasks_G[Index].Period)
  76   4                            {
  77   5                             /* Schedule regular tasks to run again */
  78   5                             SCH_tasks_G[Index].Delay = SCH_tasks_G[Index].Period;
  79   5                            }
  80   4                         }
  81   3                      }
  82   2               }
  83   1      }
  84          //////////////////////////////////////////////////////////////
  85          uchar SCH_Add_Task(void (code * pFunction)(),
  86                                   const uint DELAY,
  87                                   const uint PERIOD)
  88              {
  89   1            uchar Index = 0;
  90   1            /* First find a gap in the array (if there is one) */
  91   1            while ((SCH_tasks_G[Index].pTask != 0) && (Index < SCH_MAX_TASKS))
  92   1              {
  93   2               Index++;
  94   2              }
  95   1             /* Have we reached the end of the list? */
  96   1             if (Index == SCH_MAX_TASKS)
  97   1              {
  98   2                /* Task list is full
  99   2                -> set the global error variable */
 100   2                Error_code_G = ERROR_SCH_TOO_MANY_TASKS;
 101   2                /* Also return an error code */
 102   2                return SCH_MAX_TASKS;
 103   2              }
 104   1              /* If we're here, there is a space in the task array */
 105   1              SCH_tasks_G[Index].pTask = pFunction;
 106   1              SCH_tasks_G[Index].Delay = DELAY + 1;
 107   1              SCH_tasks_G[Index].Period = PERIOD;
 108   1              SCH_tasks_G[Index].RunMe = 0;
 109   1              return Index; /* return pos. of task (to allow deletion) */
 110   1          }
 111          ///////////////////////////////////////////////////////////////
 112          /*--------------------------------------------------------*-
 113          SCH_Dispatch_Tasks()
 114          This is the 'dispatcher' function. When a task (function)
 115          is due to run, SCH_Dispatch_Tasks() will run it.
 116          This function must be called (repeatedly) from the main loop.
 117          -*--------------------------------------------------------*/
C51 COMPILER V7.20   SCH51                                                                 05/25/2005 03:08:55 PAGE 3   

 118          void SCH_Dispatch_Tasks(void)
 119          {
 120   1          uchar Index;
 121   1          /* Dispatches (runs) the next task (if one is ready) */
 122   1          for (Index = 0; Index < SCH_MAX_TASKS; Index++)
 123   1           {
 124   2            if (SCH_tasks_G[Index].RunMe > 0)
 125   2              {
 126   3              (*SCH_tasks_G[Index].pTask)(); /* Run the task */
 127   3               SCH_tasks_G[Index].RunMe -= 1; /* Reduce RunMe count */
 128   3               /* Periodic tasks will automatically run again
 129   3               - if this is a 'one shot' task, delete it */
 130   3               if (SCH_tasks_G[Index].Period == 0)
 131   3                 {
 132   4                    SCH_Delete_Task(Index);
 133   4                 }
 134   3              }
 135   2            }
 136   1          /* Report system status */
 137   1          //SCH_Report_Status();
 138   1          /* The scheduler enters idle mode at this point */
 139   1          SCH_Go_To_Sleep();
 140   1      }
 141          //////////////////////////////////////////////////////////////
 142          /*--------------------------------------------------------*/
 143          void SCH_Go_To_Sleep(void)
 144          {
 145   1         PCON |= 0x01; /* Enter idle mode (generic 8051 version) */
 146   1          /* Entering idle mode requires TWO consecutive instructions
 147   1           on 80c515 / 80c505 - to avoid accidental triggering.
 148   1           E.g:
 149   1          PCON |= 0x01;
 150   1          PCON |= 0x20; */
 151   1      }
 152          //////////////////////////////////////////////////////////////
 153          /*--------------------------------------------------------*/
 154          void SCH_Start(void)
 155          {
 156   1        EA = 1;
 157   1      }
 158          /////////////////////////////////////////////////////////////
 159          bit SCH_Delete_Task(const uchar TASK_INDEX)
 160          {
 161   1        bit Return_code;
 162   1        if (SCH_tasks_G[TASK_INDEX].pTask == 0)
 163   1          { 
 164   2           /* No task at this location...
 165   2           -> set the global error variable */
 166   2            Error_code_G = ERROR_SCH_CANNOT_DELETE_TASK;
 167   2           /* ...also return an error code */
 168   2           Return_code = RETURN_ERROR;
 169   2          }
 170   1        else
 171   1          {
 172   2           Return_code = RETURN_NORMAL;
 173   2          }
 174   1          SCH_tasks_G[TASK_INDEX].pTask = 0x0000;
 175   1          SCH_tasks_G[TASK_INDEX].Delay = 0;
 176   1          SCH_tasks_G[TASK_INDEX].Period = 0;
 177   1          SCH_tasks_G[TASK_INDEX].RunMe = 0;
 178   1          return Return_code; /* return status */
 179   1      }
C51 COMPILER V7.20   SCH51                                                                 05/25/2005 03:08:55 PAGE 4   



MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    404    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     35       4
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      1       1
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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