|
1 | | -C51 COMPILER V9.59.0.0 MAIN 09/10/2018 05:10:32 PAGE 1 |
| 1 | +C51 COMPILER V9.59.0.0 MAIN 09/10/2018 13:33:18 PAGE 1 |
2 | 2 |
|
3 | 3 |
|
4 | 4 | C51 COMPILER V9.59.0.0, COMPILATION OF MODULE MAIN |
5 | 5 | OBJECT MODULE PLACED IN .\Objects\main.obj |
6 | | -COMPILER INVOKED BY: C:\Program Files\Keil\C51\BIN\C51.EXE main.c OPTIMIZE(0,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Li |
| 6 | +COMPILER INVOKED BY: C:\Program Files\Keil\C51\BIN\C51.EXE main.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Li |
7 | 7 | -stings\main.lst) TABS(2) OBJECT(.\Objects\main.obj) |
8 | 8 |
|
9 | 9 | line level source |
10 | 10 |
|
11 | 11 | 1 #include <STC15F2K60S2.h> |
12 | 12 | 2 #include <intrins.h> |
13 | 13 | 3 |
14 | | - 4 #define LOW 0 |
15 | | - 5 #define HIGH 1 |
16 | | - 6 |
17 | | - 7 // I/O Ports |
18 | | - 8 #define I_BUTTON P34 |
19 | | - 9 #define I_AVR_ONLINE P33 // PD2 |
20 | | - 10 #define O_BOOST P35 |
21 | | - 11 #define O_AVR_BUTTON P32 // PD1 |
22 | | - 12 |
23 | | - 13 // States |
24 | | - 14 #define SLEEP 0 |
25 | | - 15 #define BOOT 1 |
26 | | - 16 #define ONLINE 2 |
27 | | - 17 |
28 | | - 18 |
29 | | - 19 volatile int state; |
30 | | - 20 volatile int button_changed; |
31 | | - 21 volatile int button_state; |
32 | | - 22 volatile int avr_online_state; |
33 | | - 23 |
34 | | - 24 |
35 | | - 25 void timer0_ISR (void) interrupt 1 |
36 | | - 26 { |
37 | | - 27 1 static float avg_button = 100; |
38 | | - 28 1 static float avg_avr_online = 100; |
39 | | - 29 1 |
40 | | - 30 1 int new_button_state; |
41 | | - 31 1 int new_avr_online_state; |
| 14 | + 4 #define LOW 0 |
| 15 | + 5 #define HIGH 1 |
| 16 | + 6 #define FALSE 0 |
| 17 | + 7 #define TRUE 1 |
| 18 | + 8 |
| 19 | + 9 // I/O Ports |
| 20 | + 10 #define I_BUTTON P34 |
| 21 | + 11 #define I_AVR_ONLINE P33 // PD2 |
| 22 | + 12 #define O_BOOST P35 |
| 23 | + 13 #define O_AVR_BUTTON P32 // PD1 |
| 24 | + 14 |
| 25 | + 15 // States |
| 26 | + 16 #define SLEEP 0 |
| 27 | + 17 #define BOOT 1 |
| 28 | + 18 #define ONLINE 2 |
| 29 | + 19 |
| 30 | + 20 #define CLR_BIT(p,n) ((p) &= ~(1 << (n))) |
| 31 | + 21 #define SET_BIT(p,n) ((p) |= (1 << (n))) |
| 32 | + 22 |
| 33 | + 23 volatile int state; |
| 34 | + 24 volatile int button_changed; |
| 35 | + 25 volatile int button_state; |
| 36 | + 26 volatile int avr_online_state; |
| 37 | + 27 |
| 38 | + 28 void timer0_ISR (void) interrupt 1 |
| 39 | + 29 { |
| 40 | + 30 1 static float avg_button = 10; |
| 41 | + 31 1 static float avg_avr_online = 10; |
42 | 42 | 32 1 |
43 | | - 33 1 // Increment Counter to shorten overflow time |
44 | | - 34 1 TH0 = (65536 - 1000)/256; // TODO: Calculation?! Old: 1ms = 1000MZ, davon das High-Byte in TH0 |
45 | | - 35 1 TL0 = (65536 - 1000)%256; // das Low-Byte in TL0 |
46 | | - 36 1 |
47 | | - 37 1 // Button entprellen |
48 | | - 38 1 |
| 43 | + 33 1 int new_button_state; |
| 44 | + 34 1 int new_avr_online_state; |
| 45 | + 35 1 |
| 46 | + 36 1 // Increment Counter to shorten overflow time |
| 47 | + 37 1 TH0 = (65536 - 1000) / 256; // TODO: Calculation?! Old: 1ms = 1000MZ, davon das High-Byte in TH0 |
| 48 | + 38 1 TL0 = (65536 - 1000) % 256; // das Low-Byte in TL0 |
49 | 49 | 39 1 |
50 | | - 40 1 avg_button = (avg_button * 9 + I_BUTTON * 100) / 10; |
51 | | - 41 1 avg_avr_online = (avg_avr_online * 9 + I_AVR_ONLINE * 100) / 10; |
52 | | - 42 1 |
53 | | - 43 1 if (avg_button > 50) { |
54 | | - 44 2 new_button_state = HIGH; |
55 | | - 45 2 } else { |
56 | | - 46 2 new_button_state = LOW; |
57 | | - 47 2 } |
| 50 | + 40 1 // Button debouncing using exponential moving average |
| 51 | + 41 1 // avg = alpha * avg + (1 - alpha) * input, alpha < 1 |
| 52 | + 42 1 // TODO: inefficient, replace |
| 53 | + 43 1 avg_button = 0.9 * avg_button + 0.1 * (I_BUTTON * 10); |
| 54 | + 44 1 avg_avr_online = 0.9 * avg_avr_online + 0.1 * (I_AVR_ONLINE * 10); |
| 55 | + 45 1 |
| 56 | + 46 1 (avg_button > 5) ? (new_button_state = HIGH) : (new_button_state = LOW); |
| 57 | + 47 1 (avg_avr_online > 5) ? (new_avr_online_state = HIGH) : (new_avr_online_state = LOW); |
58 | 58 | 48 1 |
59 | | - 49 1 if (avg_avr_online > 50) { |
60 | | - 50 2 new_avr_online_state = HIGH; |
61 | | - 51 2 } else { |
62 | | - 52 2 new_avr_online_state = LOW; |
63 | | - 53 2 } |
64 | | - 54 1 |
65 | | -C51 COMPILER V9.59.0.0 MAIN 09/10/2018 05:10:32 PAGE 2 |
| 59 | + 49 1 if (new_button_state != button_state) { |
| 60 | + 50 2 button_state = new_button_state; |
| 61 | + 51 2 button_changed = 1; |
| 62 | + 52 2 } else { |
| 63 | + 53 2 button_changed = 0; |
| 64 | + 54 2 } |
| 65 | +C51 COMPILER V9.59.0.0 MAIN 09/10/2018 13:33:18 PAGE 2 |
66 | 66 |
|
67 | 67 | 55 1 |
68 | | - 56 1 if (new_button_state != button_state) { |
69 | | - 57 2 button_state = new_button_state; |
70 | | - 58 2 button_changed = 1; |
71 | | - 59 2 } |
72 | | - 60 1 |
73 | | - 61 1 if (new_avr_online_state != avr_online_state) { |
74 | | - 62 2 avr_online_state = new_avr_online_state; |
75 | | - 63 2 } |
76 | | - 64 1 |
77 | | - 65 1 } |
78 | | - 66 |
79 | | - 67 |
80 | | - 68 void setup() |
81 | | - 69 { |
82 | | - 70 1 // P33 (I_AVR_ONLINE) to Input only (HiZ) |
83 | | - 71 1 //P3M0 &= ~(0 << 3); |
84 | | - 72 1 //P3M1 |= 1 << 3; |
85 | | - 73 1 |
86 | | - 74 1 // P34 (I_BUTTON) to Input only (HiZ) |
87 | | - 75 1 //P3M0 &= ~(0 << 4); |
88 | | - 76 1 //P3M1 |= 1 << 4; |
89 | | - 77 1 |
90 | | - 78 1 // P35 (O_BOOST) to PushPull Output |
91 | | - 79 1 P3M0 |= 1 << 5; |
92 | | - 80 1 P3M1 &= ~(0 << 5); |
| 68 | + 56 1 if (new_avr_online_state != avr_online_state) { |
| 69 | + 57 2 avr_online_state = new_avr_online_state; |
| 70 | + 58 2 } |
| 71 | + 59 1 } |
| 72 | + 60 |
| 73 | + 61 |
| 74 | + 62 void setup() |
| 75 | + 63 { |
| 76 | + 64 1 // Keep P33 (I_AVR_ONLINE) and P34 (I_BUTTON) as Quasi-Bidirectional |
| 77 | + 65 1 // since we need the internal PullUps |
| 78 | + 66 1 |
| 79 | + 67 1 // P35 (O_BOOST): PushPull Output |
| 80 | + 68 1 SET_BIT(P3M0, 5); // P3M0 |= 1 << 5; |
| 81 | + 69 1 CLR_BIT(P3M1, 5); // P3M1 &= ~(0 << 5); |
| 82 | + 70 1 |
| 83 | + 71 1 // P32 (O_AVR_BUTTON): PushPull Output |
| 84 | + 72 1 SET_BIT(P3M1, 2); // P3M0 |= 1 << 2; |
| 85 | + 73 1 CLR_BIT(P3M1, 2); // P3M1 &= ~(0 << 2); |
| 86 | + 74 1 |
| 87 | + 75 1 // Init States |
| 88 | + 76 1 state = SLEEP; |
| 89 | + 77 1 |
| 90 | + 78 1 button_changed = FALSE; |
| 91 | + 79 1 button_state = HIGH; |
| 92 | + 80 1 avr_online_state = LOW; |
93 | 93 | 81 1 |
94 | | - 82 1 // P32 (O_AVR_BUTTON) to PushPull Output |
95 | | - 83 1 P3M0 |= 1 << 2; |
96 | | - 84 1 P3M1 &= ~(0 << 2); |
97 | | - 85 1 |
98 | | - 86 1 // Init States |
99 | | - 87 1 state = SLEEP; |
100 | | - 88 1 button_changed = 0; |
101 | | - 89 1 button_state = HIGH; |
102 | | - 90 1 avr_online_state = LOW; |
103 | | - 91 1 |
104 | | - 92 1 // Init I/O's |
105 | | - 93 1 O_AVR_BUTTON = HIGH; |
106 | | - 94 1 O_BOOST = LOW; |
107 | | - 95 1 I_BUTTON = 1; // quasi-bidirectional => pullups! |
108 | | - 96 1 I_AVR_ONLINE = 1; // quasi-bidirectional => pullups! |
109 | | - 97 1 |
110 | | - 98 1 // Timers |
111 | | - 99 1 TMOD = (TMOD & 0xF0) | 0x01; // Set T/C0 Mode 1, 16Bit, No Auto Reload |
112 | | - 100 1 ET0 = 1; // Enable Timer 0 Interrupts |
113 | | - 101 1 TR0 = 1; // Start Timer 0 Running |
114 | | - 102 1 EA = 1; // Global Interrupt Enable |
115 | | - 103 1 |
116 | | - 104 1 } |
117 | | - 105 |
118 | | - 106 void delay(int ms) |
119 | | - 107 { |
120 | | - 108 1 unsigned int j = 0; |
121 | | - 109 1 unsigned int g = 0; |
122 | | - 110 1 for(j=0;j<ms;j++) |
123 | | - 111 1 { |
124 | | - 112 2 for(g=0;g<600;g++) |
125 | | - 113 2 { |
126 | | - 114 3 _nop_(); |
127 | | - 115 3 _nop_(); |
128 | | - 116 3 _nop_(); |
129 | | -C51 COMPILER V9.59.0.0 MAIN 09/10/2018 05:10:32 PAGE 3 |
| 94 | + 82 1 // Init I/O's |
| 95 | + 83 1 O_AVR_BUTTON = HIGH; |
| 96 | + 84 1 O_BOOST = LOW; |
| 97 | + 85 1 I_BUTTON = HIGH; // set to weak high => pullups! |
| 98 | + 86 1 I_AVR_ONLINE = HIGH; // set to weak high => pullups! |
| 99 | + 87 1 |
| 100 | + 88 1 // Timers |
| 101 | + 89 1 TMOD = (TMOD & 0xF0) | 0x01; // Set T/C0 Mode 1, 16Bit, Manual Reload |
| 102 | + 90 1 ET0 = 1; // Enable Timer 0 Interrupts |
| 103 | + 91 1 TR0 = 1; // Start Timer 0 Running |
| 104 | + 92 1 EA = 1; // Global Interrupt Enable |
| 105 | + 93 1 } |
| 106 | + 94 |
| 107 | + 95 void delay(int ms) |
| 108 | + 96 { |
| 109 | + 97 1 unsigned int j = 0; |
| 110 | + 98 1 unsigned int g = 0; |
| 111 | + 99 1 for(j=0;j<ms;j++) |
| 112 | + 100 1 { |
| 113 | + 101 2 for(g=0;g<600;g++) |
| 114 | + 102 2 { |
| 115 | + 103 3 _nop_(); |
| 116 | + 104 3 _nop_(); |
| 117 | + 105 3 _nop_(); |
| 118 | + 106 3 _nop_(); |
| 119 | + 107 3 _nop_(); |
| 120 | + 108 3 } |
| 121 | + 109 2 } |
| 122 | + 110 1 } |
| 123 | + 111 |
| 124 | + 112 void main() |
| 125 | + 113 { |
| 126 | + 114 1 setup(); |
| 127 | + 115 1 |
| 128 | + 116 1 while(1) |
| 129 | +C51 COMPILER V9.59.0.0 MAIN 09/10/2018 13:33:18 PAGE 3 |
130 | 130 |
|
131 | | - 117 3 _nop_(); |
132 | | - 118 3 _nop_(); |
133 | | - 119 3 } |
134 | | - 120 2 } |
135 | | - 121 1 } |
136 | | - 122 |
137 | | - 123 void main() |
138 | | - 124 { |
139 | | - 125 1 setup(); |
140 | | - 126 1 |
141 | | - 127 1 while(1) |
142 | | - 128 1 { |
143 | | - 129 2 switch (state) { |
144 | | - 130 3 case SLEEP: |
145 | | - 131 3 |
146 | | - 132 3 // TODO: POWER SAVING OPTIONS |
147 | | - 133 3 // deactivate timer, enable interrupt2, ... |
148 | | - 134 3 |
149 | | - 135 3 if (button_changed && button_state == LOW) { |
150 | | - 136 4 button_changed = 0; |
151 | | - 137 4 O_AVR_BUTTON = LOW; |
152 | | - 138 4 delay(1); // otherwise the fw hangs up |
153 | | - 139 4 O_BOOST = HIGH; |
154 | | - 140 4 state = BOOT; |
155 | | - 141 4 } |
| 131 | + 117 1 { |
| 132 | + 118 2 switch (state) { |
| 133 | + 119 3 case SLEEP: |
| 134 | + 120 3 // TODO: POWER SAVING OPTIONS |
| 135 | + 121 3 // deactivate timer, enable interrupt2, ... |
| 136 | + 122 3 |
| 137 | + 123 3 if (button_changed && button_state == LOW) { |
| 138 | + 124 4 O_AVR_BUTTON = LOW; |
| 139 | + 125 4 delay(1); // otherwise the fw hangs up |
| 140 | + 126 4 O_BOOST = HIGH; |
| 141 | + 127 4 state = BOOT; |
| 142 | + 128 4 } |
| 143 | + 129 3 break; |
| 144 | + 130 3 |
| 145 | + 131 3 case BOOT: |
| 146 | + 132 3 O_AVR_BUTTON = button_state; |
| 147 | + 133 3 |
| 148 | + 134 3 if (avr_online_state == HIGH) |
| 149 | + 135 3 state = ONLINE; |
| 150 | + 136 3 |
| 151 | + 137 3 // TODO: Timeout |
| 152 | + 138 3 break; |
| 153 | + 139 3 |
| 154 | + 140 3 case ONLINE: |
| 155 | + 141 3 O_AVR_BUTTON = button_state; |
156 | 156 | 142 3 |
157 | | - 143 3 |
158 | | - 144 3 break; |
159 | | - 145 3 |
160 | | - 146 3 case BOOT: |
161 | | - 147 3 O_AVR_BUTTON = button_state; |
162 | | - 148 3 |
163 | | - 149 3 if (avr_online_state == HIGH) |
164 | | - 150 3 state = ONLINE; |
165 | | - 151 3 |
166 | | - 152 3 // TODO: Timeout |
167 | | - 153 3 |
168 | | - 154 3 break; |
169 | | - 155 3 |
170 | | - 156 3 case ONLINE: |
171 | | - 157 3 O_AVR_BUTTON = button_state; |
172 | | - 158 3 |
173 | | - 159 3 if (avr_online_state == LOW) { |
174 | | - 160 4 O_BOOST = LOW; |
175 | | - 161 4 state = SLEEP; |
176 | | - 162 4 button_changed = 0; // clear the button event, otherwise you cannot shut down |
177 | | - 163 4 } |
178 | | - 164 3 break; |
179 | | - 165 3 |
180 | | - 166 3 default: |
181 | | - 167 3 break; |
182 | | - 168 3 } |
183 | | - 169 2 |
184 | | - 170 2 } |
185 | | - 171 1 |
186 | | - 172 1 } |
| 157 | + 143 3 if (avr_online_state == LOW) { |
| 158 | + 144 4 O_BOOST = LOW; |
| 159 | + 145 4 state = SLEEP; |
| 160 | + 146 4 } |
| 161 | + 147 3 break; |
| 162 | + 148 3 |
| 163 | + 149 3 default: |
| 164 | + 150 3 state = SLEEP; |
| 165 | + 151 3 break; |
| 166 | + 152 3 } |
| 167 | + 153 2 |
| 168 | + 154 2 } |
| 169 | + 155 1 |
| 170 | + 156 1 } |
187 | 171 |
|
188 | 172 |
|
189 | 173 | MODULE INFORMATION: STATIC OVERLAYABLE |
190 | | - CODE SIZE = 610 ---- |
| 174 | + CODE SIZE = 529 ---- |
191 | 175 | CONSTANT SIZE = ---- ---- |
192 | 176 | XDATA SIZE = ---- ---- |
193 | | -C51 COMPILER V9.59.0.0 MAIN 09/10/2018 05:10:32 PAGE 4 |
194 | | - |
195 | 177 | PDATA SIZE = ---- ---- |
196 | | - DATA SIZE = 26 ---- |
| 178 | + DATA SIZE = 16 4 |
197 | 179 | IDATA SIZE = ---- ---- |
198 | 180 | BIT SIZE = ---- ---- |
199 | 181 | END OF MODULE INFORMATION. |
|
0 commit comments