Code: Select all

```
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
int cycle(int data);
int latch(void);
int main(void)
{
DDRB = 0b000111;
PORTB = 0b000000;
while(1)
{
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
latch();
_delay_ms(2.5);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
cycle(1);
cycle(0);
latch();
_delay_ms(2.5);
}
return 1;
}
int latch(void)
{
PORTB |= (1 << PIN2);
PORTB &= ~(1 << PIN2);
return 1;
}
int cycle(int data)
{
if (data == 0)
{
PORTB &= ~(1 << PIN0);
PORTB |= (1 << PIN1);
PORTB &= ~(1 << PIN1);
}
else
{
PORTB |= (1 << PIN0);
PORTB |= (1 << PIN1);
PORTB &= ~(1 << PIN1);
}
return 1;
}
```