// Pines en PORTD
// PD2, PD3, PD4 -> Entradas (DIP Switch)
// PD5, PD6 -> Salidas (Sum y Carry)
// Configuración de entradas y salidas
void setup() {
DDRD &= ~(1 << PD2);
DDRD &= ~(1 << PD3);
DDRD &= ~(1 << PD4);
// Activa resistencias Pull-Down
PORTD &= ~(1 << PD2);
PORTD &= ~(1 << PD3);
PORTD &= ~(1 << PD4);
DDRD |= (1 << PD5);
DDRD |= (1 << PD6);
}
void loop() {
// Lee entradas (A, B, Carry-In)
bool A = (PIND & (1 << PD2)) != 0;
bool B = (PIND & (1 << PD3)) != 0;
bool Cin = (PIND & (1 << PD4)) != 0;
// Sumador completo
bool Sum = A ^ B ^ Cin;
bool Cout = (A & B) | (B & Cin) | (Cin & A);
// Escribe resultados en el puerto D
PORTD = (PORTD & ~(1 << PD5)) | (Sum << PD5);
PORTD = (PORTD & ~(1 << PD6)) | (Cout << PD6);
}