#include #include #include #include #include #include #include #define asm(x) __asm__ volatile(x) uint8_t leds[9*3] = { 0 }; #if 0 const uint8_t fleds[9*3] = { 0xbb, 0x00, 0x77, 0xbb, 0x77, 0x00, 0x77, 0xbb, 0x00, 0x00, 0xbb, 0x00, 0x00, 0xbb, 0x77, 0x00, 0x77, 0xbb, 0x00, 0x00, 0xbb, 0x77, 0x00, 0xbb, }; #else const uint8_t fleds[9*3] = { 0xbb, 0x00, 0x00, 0xbb, 0x77, 0x00, 0x77, 0xbb, 0x00, 0x00, 0xbb, 0x00, 0x00, 0xbb, 0x77, 0x00, 0x77, 0xbb, 0x00, 0x00, 0xbb, 0x77, 0x00, 0xbb, 0xbb, 0x00, 0x77, }; #endif int main(void) { char j; uint8_t x, *p; uint8_t on, off; uint8_t end = (uint8_t)(uint16_t)(leds + sizeof(leds)); uint8_t fade = 0; uint8_t counter = 0; uint8_t skip = 0; on = 1; off = 0; DDRB = on; for (;;) { counter++; if (++fade >= 0x80) { skip+= 3; if (skip > sizeof(fleds)) skip-= sizeof(fleds); fade = 0; } for (x = 0;x != sizeof(leds);x++) leds[x] = (((fleds[(x + skip) % sizeof(fleds)] * (0x80 - fade)) >> 8) + (fleds[(x + skip + 3) % sizeof(fleds)] * fade >> 8) + (~counter & 7)) / 8; p = leds; _delay_us(50); for (;;) { x = *p++; for (j = 7;j >= 0;j--) { PORTB = on; asm("nop"); asm("rjmp .+0"); if (!(x & (uint8_t)(1 << j))) PORTB = off; asm("rjmp .+0"); asm("rjmp .+0"); asm("nop"); PORTB = off; if (j != 0) { asm("rjmp .+0"); asm("rjmp .+0"); } } if ((uint8_t)(uint16_t)p == end) break; } } }