📄 2_01_12g.lst
字号:
=3 // Error codes
=3 // - see Chapter 14.
=3 //------------------------------------------------------------------
=3
=3 #define ERROR_SCH_TOO_MANY_TASKS (1)
=3 #define ERROR_SCH_CANNOT_DELETE_TASK (2)
=3
=3 #define ERROR_SCH_WAITING_FOR_SLAVE_TO_ACK (3)
=3 #define ERROR_SCH_WAITING_FOR_START_COMMAND_FROM_MASTER (3)
=3
=3 #define ERROR_SCH_ONE_OR_MORE_SLAVES_DID_NOT_START (4)
=3 #define ERROR_SCH_LOST_SLAVE (5)
=3
=3 #define ERROR_SCH_CAN_BUS_ERROR (6)
=3
=3 #define ERROR_I2C_WRITE_BYTE (10)
=3 #define ERROR_I2C_READ_BYTE (11)
=3 #define ERROR_I2C_WRITE_BYTE_AT24C64 (12)
=3 #define ERROR_I2C_READ_BYTE_AT24C64 (13)
=3 #define ERROR_I2C_DS1621 (14)
=3
=3 #define ERROR_USART_TI (21)
=3 #define ERROR_USART_WRITE_CHAR (22)
=3
=3 #define ERROR_SPI_EXCHANGE_BYTES_TIMEOUT (31)
=3 #define ERROR_SPI_X25_TIMEOUT (32)
=3 #define ERROR_SPI_MAX1110_TIMEOUT (33)
=3
=3 #define ERROR_ADC_MAX150_TIMEOUT (44)
=3
=3 #endif
115 =3
116 =3 /*------------------------------------------------------------------*-
117 =3 ---- END OF FILE -------------------------------------------------
118 =3 -*------------------------------------------------------------------*/
28 =2
29 =2 // ------ Public data type declarations ----------------------------
30 =2
31 =2 // Store in DATA area, if possible, for rapid access
32 =2 // Total memory per task is 7 bytes
33 =2 typedef data struct
34 =2 {
35 =2 // Pointer to the task (must be a 'void (void)' function)
36 =2 void (code * pTask)(void);
37 =2
38 =2 // Delay (ticks) until the function will (next) be run
39 =2 // - see SCH_Add_Task() for further details
40 =2 tWord Delay;
C51 COMPILER V6.10 2_01_12G 04/18/2001 16:18:09 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 } sTask;
49 =2
50 =2 // ------ Public function prototypes -------------------------------
51 =2
52 =2 // Core scheduler functions
53 =2 void SCH_Dispatch_Tasks(void);
54 =2 tByte SCH_Add_Task(void (code*) (void), const tWord, const tWord);
55 =2 bit SCH_Delete_Task(const tByte);
56 =2 void SCH_Report_Status(void);
57 =2
58 =2 // ------ Public constants -----------------------------------------
59 =2
60 =2 // The maximum number of tasks required at any one time
61 =2 // during the execution of the program
62 =2 //
63 =2 // MUST BE ADJUSTED FOR EACH NEW PROJECT
64 =2 #define SCH_MAX_TASKS (2)
65 =2
66 =2 #endif
67 =2
68 =2 /*------------------------------------------------------------------*-
69 =2 ---- END OF FILE -------------------------------------------------
70 =2 -*------------------------------------------------------------------*/
71 =2
26 =1
27 =1
28 =1 // ------ Public function prototypes -------------------------------
29 =1
30 =1 void SCH_Init_T2(void);
31 =1 void SCH_Start(void);
32 =1
33 =1 /*------------------------------------------------------------------*-
34 =1 ---- END OF FILE -------------------------------------------------
35 =1 -*------------------------------------------------------------------*/
36 =1
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
C51 COMPILER V6.10 2_01_12G 04/18/2001 16:18:09 PAGE 11
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);
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 // 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 SCH_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 SCH_Start(void)
99 {
100 1 EA = 1;
101 1 }
102
103 /*------------------------------------------------------------------*-
104
105 SCH_Update()
106
107 This is the scheduler ISR. It is called at a rate
108 determined by the timer settings in the 'init' function.
109
C51 COMPILER V6.10 2_01_12G 04/18/2001 16:18:09 PAGE 12
110 This version is triggered by Timer 2 interrupts:
111 timer is automatically reloaded.
112
113 -*------------------------------------------------------------------*/
114 void SCH_Update(void) interrupt INTERRUPT_Timer_2_Overflow
115 {
116 1 tByte Index;
117 1
118 1 TF2 = 0; // Have to manually clear this.
119 1
120 1 // NOTE: calculations are in *TICKS* (not milliseconds)
121 1 for (Index = 0; Index < SCH_MAX_TASKS; Index++)
122 1 {
123 2 // Check if there is a task at this location
124 2 if (SCH_tasks_G[Index].pTask)
125 2 {
126 3 if (SCH_tasks_G[Index].Delay == 0)
127 3 {
128 4 // The task is due to run
129 4 SCH_tasks_G[Index].RunMe += 1; // Inc. the 'RunMe' flag
130 4
131 4 if (SCH_tasks_G[Index].Period)
132 4 {
133 5 // Schedule regular tasks to run again
134 5 SCH_tasks_G[Index].Delay = SCH_tasks_G[Index].Period;
135 5 }
136 4 }
137 3 else
138 3 {
139 4 // Not yet ready to run: just decrement the delay
140 4 SCH_tasks_G[Index].Delay -= 1;
141 4 }
142 3 }
143 2 }
144 1 }
145
146
147 /*------------------------------------------------------------------*-
148 ---- END OF FILE -------------------------------------------------
149 -*------------------------------------------------------------------*/
150
C51 COMPILER V6.10 2_01_12G 04/18/2001 16:18:09 PAGE 13
ASSEMBLY LISTING OF GENERATED OBJECT CODE
; FUNCTION SCH_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 _SCH_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 SCH_Init_T2 (END)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -