# HG changeset patch # User Malte Bayer # Date 1387667326 -3600 # Node ID 08cb88614d69132799cc29862699b2cdaefee356 # Parent f66c5b3b3ed22c65028b07a8ea8595b8e29b16cc car firmware: finished pwm drive and lights switching diff -r f66c5b3b3ed2 -r 08cb88614d69 car004f/main.c --- a/car004f/main.c Sat Dec 21 21:01:55 2013 +0100 +++ b/car004f/main.c Sun Dec 22 00:08:46 2013 +0100 @@ -16,8 +16,12 @@ #define PULSE_PORT PORTD #define PULSE_BIT PD2 -#define RESPONSE_PORT PORTC -#define RESPONSE_PIN PC1 +typedef struct { + uint8_t slot; + uint8_t light; + unsigned program:1; // programming mode active +} config_t; + volatile uint16_t data = 0; volatile uint8_t data_len = 0; @@ -25,11 +29,14 @@ volatile uint16_t bitbuf = 0; volatile uint8_t car_speed[8]; volatile uint8_t car_switch[8]; -volatile uint8_t my_id; // Die ID des Autos! + +volatile uint8_t timeout = 0; +volatile uint8_t brake_timeout = 0; + uint8_t my_switch; uint8_t my_speed; -uint8_t light_mode; +config_t config; ISR ( INT0_vect ) { GICR &= ~_BV(INT0) ; // Disable INT0 @@ -94,10 +101,13 @@ } } -ISR (TIMER1_OVF_vect) { +ISR (INT1_vect) { } -ISR (INT1_vect) { +ISR (TIMER0_OVF_vect) { + TCNT0 = 100; // TIMER0 vorladen mit 100 + if (brake_timeout > 1) brake_timeout--; + if (timeout > 1) timeout--; } #define LIGHT_PORT PORTC @@ -107,15 +117,31 @@ #define IR_PORT PORTB #define IR_LED 3 +#define BRAKE_PORT PORTB +#define BRAKE 0 #define LIGHT_MODES 1 // anzahl der lichtmodi (ohne den modus "aus") +void config_save(void) { + eeprom_write_block( (void*)&config, 0, sizeof(config) ); +} + + +void brake_on(void) { + LIGHT_PORT |= _BV(LIGHT_BRAKE); // brake light on + BRAKE_PORT |= _BV(BRAKE); // brake on + brake_timeout = 50; +} + +void brake_off(void) { + LIGHT_PORT &= ~_BV(LIGHT_BRAKE); // brake light off + BRAKE_PORT &= ~_BV(BRAKE); // brake off + brake_timeout = 0; +} int main(void) { - uint8_t car0_state, car1_state; - // setup data bit timer2 TCCR2 = (1<