Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
282 | grottenfli | 1 | // |
2 | // Grottenflieger hat: Nisthakens main.c angepasst auf PCB version 2.2 |
||
3 | // |
||
4 | |||
5 | #include <avr/io.h> |
||
6 | #include <util/delay.h> |
||
7 | #include <stdint.h> |
||
8 | #include <avr/interrupt.h> |
||
9 | |||
10 | void sleep_ms(uint16_t ms); |
||
11 | |||
12 | #define LED_WS PB2 // LED port 1 |
||
13 | #define LED_BL PC1 // LED port 2 |
||
14 | #define LED_BLITZRT PC2 // LED port 3 |
||
15 | #define LED_BLITZGN PC3 // LED port 4 |
||
16 | #define LED_PORT5 PC4 // LED port 5 |
||
17 | #define LED_HINTENGN PC5 // LED port 6 |
||
18 | #define LED_HINTENRT PD4 // LED port 7 |
||
19 | #define LED_VORNEGN PD5 // LED port 8 |
||
20 | #define LED_UNTENGB PD6 // LED port 9 |
||
21 | #define LED_VORNERT PD7 // LED port 10 |
||
22 | #define LED_STATUS PB0 // LED blau - on board |
||
23 | |||
24 | #define STATUS_OFF PORTB |= (1<<LED_STATUS) //Den Portpin auf high setzen |
||
25 | #define STATUS_ON PORTB &= ~(1<<LED_STATUS) //Den Portpin auf low setzen |
||
26 | #define STATUS_TOGGLE PORTB ^= ~(1<<LED_STATUS) //Den Portpin toggeln |
||
27 | |||
28 | #define WEISS_ON PORTB |= (1<<LED_WS) //Den Portpin auf high setzen |
||
29 | #define WEISS_OFF PORTB &= ~(1<<LED_WS) //Den Portpin auf low setzen |
||
30 | |||
31 | #define PORT5_ON PORTC |= (1<<LED_PORT5) //Den Portpin auf high setzen |
||
32 | #define PORT5_OFF PORTC &= ~(1<<LED_PORT5) //Den Portpin auf low setzen |
||
33 | |||
34 | #define BLITZGN_ON PORTC |= (1<<LED_BLITZGN) //Den Portpin auf high setzen |
||
35 | #define BLITZGN_OFF PORTC &= ~(1<<LED_BLITZGN) //Den Portpin auf low setzen |
||
36 | #define BLITZRT_ON PORTC |= (1<<LED_BLITZRT) //Den Portpin auf high setzen |
||
37 | #define BLITZRT_OFF PORTC &= ~(1<<LED_BLITZRT) //Den Portpin auf low setzen |
||
38 | #define BLAU_ON PORTC |= (1<<LED_BL) //Den Portpin auf high setzen |
||
39 | #define BLAU_OFF PORTC &= ~(1<<LED_BL) //Den Portpin auf low setzen |
||
40 | #define GELB_ON PORTD |= (1<<LED_UNTENGB) //Den Portpin auf high setzen |
||
41 | #define GELB_OFF PORTD &= ~(1<<LED_UNTENGB) //Den Portpin auf low setzen |
||
42 | #define VORNGN_ON PORTD |= (1<<LED_VORNEGN) //Den Portpin auf high setzen |
||
43 | #define VORNGN_OFF PORTD &= ~(1<<LED_VORNEGN) //Den Portpin auf low setzen |
||
44 | #define HINTENGN_ON PORTC |= (1<<LED_HINTENGN) //Den Portpin auf high setzen |
||
45 | #define HINTENGN_OFF PORTC &= ~(1<<LED_HINTENGN) //Den Portpin auf low setzen |
||
46 | #define VORNRT_ON PORTD |= (1<<LED_VORNERT) //Den Portpin auf high setzen |
||
47 | #define VORNRT_OFF PORTD &= ~(1<<LED_VORNERT) //Den Portpin auf low setzen |
||
48 | #define HINTENRT_ON PORTD |= (1<<LED_HINTENRT) //Den Portpin auf high setzen |
||
49 | #define HINTENRT_OFF PORTD &= ~(1<<LED_HINTENRT) //Den Portpin auf low setzen |
||
50 | |||
51 | |||
52 | #define ALLES_OFF BLITZGN_OFF;BLITZRT_OFF;WEISS_OFF;BLAU_OFF;GELB_OFF;VORNGN_OFF;HINTENGN_OFF;VORNRT_OFF;HINTENRT_OFF |
||
53 | #define ALLES_ON BLITZGN_ON;BLITZRT_ON;WEISS_ON;BLAU_ON;GELB_ON;VORNGN_ON;HINTENGN_ON;VORNRT_ON;HINTENRT_ON |
||
54 | |||
55 | |||
56 | |||
57 | #define F_CPU 1000000UL |
||
58 | |||
59 | #ifndef F_CPU |
||
60 | #define F_CPU 1000000 |
||
61 | #endif |
||
62 | |||
63 | |||
64 | volatile uint8_t mode = 0; |
||
65 | volatile uint8_t abbruch = 0; |
||
66 | |||
67 | |||
68 | ISR(INT1_vect) |
||
69 | { |
||
70 | // Interrupt Code |
||
71 | if (mode <= 3) |
||
72 | { |
||
73 | mode++; |
||
74 | } |
||
75 | else |
||
76 | { |
||
77 | mode = 0; |
||
78 | } |
||
79 | STATUS_TOGGLE; |
||
80 | abbruch = 1; |
||
81 | } |
||
82 | |||
83 | |||
84 | |||
85 | int main(void){ |
||
86 | |||
87 | // Ports einstellen |
||
88 | |||
89 | // Pin B |7|6|5|4|3|2|1|0 |
||
90 | // Binär:|0|0|0|0|0|1|0|1 (b) => #05 (h) |
||
91 | // Pin B0 und B2 als Ausgänge festlegen |
||
92 | DDRB = 0x05; |
||
93 | |||
94 | // Pin C |7|6|5|4|3|2|1|0 |
||
95 | // Binär:|0|0|1|1|1|1|1|0 (b) => #3E (h) |
||
96 | // Pin C1 bis C5 als Ausgänge festlegen |
||
97 | DDRC = 0x3E; |
||
98 | |||
99 | // Pin D |7|6|5|4|3|2|1|0 |
||
100 | // Binär:|1|1|1|1|0|0|0|0 (b) => #F0 (h) |
||
101 | DDRD = 0xF0; |
||
102 | //Pullup für PD3 aktivieren |
||
103 | PORTD |= (1 << PD3); |
||
104 | |||
105 | |||
106 | //interrupt konfigurueren |
||
107 | GIMSK = 1<<INT1; |
||
108 | MCUCR = 1<<ISC10; |
||
109 | |||
110 | ALLES_OFF; |
||
111 | STATUS_OFF; |
||
112 | sleep_ms(3000); |
||
113 | STATUS_ON; |
||
114 | sei(); //interrupts einschalten |
||
115 | |||
116 | |||
117 | while(1){ |
||
118 | |||
119 | |||
120 | abbruch = 0; |
||
121 | if (mode == 0) |
||
122 | { |
||
123 | BLITZRT_OFF; |
||
124 | BLITZGN_OFF; |
||
125 | WEISS_ON; |
||
126 | sleep_ms(50); |
||
127 | WEISS_OFF; |
||
128 | BLAU_ON; |
||
129 | sleep_ms(50); |
||
130 | BLAU_OFF; |
||
131 | VORNGN_ON; |
||
132 | HINTENGN_ON; |
||
133 | sleep_ms(50); |
||
134 | VORNGN_OFF; |
||
135 | HINTENGN_OFF; |
||
136 | VORNRT_ON; |
||
137 | HINTENRT_ON; |
||
138 | sleep_ms(50); |
||
139 | VORNRT_OFF; |
||
140 | HINTENRT_OFF; |
||
141 | } |
||
142 | |||
143 | if (mode == 1) //mit diesem Mode wird gestartet |
||
144 | { |
||
145 | ALLES_OFF; |
||
146 | } |
||
147 | |||
148 | if (mode == 2) |
||
149 | { |
||
150 | ALLES_ON; |
||
151 | } |
||
152 | |||
153 | if (mode == 3) //Dieser Mode ist nach dem Kalibrieren an |
||
154 | { |
||
155 | WEISS_OFF; |
||
156 | BLAU_OFF; |
||
157 | GELB_ON; |
||
158 | VORNGN_OFF; |
||
159 | HINTENGN_OFF; |
||
160 | HINTENRT_OFF; |
||
161 | VORNRT_OFF; |
||
162 | BLITZGN_ON; |
||
163 | sleep_ms(30); |
||
164 | BLITZGN_OFF; |
||
165 | sleep_ms(60); |
||
166 | BLITZRT_ON; |
||
167 | sleep_ms(30); |
||
168 | BLITZRT_OFF; |
||
169 | sleep_ms(200); |
||
170 | BLITZGN_ON; |
||
171 | sleep_ms(30); |
||
172 | BLITZGN_OFF; |
||
173 | BLITZRT_ON; |
||
174 | sleep_ms(30); |
||
175 | BLITZRT_OFF; |
||
176 | sleep_ms(1000); |
||
177 | } |
||
178 | |||
179 | if (mode == 4) |
||
180 | { |
||
181 | WEISS_ON; |
||
182 | BLAU_ON; |
||
183 | GELB_ON; |
||
184 | VORNGN_OFF; |
||
185 | HINTENGN_OFF; |
||
186 | HINTENRT_OFF; |
||
187 | VORNRT_OFF; |
||
188 | BLITZGN_ON; |
||
189 | sleep_ms(30); |
||
190 | BLITZGN_OFF; |
||
191 | sleep_ms(60); |
||
192 | BLITZRT_ON; |
||
193 | sleep_ms(30); |
||
194 | BLITZRT_OFF; |
||
195 | sleep_ms(200); |
||
196 | BLITZGN_ON; |
||
197 | sleep_ms(30); |
||
198 | BLITZGN_OFF; |
||
199 | BLITZRT_ON; |
||
200 | sleep_ms(30); |
||
201 | BLITZRT_OFF; |
||
202 | sleep_ms(1000); |
||
203 | } |
||
204 | |||
205 | else |
||
206 | { |
||
207 | sleep_ms(10); |
||
208 | } |
||
209 | } |
||
210 | } |
||
211 | |||
212 | |||
213 | void sleep_ms(uint16_t ms){ |
||
214 | if (abbruch == 0) |
||
215 | { |
||
216 | while(ms) |
||
217 | { |
||
218 | if (abbruch != 0) |
||
219 | { |
||
220 | break; |
||
221 | } |
||
222 | else |
||
223 | { |
||
224 | ms--; |
||
225 | _delay_ms(1); |
||
226 | } |
||
227 | } |
||
228 | } |
||
229 | } |