Материал из Automata.
#include <stdint.h>
#include <avr/io.h>
#include <avr/interrupt.h>
//MISO - RCK;
#define LATCH 0x40
/*0*/ /*1*/ /*2*/ /*3*/ /*4*/ /*5*/ /*6*/ /*7*/ /*8*/ /*9*/ /*.*/
static const uint8_t LEDS[11] = {~0x5f,~0x42,~0x37,~0x76,~0x6a,~0x7c,~0x7d,~0x46,~0x7f,~0x7e,~0x00 };
static volatile uint8_t i = 0;
void Indicate (void)
{
SPCR |= _BV(SPE);
register uint8_t k;
for (k = 0; k < 9; k++)
{
SPDR = i == k ? LEDS[k+1] : 0xFF;
while (!(SPSR & _BV(SPIF)));
}
SPCR &= ~_BV(SPE);
PORTB |= LATCH;
PORTB &= ~LATCH;
}
ISR (TIMER1_COMPA_vect)
{
Indicate();
if (i++ == 9)
i = 0;
}
int main (void)
{
DDRB = 0xff;
PORTB = 0x00;
SPCR = _BV(SPE) | _BV(MSTR) | _BV(SPR1);
TCCR1B = _BV(WGM12) | _BV(CS12);
TIMSK = _BV(OCIE1A);
OCR1A = 11250;
sei();
while (1);
}