Skip to content

Commit 65e7472

Browse files
committed
first commit
0 parents  commit 65e7472

12 files changed

Lines changed: 3563 additions & 0 deletions

File tree

Listings/main.lst

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
C51 COMPILER V9.59.0.0 MAIN 09/10/2018 02:34:02 PAGE 1
2+
3+
4+
C51 COMPILER V9.59.0.0, COMPILATION OF MODULE MAIN
5+
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
7+
-stings\main.lst) TABS(2) OBJECT(.\Objects\main.obj)
8+
9+
line level source
10+
11+
1 #include <STC15F2K60S2.h>
12+
2 #include <intrins.h>
13+
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
33+
23
34+
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
66+
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 }
79+
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
105+
93 1 O_AVR_BUTTON = HIGH;
106+
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_();
126+
114 3 _nop_();
127+
115 3 _nop_();
128+
116 3 _nop_();
129+
C51 COMPILER V9.59.0.0 MAIN 09/10/2018 02:34:02 PAGE 3
130+
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
194+
195+
196+
MODULE INFORMATION: STATIC OVERLAYABLE
197+
CODE SIZE = 433 ----
198+
CONSTANT SIZE = ---- ----
199+
XDATA SIZE = ---- ----
200+
PDATA SIZE = ---- ----
201+
DATA SIZE = 16 4
202+
IDATA SIZE = ---- ----
203+
BIT SIZE = ---- ----
204+
END OF MODULE INFORMATION.
205+
206+
207+
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)

0 commit comments

Comments
 (0)