#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
unsigned char digito[16] = {
0b01111110, // = 0
0b00110000, // = 1
0b01101101, // = 2
0b01111001, // = 3
0b00110011, // = 4
0b01011011, // = 5
0b01011111, // = 6
0b01110000, // = 7
0b01111111, // = 8
0b01110011, // = 9
0b01110111, // = A
0b00011111, // = B
0b01001110, // = C
0b00111101, // = D
0b01001111, // = E
0b01000111 // = F
};
void exibir(int valor) {
// Segmento "a" - Bit 6
if ((digito[valor] & 64) != 0)
PORTD |= (1 << PORTD7);
else
PORTD &= ~(1 << PORTD7);
// Segmento "b" - Bit 5
if ((digito[valor] & 32) != 0)
PORTB |= (1 << PORTB0);
else
PORTB &= ~(1 << PORTB0);
// Segmento "c" - Bit 4
if ((digito[valor] & 16) != 0)
PORTB |= (1 << PORTB1);
else
PORTB &= ~(1 << PORTB1);
// Segmento "d" - Bit 3
if ((digito[valor] & 8) != 0)
PORTB |= (1 << PORTB2);
else
PORTB &= ~(1 << PORTB2);
// Segmento "e" - Bit 2
if ((digito[valor] & 4) != 0)
PORTB |= (1 << PORTB3);
else
PORTB &= ~(1 << PORTB3);
// Segmento "f" - Bit 1
if ((digito[valor] & 2) != 0)
PORTB |= (1 << PORTB4);
else
PORTB &= ~(1 << PORTB4);
// Segmento "g" - Bit 0
if ((digito[valor] & 1) != 0)
PORTB |= (1 << PORTB5);
else
PORTB &= ~(1 << PORTB5);
}
int main(void) {
DDRD |= (1 << DDD7); // Segmento "a"
DDRB |= (1 << DDB0); // Segmento "b"
DDRB |= (1 << DDB1); // Segmento "c"
DDRB |= (1 << DDB2); // Segmento "d"
DDRB |= (1 << DDB3); // Segmento "e"
DDRB |= (1 << DDB4); // Segmento "f"
DDRB |= (1 << DDB5); // Segmento "g"
while (1) {
for (int cont = 0; cont <= 16; cont++) {
exibir(cont);
_delay_ms(1000);
}
}
}