Skip to content

Commit 9e6ce6c

Browse files
committed
v.0.1
1 parent 98363e8 commit 9e6ce6c

9 files changed

Lines changed: 401 additions & 355 deletions

File tree

Listings/main.lst

Lines changed: 169 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -1,204 +1,199 @@
1-
C51 COMPILER V9.59.0.0 MAIN 09/10/2018 02:34:02 PAGE 1
1+
C51 COMPILER V9.59.0.0 MAIN 09/10/2018 05:10:32 PAGE 1
22

33

44
C51 COMPILER V9.59.0.0, COMPILATION OF MODULE MAIN
55
OBJECT MODULE PLACED IN .\Objects\main.obj
6-
COMPILER INVOKED BY: C:\Program Files\Keil\C51\BIN\C51.EXE main.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Li
6+
COMPILER INVOKED BY: C:\Program Files\Keil\C51\BIN\C51.EXE main.c OPTIMIZE(0,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Li
77
-stings\main.lst) TABS(2) OBJECT(.\Objects\main.obj)
88

99
line level source
1010

1111
1 #include <STC15F2K60S2.h>
1212
2 #include <intrins.h>
1313
3
14-
4 #define O_BOOST P35
15-
5 #define I_AVR_ONLINE P33 // PD2
16-
6 #define O_AVR_BUTTON P32 // PD1
17-
7 #define I_BUTTON P34
18-
8
19-
9 // states
20-
10 #define SLEEP 0
21-
11 #define BOOT 1
22-
12 #define ONLINE 2
23-
13
24-
14 #define LOW 0
25-
15 #define HIGH 1
26-
16
27-
17 int state;
28-
18 int button_changed;
29-
19 int button_state;
30-
20
31-
21 int avr_online_state;
32-
22
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;
3333
23
3434
24
35-
25
36-
26 void timer0_ISR (void) interrupt 1
37-
27 {
38-
28 1 static float avg_button = 10;
39-
29 1 static float avg_avr_online = 10;
40-
30 1
41-
31 1 int new_button_state;
42-
32 1 int new_avr_online_state;
43-
33 1
44-
34 1 // Increment Counter to shorten overflow time
45-
35 1 //TH0 = (65536 - 1000)/256; // TODO: Calculation?! Old: 1ms = 1000MZ, davon das High-Byte in TH0
46-
36 1 //TL0 = (65536 - 1000)%256; // das Low-Byte in TL0
47-
37 1
48-
38 1 // Button entprellen
49-
39 1
50-
40 1
51-
41 1
52-
42 1 avg_button = (avg_button * 9+I_BUTTON * 10) / 10;
53-
43 1 avg_avr_online = (avg_avr_online * 9+I_AVR_ONLINE * 10) / 10;
54-
44 1
55-
45 1 if (avg_button > 5) {
56-
46 2 new_button_state = HIGH;
57-
47 2 } else {
58-
48 2 new_button_state = LOW;
59-
49 2 }
60-
50 1
61-
51 1 if (avg_avr_online > 5) {
62-
52 2 new_avr_online_state = HIGH;
63-
53 2 } else {
64-
54 2 new_avr_online_state = LOW;
65-
C51 COMPILER V9.59.0.0 MAIN 09/10/2018 02:34:02 PAGE 2
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;
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
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 }
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
6666

67-
55 2 }
68-
56 1
69-
57 1 if (new_button_state != button_state) {
70-
58 2 button_state = new_button_state;
71-
59 2 button_changed = 1;
72-
60 2 }
73-
61 1
74-
62 1 if (new_avr_online_state != avr_online_state) {
75-
63 2 avr_online_state = new_avr_online_state;
76-
64 2 }
77-
65 1
78-
66 1 }
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
7979
67
80-
68
81-
69 void setup()
82-
70 {
83-
71 1 // P33 (I_AVR_ONLINE) to Input only
84-
72 1 P3M0 &= ~(0 << 3);
85-
73 1 P3M1 |= 1 << 3;
86-
74 1
87-
75 1 // P34 (I_BUTTON) to Input only
88-
76 1 P3M0 &= ~(0 << 4);
89-
77 1 P3M1 |= 1 << 4;
90-
78 1
91-
79 1 // P35 (O_BOOST) to PushPull Output
92-
80 1 P3M0 |= 1 << 5;
93-
81 1 P3M1 &= ~(0 << 5);
94-
82 1
95-
83 1 // P32 (O_AVR_BUTTON) to PushPull Output
96-
84 1 P3M0 |= 1 << 2;
97-
85 1 P3M1 &= ~(0 << 2);
98-
86 1
99-
87 1 // initial states
100-
88 1 state = SLEEP;
101-
89 1 button_changed = 0;
102-
90 1 button_state = HIGH;
103-
91 1 avr_online_state = LOW;
104-
92 1
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);
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
105105
93 1 O_AVR_BUTTON = HIGH;
106106
94 1 O_BOOST = LOW;
107-
95 1
108-
96 1 // Timers
109-
97 1 TMOD = (TMOD & 0xF0) | 0x01; // Set T/C0 Mode 1, 16Bit, No Auto Reload
110-
98 1 ET0 = 1; // Enable Timer 0 Interrupts
111-
99 1 TR0 = 1; // Start Timer 0 Running
112-
100 1 EA = 1; // Global Interrupt Enable
113-
101 1
114-
102 1 }
115-
103
116-
104 void delay(int ms)
117-
105 {
118-
106 1 unsigned int j = 0;
119-
107 1 unsigned int g = 0;
120-
108 1 for(j=0;j<ms;j++)
121-
109 1 {
122-
110 2 for(g=0;g<600;g++)
123-
111 2 {
124-
112 3 _nop_();
125-
113 3 _nop_();
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 {
126126
114 3 _nop_();
127127
115 3 _nop_();
128128
116 3 _nop_();
129-
C51 COMPILER V9.59.0.0 MAIN 09/10/2018 02:34:02 PAGE 3
129+
C51 COMPILER V9.59.0.0 MAIN 09/10/2018 05:10:32 PAGE 3
130130

131-
117 3 }
132-
118 2 }
133-
119 1 }
134-
120
135-
121 void main()
136-
122 {
137-
123 1 setup();
138-
124 1
139-
125 1 delay(5000);
140-
126 1 O_AVR_BUTTON = LOW;
141-
127 1 O_BOOST = HIGH;
142-
128 1 delay(500);
143-
129 1 O_AVR_BUTTON = HIGH;
144-
130 1
145-
131 1 while(1){}
146-
132 1
147-
133 1
148-
134 1 /*
149-
135 1 while(1)
150-
136 1 {
151-
137 1
152-
138 1 O_AVR_BUTTON = button_state;
153-
139 1
154-
140 1
155-
141 1 switch (state) {
156-
142 1 case SLEEP:
157-
143 1
158-
144 1 // POWER SAVING OPTIONS,
159-
145 1 // deactivate timer, enable interrupt2, ...
160-
146 1
161-
147 1 if (button_changed && button_state == LOW) {
162-
148 1 button_changed = 0;
163-
149 1 O_BOOST = HIGH;
164-
150 1 state = BOOT;
165-
151 1 }
166-
152 1 break;
167-
153 1
168-
154 1 case BOOT:
169-
155 1 if (avr_online_state == HIGH)
170-
156 1 state = ONLINE;
171-
157 1
172-
158 1 // TODO: Timeout
173-
159 1
174-
160 1 break;
175-
161 1
176-
162 1 case ONLINE:
177-
163 1 if (avr_online_state == LOW) {
178-
164 1 O_BOOST = LOW;
179-
165 1 state = SLEEP;
180-
166 1 }
181-
167 1 break;
182-
168 1
183-
169 1 default:
184-
170 1 break;
185-
171 1 }
186-
172 1
187-
173 1 }
188-
174 1 */
189-
175 1 }
190-
176
191-
177
192-
193-
C51 COMPILER V9.59.0.0 MAIN 09/10/2018 02:34:02 PAGE 4
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 }
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 }
194187

195188

196189
MODULE INFORMATION: STATIC OVERLAYABLE
197-
CODE SIZE = 433 ----
190+
CODE SIZE = 610 ----
198191
CONSTANT SIZE = ---- ----
199192
XDATA SIZE = ---- ----
193+
C51 COMPILER V9.59.0.0 MAIN 09/10/2018 05:10:32 PAGE 4
194+
200195
PDATA SIZE = ---- ----
201-
DATA SIZE = 16 4
196+
DATA SIZE = 26 ----
202197
IDATA SIZE = ---- ----
203198
BIT SIZE = ---- ----
204199
END OF MODULE INFORMATION.

0 commit comments

Comments
 (0)