#include #include #include volatile uint8_t currentbit; volatile uint8_t seconds = 0; volatile uint8_t minutes = 25; volatile uint8_t hours = 5; volatile uint32_t lights_time = 1; volatile uint8_t lights_disco = 1; volatile uint8_t phase_DDR[4]; volatile uint8_t phase = 0; volatile uint8_t port = 1; volatile uint8_t OCRvalue = 255; volatile uint16_t counter_time = 0; volatile uint16_t counter_lights = 0; volatile uint8_t adc_akku; volatile uint8_t adc_lights; uint8_t map[] = { 0, 1, // A 1, 0, // B 0, 2, // C 2, 0, // D 0, 3, // E 3, 0, // F 0, 4, // G 4, 0, // H 1, 2, // I 2, 1, // J 1, 3, // K 3, 1, // L 1, 4, // M 4, 1, // N 2, 3, // O 3, 2, // P 2, 4, // Q 4, 2, // R 3, 4, // S 4, 3 // T }; void plexdata(void) { phase_DDR[0] = 0; phase_DDR[1] = 0; phase_DDR[2] = 0; phase_DDR[3] = 0; phase_DDR[4] = 0; uint8_t a = 0; uint8_t b; lights_time = (hours << 12) | (minutes << 6) | seconds; for(b=0; b<20; b++) { if(lights_time & (1UL << b)) { phase_DDR[map[a]] |= (1 << map[a+1]); } a += 2; } } int main(void) { DDRB = 0b00001111; //TCCR1B = (1 << CS13) | (1 << CS12) | (1 << CS11) | (1 << CS10); TCCR1B = (1 << CS12) | (1 << CS11) | (1 << CS10); TIMSK = (1 << OCIE1B) | (1 << TOIE1); ADMUX = (1 << ADLAR) | (1 << MUX2); ADCSR = (1 << ADEN) | (1 << ADPS2) | (1 << ADPS1); plexdata(); sei(); while(1) { ADCSR |= (1 << ADSC); loop_until_bit_is_set(ADCSR, ADIF); adc_lights = ADCH; /* if(adc_light == 0) { lights_disco = 1; counter_lights = 0; PORTB &= ~(0b00001111); } _delay_ms(25); */ } } ISR(TIMER1_CMPB_vect) { PORTA = 0; } ISR(TIMER1_OVF1_vect) { if(OCRvalue > 0) { PORTA = port; DDRA = phase_DDR[phase] | port; } OCR1B = OCRvalue; sei(); if(phase < 4) { phase++; port <<= 1; } else { phase = 0; port = 1; } counter_time++; if(counter_time >= 450) { counter_time = 0; seconds++; if(seconds == 60) { seconds = 0; minutes++; if(minutes == 60) { minutes = 0; hours++; if(hours == 24) { hours = 0; } } } plexdata(); } /* if(adc_light > 0) { counter_lights++; if(counter_lights >= (400 - adc_light)) { counter_lights = 0; PORTB = lights_disco | (PORTB & (0b11110000)); lights_disco <<= 1; if(lights_disco >= 0b00010000) { lights_disco = 1; } } } */ }