#include #include #include /* const struct avr_mmcu_vcd_trace_t _mytrace[] _MMCU_ = { { AVR_MCU_VCD_SYMBOL("PORTB"), .what = (void *)&PORTB, }, }; */ #define FPS 100 #define FPS_MS 1000 / FPS #define MULT 5 typedef struct { uint8_t value; int8_t inc; } counter_t; void step_counter(counter_t *counter) { int16_t value = counter->value; value += counter->inc; if (value >= 255) { counter->value = 255; counter->inc = -1; } else if (value <= 0) { counter->value = 0; counter->inc = 1; } else { counter->value = value; } } int main(void) { dio_t dio0 = (dio_t){ .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 0 }; dio_t dio1 = (dio_t){ .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 1 }; dio_set_direction(&dio0, LINE_OUT); dio_set_direction(&dio1, LINE_OUT); // GTCCR = _BV(TSM) | _BV(PSR0); TCCR0A = _BV(COM0A1) | _BV(COM0A0) | _BV(COM0B1) | _BV(COM0B0) | _BV(WGM01) | _BV(WGM00); TCCR0B = _BV(WGM02) | _BV(CS00); counter_t red = (counter_t){ .value = 128, .inc = -1 }; counter_t blue = (counter_t){ .value = 128, .inc = -1 }; // GTCCR &= ~_BV(TSM); while(1) { step_counter(&red); step_counter(&blue); OCR0A = red.value; OCR0B = blue.value; _delay_ms(FPS_MS); } return 0; }