avr/led3/led3.c

48 lines
844 B
C
Raw Permalink Normal View History

2021-05-16 21:54:45 +00:00
#include <avr/io.h>
#include <util/delay.h>
#include <limits.h>
#define DELAY 75
#define LEN sizeof(PORTB) * CHAR_BIT
#define LED_DDR DDRB
#define LED_PORT PORTB
void _delay_s(double __s)
{
int i;
for (i = 0; i < __s; i++)
_delay_ms(1000);
}
int main(void) {
uint8_t i;
LED_DDR = 0xff;
for (;;) {
for (i = 0; i < LEN; i++) {
_delay_ms(DELAY);
LED_PORT |= (1 << i);
}
for (i = 0; i < LEN; i++) {
_delay_ms(DELAY);
LED_PORT &= ~(1 << i);
}
_delay_s(1);
for (i = LEN; i < 255; i--) {
_delay_ms(DELAY);
LED_PORT |= (1 << i);
}
for (i = LEN; i < 255; i--) {
_delay_ms(DELAY);
LED_PORT &= ~(1 << i);
}
_delay_s(1);
}
return 0;
}