📄 2_05_11g.lst
字号:
C51 COMPILER V6.10 2_05_11G 04/18/2001 16:29:14 PAGE 1
C51 COMPILER V6.10, COMPILATION OF MODULE 2_05_11G
OBJECT MODULE PLACED IN .\2_05_11G.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE .\2_05_11G.C OPTIMIZE(6,SIZE) BROWSE NOINTPROMOTE DEBUG OBJECTEXTEND
stmt level source
1 /*------------------------------------------------------------------*-
2
3 2_05_11g.C (v1.00)
4
5 ------------------------------------------------------------------
6
7 *** THIS IS A SCHEDULER FOR STANDARD 8051 / 8052 ***
8
9 *** Uses T2 for timing, 16-bit auto reload ***
10 *** 11.059 MHz oscillator -> 5 ms (precise) tick interval ***
11
12
13 COPYRIGHT
14 ---------
15
16 This code is from the book:
17
18 PATTERNS FOR TIME-TRIGGERED EMBEDDED SYSTEMS by Michael J. Pont
19 [Pearson Education, 2001; ISBN: 0-201-33138-1].
20
21 This code is copyright (c) 2001 by Michael J. Pont.
22
23 See book for copyright details and other information.
24
25 -*------------------------------------------------------------------*/
26
27 #include "2_05_11g.h"
28
29 // ------ Public variable declarations -----------------------------
30
31 // The array of tasks (see Sch51.C)
32 extern sTask SCH_tasks_G[SCH_MAX_TASKS];
33
34 // Used to display the error code
35 // See Main.H for details of error codes
36 // See Port.H for details of the error port
37 extern tByte Error_code_G;
38
39 /*------------------------------------------------------------------*-
40
41 SCH_Init_T2()
42
43 Scheduler initialisation function. Prepares scheduler
44 data structures and sets up timer interrupts at required rate.
45
46 You must call this function before using the scheduler.
47
48 -*------------------------------------------------------------------*/
49 void SCH_Init_T2(void)
50 {
51 1 tByte i;
52 1
53 1 for (i = 0; i < SCH_MAX_TASKS; i++)
54 1 {
55 2 SCH_Delete_Task(i);
C51 COMPILER V6.10 2_05_11G 04/18/2001 16:29:14 PAGE 2
56 2 }
57 1
58 1 // Reset the global error variable
59 1 // - SCH_Delete_Task() will generate an error code,
60 1 // (because the task array is empty)
61 1 Error_code_G = 0;
62 1
63 1 // Now set up Timer 2
64 1 // 16-bit timer function with automatic reload
65 1
66 1 T2CON = 0x04; // load Timer 2 control register
67 1 T2MOD = 0x00; // load Timer 2 mode register
68 1
69 1 // Crystal is assumed to be 11.059 MHz
70 1 // Assume 12 osc cycles per timer increment
71 1 // -> timer resolution is 0.000001085069444444 seconds (1.085 祍)
72 1 // The required Timer 2 overflow is 0.005 seconds (5 ms)
73 1 // - this takes 4608 timer ticks
74 1 // Reload value is 65536 - 4608 = 60928 (dec) = 0xEE00
75 1
76 1 TH2 = 0xEE; // load timer 2 high byte
77 1 RCAP2H = 0xEE; // load timer 2 reload capture reg, high byte
78 1 TL2 = 0x00; // load timer 2 low byte
79 1 RCAP2L = 0x00; // load timer 2 reload capture reg, low byte
80 1
81 1 // Start timer
82 1 ET2 = 1; // Timer 2 interrupt is enabled
83 1 TR2 = 1; // Start Timer 2
84 1 }
85
86
87 /*------------------------------------------------------------------*-
88
89 SCH_Start()
90
91 Starts the scheduler, by enabling interrupts.
92
93 NOTE: Usually called after all regular tasks are added,
94 to keep the tasks synchronised.
95
96 NOTE: ONLY THE SCHEDULER INTERRUPT SHOULD BE ENABLED!!!
97
98 -*------------------------------------------------------------------*/
99 void SCH_Start(void)
100 {
101 1 EA = 1;
102 1 }
103
104 /*------------------------------------------------------------------*-
105
106 SCH_Update()
107
108 This is the scheduler ISR. It is called at a rate
109 determined by the timer settings in the 'init' function.
110
111 This version is triggered by Timer 2 interrupts:
112 timer is automatically reloaded.
113
114 -*------------------------------------------------------------------*/
115 void SCH_Update(void) interrupt INTERRUPT_Timer_2_Overflow
116 {
117 1 tByte Index;
C51 COMPILER V6.10 2_05_11G 04/18/2001 16:29:14 PAGE 3
118 1
119 1 TF2 = 0; // Have to manually clear this.
120 1
121 1 // NOTE: calculations are in *TICKS* (not milliseconds)
122 1 for (Index = 0; Index < SCH_MAX_TASKS; Index++)
123 1 {
124 2 // Check if there is a task at this location
125 2 if (SCH_tasks_G[Index].pTask)
126 2 {
127 3 if (SCH_tasks_G[Index].Delay == 0)
128 3 {
129 4 // The task is due to run
130 4 SCH_tasks_G[Index].RunMe += 1; // Inc. the 'RunMe' flag
131 4
132 4 if (SCH_tasks_G[Index].Period)
133 4 {
134 5 // Schedule periodic tasks to run again
135 5 SCH_tasks_G[Index].Delay = SCH_tasks_G[Index].Period;
136 5 }
137 4 }
138 3 else
139 3 {
140 4 // Not yet ready to run: just decrement the delay
141 4 SCH_tasks_G[Index].Delay -= 1;
142 4 }
143 3 }
144 2 }
145 1 }
146
147
148 /*------------------------------------------------------------------*-
149 ---- END OF FILE -------------------------------------------------
150 -*------------------------------------------------------------------*/
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 168 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 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 + -