car004f/main.c

changeset 155
9e27eb837d3f
parent 154
46822de910ff
equal deleted inserted replaced
154:46822de910ff 155:9e27eb837d3f
30 30
31 volatile uint16_t data = 0; 31 volatile uint16_t data = 0;
32 volatile uint8_t data_len = 0; 32 volatile uint8_t data_len = 0;
33 volatile uint8_t bitbuf_len = 0; 33 volatile uint8_t bitbuf_len = 0;
34 volatile uint16_t bitbuf = 0; 34 volatile uint16_t bitbuf = 0;
35
35 volatile uint8_t car_speed[MAX_SLOTS]; 36 volatile uint8_t car_speed[MAX_SLOTS];
36 volatile uint8_t car_switch[MAX_SLOTS]; 37 volatile uint8_t car_switch[MAX_SLOTS];
37 volatile uint8_t car_act; 38 volatile uint8_t car_act;
38 39
39 volatile uint8_t car_timeout[MAX_SLOTS]; 40 volatile uint8_t car_timeout[MAX_SLOTS];
52 // empfangene Bit in den Puffer 53 // empfangene Bit in den Puffer
53 bitbuf = 0; // init 54 bitbuf = 0; // init
54 bitbuf_len = 0b10000000; // init 1 pulse received 55 bitbuf_len = 0b10000000; // init 1 pulse received
55 56
56 //TCNT2 = 10; 57 //TCNT2 = 10;
57 TCNT2 = 9; 58 TCNT2 = 11;
58 TIMSK |= _BV(OCIE2); //enable timer2 interrupt 59 TIMSK |= _BV(OCIE2); //enable timer2 interrupt
59 } 60 }
60 61
61 ISR ( TIMER2_COMP_vect ) { 62 ISR ( TIMER2_COMP_vect ) {
62 // TCNT2 = 0; 63 // TCNT2 = 0;
80 // write data of controllers to array 81 // write data of controllers to array
81 if (data_len == 10) { // controller data packet 82 if (data_len == 10) { // controller data packet
82 clock = (bitbuf >> 6) & 0b00000111; 83 clock = (bitbuf >> 6) & 0b00000111;
83 car_speed[clock] = (bitbuf >> 1) & 0x0F; 84 car_speed[clock] = (bitbuf >> 1) & 0x0F;
84 car_switch[clock] = (bitbuf >> 5) & 1; 85 car_switch[clock] = (bitbuf >> 5) & 1;
85 // current response for this car? 86
86 /*
87 if (response != 0) {
88 if ( ((response & 0b00001110) >> 1) == clock) {
89 // add our ID to response:
90 send_response(response | self_id << 6);
91 response = 0;
92 }
93 }
94 */
95 } 87 }
96 88
97 if (data_len == 8) { // activity data packet 89 if (data_len == 8) { // activity data packet
98 car_act = (bitbuf >> 1) & 0b00111111; 90 car_act = (bitbuf >> 1) & 0b00111111;
99 for (clock = 0; clock<MAX_SLOTS; clock++) { 91 for (clock = 0; clock<MAX_SLOTS; clock++) {

mercurial