#define __ATmega2560__
#define __AVR_ATmega2560__
#ifndef F_CPU
#define F_CPU 16000000UL
#endif
#include <stdint.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <stdbool.h>
#include <stdint.h>
#include <util/delay.h>
#include <stdint.h>
#include <stdlib.h>
#include <avr/interrupt.h>
int main(void)
{
uint8_t ler0; //
uint8_t ler1; //
uint8_t ler2; //
//LED
DDRB = DDRB | (1 << DDB7); // fazemos PB7 uma saída
PORTB = PORTB & (~(1 << PORTB7)); // inicialmente o LED está apagado.
//chaves
DDRB = DDRB & (~(1 << DDB0)); //
DDRB = DDRB & (~(1 << DDB1)); //
DDRB = DDRB & (~(1 << DDB2)); //
//pull-up
PORTB = PORTB | (1 << PORTB0); //
PORTB = PORTB | (1 << PORTB1); //
PORTB = PORTB | (1 << PORTB2); //
ler0 = PINB & (1 << PINB0); // lemos o valor da chave 0
ler1 = PINB & (1 << PINB1); // lemos o valor da chave 1
ler2 = PINB & (1 << PINB2); // lemos o valor da chave 3
while (1) {
// faz a leitura da chave
uint8_t ler0 = PINB & (1 << PINB0); // realizamos a leitura de PB0
uint8_t ler1 = PINB & (1 << PINB1); // realizamos a leitura de PB1
uint8_t ler2 = PINB & (1 << PINB2); // realizamos a leitura de PB2
if (ler2 == 1 && ler1 == 0) {
PORTB |= (1 << PORTB7); // Acende o LED (se PB2 é alto e PB1 é baixo)
} else if (ler1 == 1 && ler0 == 0) {
PORTB &= ~(1 << PORTB7); // Apaga o LED (se PB1 é alto e PB0 é baixo)
}
}
return 0;
}