0% found this document useful (0 votes)
6 views

Projectcode

Uploaded by

hasunbriren
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Projectcode

Uploaded by

hasunbriren
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <LiquidCrystal.

h>
#include <Keypad.h>

LiquidCrystal lcd(14, 15, 16, 17, 18, 19);

const byte ROWS = 4;


const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};

byte rowPins[ROWS] = {2, 3, 4, 5};


byte colPins[COLS] = {6, 7, 8};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

int num1 = 0;
int num2 = 0;
bool isNum1 = true;
int col = 0;

// Define pin connections


const int carryInFirst = 12; // C0 for first IC (connected to GND)
const int carryInSecond = 11; // C0 for second IC (connected to C4 of first IC)
const int carryOutPinSecond = 10; // C4 for second IC (output pin)
const int sumPinsLower[4] = {38, 40, 42, 44}; // Pins to read lower sum bits from
lower 7483 IC
const int sumPinsUpper[4] = {45, 43, 41, 39}; // Pins to read upper sum bits
from upper 7483 IC
const int aPinsLower[4] = {22, 24, 26, 28}; // Lower 4 bits of num1 input to
lower 7483
const int aPinsUpper[4] = {46, 48, 50, 52}; // Upper 4 bits of num1 input to
upper 7483
const int bPinsLower[4] = {30, 32, 34, 36}; // Lower 4 bits of num2 input to lower
7483
const int bPinsUpper[4] = {53, 51, 49, 47}; // Upper 4 bits of num2 input to upper
7483

void setup() {
// Set sum and carry pins as input
for (int i = 0; i < 4; i++) {
pinMode(sumPinsLower[i], INPUT);
pinMode(sumPinsUpper[i], INPUT);
}
pinMode(carryOutPinSecond, INPUT); // Set the carry out pin of the second IC as
input

lcd.begin(16, 2);
lcd.print("Enter values:");
delay(2000);
lcd.clear();
}

void loop() {
char key = keypad.getKey();
if (key) {
if (key == '#') {
// Trigger addition in the 7483s and read the result
int sum = readResultFrom7483s();
bool carryOut = digitalRead(carryOutPinSecond);

lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sum: ");
lcd.print(sum);
lcd.setCursor(0, 1);
lcd.print("Carry Out: ");
lcd.print(carryOut);
delay(5000);

// Reset for new inputs


num1 = 0;
num2 = 0;
isNum1 = true;
col = 0;
lcd.clear();
lcd.print("Enter values:");
delay(2000);
lcd.clear();
} else if (key == '*') {
isNum1 = false;
col = 0;
lcd.setCursor(col, 1);
} else {
if (isNum1) {
num1 = num1 * 10 + (key - '0');
lcd.setCursor(col, 0);
} else {
num2 = num2 * 10 + (key - '0');
lcd.setCursor(col, 1);
}
lcd.print(key);
col++;
}
}

delay(100);
}

void setInputsTo7483s(int a, int b) {


// Set lower 4 bits of num1 and num2 to lower 7483
for (int i = 0; i < 4; i++) {
pinMode(aPinsLower[i], OUTPUT);
pinMode(bPinsLower[i], OUTPUT);
digitalWrite(aPinsLower[i], (a >> i) & 1);
digitalWrite(bPinsLower[i], (b >> i) & 1);
}

// Set upper 4 bits of num1 and num2 to upper 7483


for (int i = 0; i < 4; i++) {
pinMode(aPinsUpper[i], OUTPUT);
pinMode(bPinsUpper[i], OUTPUT);
digitalWrite(aPinsUpper[i], (a >> (i + 4)) & 1);
digitalWrite(bPinsUpper[i], (b >> (i + 4)) & 1);
}
}

int readResultFrom7483s() {
setInputsTo7483s(num1, num2); // Send num1 and num2 to both 7483 ICs

// Read sum from lower 7483


int sumLower = 0;
for (int i = 0; i < 4; i++) {
sumLower |= (digitalRead(sumPinsLower[i]) << i);
}

// Read sum from upper 7483


int sumUpper = 0;
for (int i = 0; i < 4; i++) {
sumUpper |= (digitalRead(sumPinsUpper[i]) << i);
}

// Combine the results from both 7483 ICs


return (sumUpper << 4) | sumLower;
}

You might also like