//juan david ramirez rodriguez
//simon salgado lara
// 102
#define A_PIN 0 // PD0 - Entrada A
#define B_PIN 1 // PD1 - Entrada B
#define CIN_PIN 2 // PD2 - Entrada Cin (Carry In)
#define S_PIN 3 // PD3 - Salida S (Suma)
#define COUT_PIN 4 // PD4 - Salida Cout (Carry Out)
void setup() {
DDRD = (1 << S_PIN) | (1 << COUT_PIN);
PORTD = 0x00;
}
void loop() {
// Lee los estados de los pines de entrada controlados por el DIP switch
bool A = PIND & (1 << A_PIN);
bool B = PIND & (1 << B_PIN);
bool Cin = PIND & (1 << CIN_PIN);
// Implementación del sumador completo
bool S = A ^ B ^ Cin; // Calcula la suma
bool Cout = (A & B) | (Cin & (A ^ B)); // Calcula el carry out
// Asigna el resultado en los pines de salida
PORTD = (PORTD & ~((1 << S_PIN) | (1 << COUT_PIN))) | (S << S_PIN) | (Cout << COUT_PIN);
}