📄 tlight_b.lst
字号:
53 =1 typedef unsigned char tByte;
54 =1 typedef unsigned int tWord;
55 =1 typedef unsigned long tLong;
56 =1
57 =1 // Misc #defines
58 =1 #ifndef TRUE
59 =1 #define FALSE 0
60 =1 #define TRUE (!FALSE)
61 =1 #endif
62 =1
63 =1 #define RETURN_NORMAL (bit) 0
64 =1 #define RETURN_ERROR (bit) 1
65 =1
66 =1
67 =1 //------------------------------------------------------------------
68 =1 // Interrupts
69 =1 // - see Chapter 13.
70 =1 //------------------------------------------------------------------
71 =1
72 =1 // Generic 8051/52 timer interrupts (used in most schedulers)
73 =1 #define INTERRUPT_Timer_0_Overflow 1
74 =1 #define INTERRUPT_Timer_1_Overflow 3
75 =1 #define INTERRUPT_Timer_2_Overflow 5
C51 COMPILER V6.10 TLIGHT_B 04/19/2001 14:10:30 PAGE 6
76 =1
77 =1 // Additional interrupts (used in shared-clock schedulers)
78 =1 #define INTERRUPT_EXTERNAL_0 0
79 =1 #define INTERRUPT_EXTERNAL_1 2
80 =1 #define INTERRUPT_UART_Rx_Tx 4
81 =1 #define INTERRUPT_CAN_c515c 17
82 =1
83 =1 //------------------------------------------------------------------
84 =1 // Error codes
85 =1 // - see Chapter 14.
86 =1 //------------------------------------------------------------------
87 =1
88 =1 #define ERROR_SCH_TOO_MANY_TASKS (1)
89 =1 #define ERROR_SCH_CANNOT_DELETE_TASK (2)
90 =1
91 =1 #define ERROR_SCH_WAITING_FOR_SLAVE_TO_ACK (3)
92 =1 #define ERROR_SCH_WAITING_FOR_START_COMMAND_FROM_MASTER (3)
93 =1
94 =1 #define ERROR_SCH_ONE_OR_MORE_SLAVES_DID_NOT_START (4)
95 =1 #define ERROR_SCH_LOST_SLAVE (5)
96 =1
97 =1 #define ERROR_SCH_CAN_BUS_ERROR (6)
98 =1
99 =1 #define ERROR_I2C_WRITE_BYTE (10)
100 =1 #define ERROR_I2C_READ_BYTE (11)
101 =1 #define ERROR_I2C_WRITE_BYTE_AT24C64 (12)
102 =1 #define ERROR_I2C_READ_BYTE_AT24C64 (13)
103 =1 #define ERROR_I2C_DS1621 (14)
104 =1
105 =1 #define ERROR_USART_TI (21)
106 =1 #define ERROR_USART_WRITE_CHAR (22)
107 =1
108 =1 #define ERROR_SPI_EXCHANGE_BYTES_TIMEOUT (31)
109 =1 #define ERROR_SPI_X25_TIMEOUT (32)
110 =1 #define ERROR_SPI_MAX1110_TIMEOUT (33)
111 =1
112 =1 #define ERROR_ADC_MAX150_TIMEOUT (44)
113 =1
114 =1 #endif
115 =1
116 =1 /*------------------------------------------------------------------*-
117 =1 ---- END OF FILE -------------------------------------------------
118 =1 -*------------------------------------------------------------------*/
28 #include "TLight_B.h"
1 =1 /*------------------------------------------------------------------*-
2 =1
3 =1 TLight_B.H (v1.00)
4 =1
5 =1 ------------------------------------------------------------------
6 =1
7 =1 - See TLight_B.C for details.
8 =1
9 =1
10 =1 COPYRIGHT
11 =1 ---------
12 =1
13 =1 This code is from the book:
14 =1
15 =1 PATTERNS FOR TIME-TRIGGERED EMBEDDED SYSTEMS by Michael J. Pont
16 =1 [Pearson Education, 2001; ISBN: 0-201-33138-1].
17 =1
18 =1 This code is copyright (c) 2001 by Michael J. Pont.
C51 COMPILER V6.10 TLIGHT_B 04/19/2001 14:10:30 PAGE 7
19 =1
20 =1 See book for copyright details and other information.
21 =1
22 =1 -*------------------------------------------------------------------*/
23 =1
24 =1 // ------ Public data type declarations ----------------------------
25 =1
26 =1 // Possible system states
27 =1 typedef
28 =1 enum {RED, RED_AMBER, GREEN, AMBER, BULB_BLOWN} eLight_State;
29 =1
30 =1
31 =1 // ------ Public constants -----------------------------------------
32 =1
33 =1 #define MASTER 1
34 =1 #define SLAVE 0
35 =1
36 =1 // ------ Public function prototypes -------------------------------
37 =1
38 =1 void TRAFFIC_LIGHTS_Init(void);
39 =1 void TRAFFIC_LIGHTS_Update(void);
40 =1
41 =1 void TRAFFIC_LIGHTS_Display_Safe_Output(void);
42 =1
43 =1 /*------------------------------------------------------------------*-
44 =1 ---- END OF FILE -------------------------------------------------
45 =1 -*------------------------------------------------------------------*/
29 #include "Port.h"
1 =1 /*------------------------------------------------------------------*-
2 =1
3 =1 Port.H (v1.00)
4 =1
5 =1 ------------------------------------------------------------------
6 =1
7 =1 'Port Header' (see Chap 10) for project SCC_m515 (see Chap 28)
8 =1
9 =1
10 =1 COPYRIGHT
11 =1 ---------
12 =1
13 =1 This code is from the book:
14 =1
15 =1 PATTERNS FOR TIME-TRIGGERED EMBEDDED SYSTEMS by Michael J. Pont
16 =1 [Pearson Education, 2001; ISBN: 0-201-33138-1].
17 =1
18 =1 This code is copyright (c) 2001 by Michael J. Pont.
19 =1
20 =1 See book for copyright details and other information.
21 =1
22 =1 -*------------------------------------------------------------------*/
23 =1
24 =1 // ------ Sch51.C ----------------------------------------
25 =1
26 =1 // Comment this line out if error reporting is NOT required
27 =1 //#define SCH_REPORT_ERRORS
28 =1
29 =1 #ifdef SCH_REPORT_ERRORS
=1 // The port on which error codes will be displayed
=1 // ONLY USED IF ERRORS ARE REPORTED
=1 #define Error_port P1
=1
=1 #endif
C51 COMPILER V6.10 TLIGHT_B 04/19/2001 14:10:30 PAGE 8
35 =1
36 =1 // ------ SCC_M.C ------------------------------------------------
37 =1
38 =1 // *****************************************************************
39 =1 // P4.6, 4.7 used for CAN outputs
40 =1 // *****************************************************************
41 =1
42 =1 // Connect LED from +5V (etc) to these pins, via appropriate resistor
43 =1 sbit Network_error_pin = P4^4;
44 =1
45 =1 // Three pins used to report CAN bus errors
46 =1 sbit CAN_error_pin0 = P5^3;
47 =1 sbit CAN_error_pin1 = P5^4;
48 =1 sbit CAN_error_pin2 = P5^5;
49 =1
50 =1
51 =1 // ------ TLights_B.C ----------------------------------------------
52 =1
53 =1 sbit Red_light = (P4^0);
54 =1 sbit Amber_light = (P4^1);
55 =1 sbit Green_light = (P4^2);
56 =1
57 =1
58 =1 // ------ LED_Flas.C -----------------------------------------------
59 =1
60 =1 // Connect LED from +5V (etc) to this pin, via appropriate resistor
61 =1 // [see Chapter 7 for details]
62 =1 sbit LED_pin = P4^3;
63 =1
64 =1
65 =1 /*------------------------------------------------------------------*-
66 =1 ---- END OF FILE -------------------------------------------------
67 =1 -*------------------------------------------------------------------*/
68 =1
69 =1
70 =1
30
31 // ------ Private constants ----------------------------------------
32
33 // Easy to change logic here
34 #define ON 0
35 #define OFF 1
36
37 // Times in each of the (four) possible light states
38 // (Times are in seconds - must call the update task once per second)
39 //
40 #define RED_DURATION (10)
41 #define RED_AND_AMBER_DURATION (10)
42
43 // NOTE:
44 // GREEN_DURATION must equal RED_DURATION
45 // AMBER_DURATION must equal RED_AND_AMBER_DURATION
46 #define GREEN_DURATION RED_DURATION
47 #define AMBER_DURATION RED_AND_AMBER_DURATION
48
49 // Must specify whether this is a MASTER or a SLAVE unit
50 #define MASTER_SLAVE MASTER
51
52 // ------ Public variable declarations -----------------------------
53
54 extern tByte Tick_message_data_G;
55 extern tByte Ack_message_data_G;
C51 COMPILER V6.10 TLIGHT_B 04/19/2001 14:10:30 PAGE 9
56
57 // ------ Private variables ----------------------------------------
58
59 // The state of the system
60 static eLight_State Light_state_G;
61
62 // ------ Private function prototypes ------------------------------
63
64 bit TRAFFIC_LIGHTS_Check_for_Hardware_Faults(void) reentrant;
65 bit TRAFFIC_LIGHTS_Check_Local_Bulb(void);
66
67 /*------------------------------------------------------------------*-
68
69 TRAFFIC_LIGHTS_Init()
70
71 Prepare for scheduling.
72
73 -*-----------------------------------------------------------------*/
74 void TRAFFIC_LIGHTS_Init(void)
75 {
76 1 // Master and slave must start in opposite states
77 1 if (MASTER_SLAVE == MASTER)
78 1 {
79 2 Light_state_G = RED;
80 2 }
81 1 else
82 1 {
83 2 Light_state_G = GREEN;
84 2 }
85 1
86 1 // Display safe output until scheduler starts
87 1 TRAFFIC_LIGHTS_Display_Safe_Output();
88 1 }
89
90 /*------------------------------------------------------------------*-
91
92 TRAFFIC_LIGHTS_Update()
93
94 Must be scheduled once per second.
95
96 -*------------------------------------------------------------------*/
97 void TRAFFIC_LIGHTS_Update(void)
98 {
99 1 static tWord Time_in_state;
100 1
101 1 // Check for blown bulbs on master or slave
102 1 TRAFFIC_LIGHTS_Check_for_Hardware_Faults();
103 1
104 1 // This is the main update code
105 1 switch (Light_state_G)
106 1 {
107 2 case RED:
108 2 {
109 3 Red_light = ON;
110 3 Amber_light = OFF;
111 3 Green_light = OFF;
112 3
113 3 if (++Time_in_state == RED_DURATION)
114 3 {
115 4 Light_state_G = RED_AMBER;
116 4 Time_in_state = 0;
117 4 }
C51 COMPILER V6.10 TLIGHT_B 04/19/2001 14:10:30 PAGE 10
118 3
119 3 break;
120 3 }
121 2
122 2 case RED_AMBER:
123 2 {
124 3 Red_light = ON;
125 3 Amber_light = ON;
126 3 Green_light = OFF;
127 3
128 3 if (++Time_in_state == RED_AND_AMBER_DURATION)
129 3 {
130 4 Light_state_G = GREEN;
131 4 Time_in_state = 0;
132 4 }
133 3
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -