Sat, 21 Dec 2013 21:01:55 +0100
started firmware for car004f hardware
147
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
1 | #include <avr/interrupt.h> |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
2 | #include <avr/io.h> |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
3 | #include <avr/wdt.h> |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
4 | #include <avr/eeprom.h> |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
5 | #include <stdlib.h> |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
6 | #include <stdint.h> |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
7 | #include <avr/pgmspace.h> |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
8 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
9 | #include "main.h" |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
10 | #include "util/delay.h" |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
11 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
12 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
13 | ISR ( USART_RXC_vect ) { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
14 | } |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
15 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
16 | #define PULSE_PORT PORTD |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
17 | #define PULSE_BIT PD2 |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
18 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
19 | #define RESPONSE_PORT PORTC |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
20 | #define RESPONSE_PIN PC1 |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
21 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
22 | volatile uint16_t data = 0; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
23 | volatile uint8_t data_len = 0; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
24 | volatile uint8_t bitbuf_len = 0; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
25 | volatile uint16_t bitbuf = 0; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
26 | volatile uint8_t car_speed[8]; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
27 | volatile uint8_t car_switch[8]; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
28 | volatile uint8_t my_id; // Die ID des Autos! |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
29 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
30 | uint8_t my_switch; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
31 | uint8_t my_speed; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
32 | uint8_t light_mode; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
33 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
34 | ISR ( INT0_vect ) { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
35 | GICR &= ~_BV(INT0) ; // Disable INT0 |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
36 | // Startsignal erkannt, ab hier den Timer2 starten, |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
37 | // der liest dann alle 50µs den Zustand ein und schreibt das |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
38 | // empfangene Bit in den Puffer |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
39 | bitbuf = 0; // init |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
40 | bitbuf_len = 0b10000000; // init 1 pulse received |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
41 | TCNT2 = 0; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
42 | TIMSK |= _BV(OCIE2); //enable timer2 interrupt |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
43 | } |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
44 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
45 | ISR ( TIMER2_COMP_vect ) { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
46 | uint8_t clock; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
47 | uint8_t state; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
48 | uint8_t state2; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
49 | if ((bitbuf_len & 0b10000000) == 0) clock = 0; else clock = 0xff; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
50 | if ((bitbuf_len & 0b01000000) == 0) state = 0; else state = 0xff; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
51 | if ((PIN(PULSE_PORT) & _BV(PULSE_BIT)) == 0) state2 = 0xff; else state2 = 0; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
52 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
53 | if (clock) { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
54 | bitbuf_len &= ~_BV(7); // switch clock to low |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
55 | // second pulse of bit |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
56 | if ((state==state2) & state2) { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
57 | // two cycles high: packet end received |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
58 | data_len = (bitbuf_len & 0b00111111); |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
59 | TIMSK &= ~_BV(OCIE2); //disable timer2 interrupt |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
60 | GICR |= _BV(INT0) ; // Enable INT0 |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
61 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
62 | //data = bitbuf; // output data |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
63 | // write data of controllers to array |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
64 | if (data_len == 10) { // controller data packet |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
65 | clock = (bitbuf >> 6) & 0b00000111; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
66 | car_speed[clock] = (bitbuf >> 1) & 0x0F; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
67 | car_switch[clock] = (bitbuf >> 5) & 1; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
68 | // current response for this car? |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
69 | /* |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
70 | if (response != 0) { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
71 | if ( ((response & 0b00001110) >> 1) == clock) { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
72 | // add our ID to response: |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
73 | send_response(response | self_id << 6); |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
74 | response = 0; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
75 | } |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
76 | } |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
77 | */ |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
78 | } |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
79 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
80 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
81 | } else { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
82 | bitbuf_len++; // increment bit counter |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
83 | bitbuf = bitbuf << 1; // shift bits |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
84 | if (state2 == 0) bitbuf |= 1; // receive logic one |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
85 | } |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
86 | } else { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
87 | bitbuf_len |= _BV(7); // switch clock to high |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
88 | // first pulse of bit |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
89 | if (state2) { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
90 | bitbuf_len |= _BV(6); // store new state |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
91 | } else { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
92 | bitbuf_len &= ~_BV(6); // store new state |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
93 | } |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
94 | } |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
95 | } |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
96 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
97 | ISR (TIMER1_OVF_vect) { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
98 | } |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
99 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
100 | ISR (INT1_vect) { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
101 | } |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
102 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
103 | #define LIGHT_PORT PORTC |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
104 | #define LIGHT_FRONT 2 |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
105 | #define LIGHT_BRAKE 4 |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
106 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
107 | #define IR_PORT PORTB |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
108 | #define IR_LED 3 |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
109 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
110 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
111 | #define LIGHT_MODES 1 // anzahl der lichtmodi (ohne den modus "aus") |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
112 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
113 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
114 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
115 | int main(void) |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
116 | { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
117 | uint8_t car0_state, car1_state; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
118 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
119 | // setup data bit timer2 |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
120 | TCCR2 = (1<<CS21) | (1<<WGM21); //divide by 8, set compare match |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
121 | OCR2 = TIMER2_50US; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
122 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
123 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
124 | // enable both external interrupts |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
125 | // int 0 = data RX |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
126 | MCUCR = _BV(ISC00) | _BV(ISC01) | _BV(ISC10) | _BV(ISC11); // INT0/1 rising edge |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
127 | GICR = _BV(INT0) | _BV(INT1) ; // Enable INT0 + INT1 |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
128 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
129 | // oscillator calibration |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
130 | // atmega8@1mhz = 0xac |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
131 | // @4mhz = ca 0xa0 |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
132 | //OSCCAL = 0xa0; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
133 | //OSCCAL = 0x9A; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
134 | //OSCCAL = 0xa0; // internal oscillator @ 4 mhz.... doesnt work accurate! |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
135 | sei(); |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
136 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
137 | DDR(LIGHT_PORT) |= (_BV(LIGHT_FRONT) | _BV(LIGHT_BRAKE)); |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
138 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
139 | //defaults (from eeprom!) |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
140 | my_id = 1; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
141 | light_mode = 0; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
142 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
143 | while (1) { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
144 | // main loop |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
145 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
146 | // Light cycle if switch pressed without speed |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
147 | if (my_speed == 0) { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
148 | if (my_switch != car_switch[my_id]) { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
149 | my_switch = car_switch[my_id]; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
150 | if (my_switch != 0) { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
151 | // cycle light |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
152 | if (light_mode == LIGHT_MODES) light_mode = 0; else light_mode++; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
153 | } |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
154 | } |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
155 | } |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
156 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
157 | switch (light_mode) { |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
158 | case 0: |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
159 | LIGHT_PORT &= ~_BV(LIGHT_FRONT); // switch lights off |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
160 | break; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
161 | case 1: |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
162 | LIGHT_PORT |= _BV(LIGHT_FRONT); // switch lights on |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
163 | break; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
164 | } |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
165 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
166 | _delay_ms(100); |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
167 | LIGHT_PORT |= _BV(LIGHT_BRAKE); // brake light on |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
168 | _delay_ms(100); |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
169 | LIGHT_PORT &= ~_BV(LIGHT_BRAKE); // brake light off |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
170 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
171 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
172 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
173 | |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
174 | } // main loop end |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
175 | }; |
f66c5b3b3ed2
started firmware for car004f hardware
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
176 |