📄 2_01_12h.lst
字号:
C51 COMPILER V6.10 2_01_12H 04/19/2001 12:07:06 PAGE 10
41 =2
42 =2 // Interval (ticks) between subsequent runs.
43 =2 // - see SCH_Add_Task() for further details
44 =2 tWord Period;
45 =2
46 =2 // Incremented (by scheduler) when task is due to execute
47 =2 tByte RunMe;
48 =2
49 =2 // Set to 1 if task is co-operative
50 =2 // Set to 0 if task is pre-emptive
51 =2 tByte Co_op;
52 =2 } sTaskH;
53 =2
54 =2 // ------ Public function prototypes -------------------------------
55 =2
56 =2 // Core scheduler functions
57 =2 void hSCH_Dispatch_Tasks(void);
58 =2 tByte hSCH_Add_Task(void (code *)(void), tWord, tWord, bit);
59 =2 bit hSCH_Delete_Task(tByte);
60 =2 void hSCH_Report_Status(void);
61 =2
62 =2 // ------ Public constants -----------------------------------------
63 =2
64 =2 // The maximum number of tasks required at any one time
65 =2 // during the execution of the program
66 =2 //
67 =2 // MUST BE ADJUSTED FOR EACH NEW PROJECT
68 =2 #define hSCH_MAX_TASKS (2)
69 =2
70 =2 #endif
71 =2
72 =2 /*------------------------------------------------------------------*-
73 =2 ---- END OF FILE -------------------------------------------------
74 =2 -*------------------------------------------------------------------*/
75 =2
26 =1
27 =1 // ------ Public function prototypes -------------------------------
28 =1
29 =1 void hSCH_Init_T2(void);
30 =1 void hSCH_Start(void);
31 =1
32 =1 /*------------------------------------------------------------------*-
33 =1 ---- END OF FILE -------------------------------------------------
34 =1 -*------------------------------------------------------------------*/
35 =1
28
29 // ------ Public variable declarations -----------------------------
30
31 // The array of tasks (see Sch51.C)
32 extern sTaskH hSCH_tasks_G[hSCH_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 hSCH_Init_T2()
42
43 Scheduler initialisation function. Prepares scheduler
44 data structures and sets up timer interrupts at required rate.
C51 COMPILER V6.10 2_01_12H 04/19/2001 12:07:06 PAGE 11
45
46 You must call this function before using the scheduler.
47
48 -*------------------------------------------------------------------*/
49 void hSCH_Init_T2(void)
50 {
51 1 tByte i;
52 1
53 1 for (i = 0; i < hSCH_MAX_TASKS; i++)
54 1 {
55 2 hSCH_Delete_Task(i);
56 2 }
57 1
58 1 // Reset the global error variable
59 1 // - hSCH_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 // Crystal is assumed to be 12 MHz
67 1 // The Timer 2 resolution is 0.000001 seconds (1 祍)
68 1 // The required Timer 2 overflow is 0.001 seconds (1 ms)
69 1 // - this takes 1000 timer ticks
70 1 // Reload value is 65536 - 1000 = 64536 (dec) = 0xFC18
71 1
72 1 T2CON = 0x04; // load Timer 2 control register
73 1 T2MOD = 0x00; // load Timer 2 mode register
74 1
75 1 TH2 = 0xFC; // load timer 2 high byte
76 1 RCAP2H = 0xFC; // load timer 2 reload capture reg, high byte
77 1 TL2 = 0x18; // load timer 2 low byte
78 1 RCAP2L = 0x18; // load timer 2 reload capture reg, low byte
79 1
80 1 ET2 = 1; // Timer 2 interrupt is enabled
81 1
82 1 TR2 = 1; // Start Timer 2
83 1 }
84
85
86 /*------------------------------------------------------------------*-
87
88 hSCH_Start()
89
90 Starts the scheduler, by enabling interrupts.
91
92 NOTE: Usually called after all regular tasks are added,
93 to keep the tasks synchronised.
94
95 NOTE: ONLY THE SCHEDULER INTERRUPT SHOULD BE ENABLED!!!
96
97 -*------------------------------------------------------------------*/
98 void hSCH_Start(void)
99 {
100 1 EA = 1;
101 1 }
102
103 /*------------------------------------------------------------------*-
104
105 hSCH_Update
106
C51 COMPILER V6.10 2_01_12H 04/19/2001 12:07:06 PAGE 12
107 This is the scheduler ISR. It is called at a rate
108 determined by the timer settings in hSCH_Init().
109 This version is triggered by Timer 2 interrupts:
110 timer is automatically reloaded.
111
112 -*------------------------------------------------------------------*/
113 void hSCH_Update(void) interrupt INTERRUPT_Timer_2_Overflow
114 {
115 1 tByte Index;
116 1
117 1 TF2 = 0; // Have to manually clear this.
118 1
119 1 // NOTE: calculations are in *TICKS* (not milliseconds)
120 1 for (Index = 0; Index < hSCH_MAX_TASKS; Index++)
121 1 {
122 2 // Check if there is a task at this location
123 2 if (hSCH_tasks_G[Index].pTask)
124 2 {
125 3 if (hSCH_tasks_G[Index].Delay == 0)
126 3 {
127 4 // The task is due to run
128 4 //
129 4 if (hSCH_tasks_G[Index].Co_op)
130 4 {
131 5 // If it is a co-operative task, increment the RunMe flag
132 5 hSCH_tasks_G[Index].RunMe += 1;
133 5 }
134 4 else
135 4 {
136 5 // If it is a pre-emptive task, run it IMMEDIATELY
137 5 (*hSCH_tasks_G[Index].pTask)(); // Run the task
138 5
139 5 hSCH_tasks_G[Index].RunMe -= 1; // Reset / reduce RunMe flag
140 5
141 5 // Periodic tasks will be run again (see below)
142 5 // - if this is a 'one shot' task, remove it from the array
143 5 if (hSCH_tasks_G[Index].Period == 0)
144 5 {
145 6 hSCH_tasks_G[Index].pTask = 0;
146 6 }
147 5 }
148 4
149 4 if (hSCH_tasks_G[Index].Period)
150 4 {
151 5 // Schedule periodic tasks to run again
152 5 hSCH_tasks_G[Index].Delay = hSCH_tasks_G[Index].Period;
153 5 }
154 4 }
155 3 else
156 3 {
157 4 // Not yet ready to run: just decrement the delay
158 4 hSCH_tasks_G[Index].Delay -= 1;
159 4 }
160 3 }
161 2 }
162 1 }
163
164
165 /*------------------------------------------------------------------*-
166 ---- END OF FILE -------------------------------------------------
167 -*------------------------------------------------------------------*/
C51 COMPILER V6.10 2_01_12H 04/19/2001 12:07:06 PAGE 13
ASSEMBLY LISTING OF GENERATED OBJECT CODE
; FUNCTION hSCH_Init_T2 (BEGIN)
; SOURCE LINE # 49
; SOURCE LINE # 50
; SOURCE LINE # 53
0000 E4 CLR A
0001 F500 R MOV i,A
0003 ?C0001:
; SOURCE LINE # 54
; SOURCE LINE # 55
0003 AF00 R MOV R7,i
0005 120000 E LCALL _hSCH_Delete_Task
; SOURCE LINE # 56
0008 0500 R INC i
000A E500 R MOV A,i
000C C3 CLR C
000D 9402 SUBB A,#02H
000F 40F2 JC ?C0001
0011 ?C0002:
; SOURCE LINE # 61
0011 E4 CLR A
0012 F500 E MOV Error_code_G,A
; SOURCE LINE # 72
0014 75C804 MOV T2CON,#04H
; SOURCE LINE # 73
0017 F5C9 MOV T2MOD,A
; SOURCE LINE # 75
0019 75CDFC MOV TH2,#0FCH
; SOURCE LINE # 76
001C 75CBFC MOV RCAP2H,#0FCH
; SOURCE LINE # 77
001F 75CC18 MOV TL2,#018H
; SOURCE LINE # 78
0022 75CA18 MOV RCAP2L,#018H
; SOURCE LINE # 80
0025 D2AD SETB ET2
; SOURCE LINE # 82
0027 D2CA SETB TR2
; SOURCE LINE # 83
0029 22 RET
; FUNCTION hSCH_Init_T2 (END)
; FUNCTION hSCH_Start (BEGIN)
; SOURCE LINE # 98
; SOURCE LINE # 99
; SOURCE LINE # 100
0000 D2AF SETB EA
; SOURCE LINE # 101
0002 22 RET
; FUNCTION hSCH_Start (END)
; FUNCTION hSCH_Update (BEGIN)
0000 C0E0 PUSH ACC
0002 C0F0 PUSH B
0004 C083 PUSH DPH
0006 C082 PUSH DPL
0008 C0D0 PUSH PSW
000A 75D000 MOV PSW,#00H
000D C000 PUSH AR0
000F C001 PUSH AR1
C51 COMPILER V6.10 2_01_12H 04/19/2001 12:07:06 PAGE 14
0011 C002 PUSH AR2
0013 C003 PUSH AR3
0015 C004 PUSH AR4
0017 C005 PUSH AR5
0019 C006 PUSH AR6
001B C007 PUSH AR7
; SOURCE LINE # 113
; SOURCE LINE # 117
001D C2CF CLR TF2
; SOURCE LINE # 120
001F 750000 R MOV Index,#00H
0022 ?C0006:
; SOURCE LINE # 121
; SOURCE LINE # 123
0022 E500 R MOV A,Index
0024 75F008 MOV B,#08H
0027 A4 MUL AB
0028 2400 E ADD A,#LOW hSCH_tasks_G
002A F8 MOV R0,A
002B E6 MOV A,@R0
002C FE MOV R6,A
002D 08 INC R0
002E E6 MOV A,@R0
002F 4E ORL A,R6
0030 7003 JNZ $ + 5H
0032 020000 R LJMP ?C0008
; SOURCE LINE # 124
; SOURCE LINE # 125
0035 E500 R MOV A,Index
0037 75F008 MOV B,#08H
003A A4 MUL AB
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -