Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //initial input of the EEPROM
- int first_input_0 = 0;
- int first_input_1 = 0;
- int first_input_2 = 0;
- int first_input_3 = 0;
- //pins of initial input
- int pin_0 = 2; //LSB
- int pin_1 = 3;
- int pin_2 = 4;
- int pin_3 = 5;
- //pins of output of EEPROM (I region), becomes input of arduino
- int eeprom_out_0 = 6;
- int eeprom_out_1 = 7;
- int eeprom_out_2 = 8;
- int eeprom_out_3 = 9;
- int eeprom_out_4 = 10;
- int eeprom_out_5 = 11;
- int eeprom_out_6 = 12;
- int eeprom_out_7 = 13;
- //output to be displayed in 7segment LED
- int final_output_0 = A0;
- int final_output_1 = A1;
- int final_output_2 = A2;
- int final_output_3 = A3;
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- pinMode(pin_0, OUTPUT);
- pinMode(pin_1, OUTPUT);
- pinMode(pin_2, OUTPUT);
- pinMode(pin_3, OUTPUT);
- pinMode(eeprom_out_0, INPUT);
- pinMode(eeprom_out_1, INPUT);
- pinMode(eeprom_out_2, INPUT);
- pinMode(eeprom_out_3, INPUT);
- pinMode(eeprom_out_4, INPUT);
- pinMode(eeprom_out_5, INPUT);
- pinMode(eeprom_out_6, INPUT);
- pinMode(eeprom_out_7, INPUT);
- pinMode(final_output_0, OUTPUT);
- pinMode(final_output_1, OUTPUT);
- pinMode(final_output_2, OUTPUT);
- pinMode(final_output_3, OUTPUT);
- //SETUP 000 AS ADDRESS OF EEPROM
- digitalWrite(pin_0, LOW);
- digitalWrite(pin_1, LOW);
- digitalWrite(pin_2, LOW);
- digitalWrite(pin_3, LOW);
- }
- void loop() {
- Serial.println("address of eeprom");
- Serial.println(first_input_3);
- Serial.println(first_input_2);
- Serial.println(first_input_1);
- Serial.println(first_input_0);
- //i region bits coming from eeprom output
- int i_0 = digitalRead(eeprom_out_0);
- int i_1 = digitalRead(eeprom_out_1);
- int i_2 = digitalRead(eeprom_out_2);
- int i_3 = digitalRead(eeprom_out_3);
- int i_4 = digitalRead(eeprom_out_4);
- int i_5 = digitalRead(eeprom_out_5);
- int i_6 = digitalRead(eeprom_out_6);
- int i_7 = digitalRead(eeprom_out_7);
- //save operation (5 bits of i region but only 2 bits is necessary 00, 01, and 10)
- int operation_0 = i_3;
- int operation_1 = i_4;
- //address of D region
- int d_0 = i_0;
- int d_1 = i_1;
- int d_2 = i_2;
- int d_3 = 1; //constant + 8
- //supply the new address of eeprom to find the D
- digitalWrite(pin_0, d_0);
- digitalWrite(pin_1, d_1);
- digitalWrite(pin_2, d_2);
- digitalWrite(pin_3, d_3);
- //get d region bits from EEPROM
- i_0 = digitalRead(eeprom_out_0);
- i_1 = digitalRead(eeprom_out_1);
- i_2 = digitalRead(eeprom_out_2);
- i_3 = digitalRead(eeprom_out_3);
- i_4 = digitalRead(eeprom_out_4);
- i_5 = digitalRead(eeprom_out_5);
- i_6 = digitalRead(eeprom_out_6);
- i_7 = digitalRead(eeprom_out_7);
- //classify upper and lower nibble
- int upper_0 = i_4;
- int upper_1 = i_5;
- int upper_2 = i_6;
- int upper_3 = i_7;
- int lower_0 = i_0;
- int lower_1 = i_1;
- int lower_2 = i_2;
- int lower_3 = i_3;
- //output upper nibble
- if(operation_0 == 0 && operation_1 == 0){
- digitalWrite(final_output_0, upper_0);
- digitalWrite(final_output_1, upper_1);
- digitalWrite(final_output_2, upper_2);
- digitalWrite(final_output_3, upper_3);
- }
- else if(operation_0 == 1 && operation_1 == 0){
- digitalWrite(final_output_0, lower_0);
- digitalWrite(final_output_1, lower_1);
- digitalWrite(final_output_2, lower_2);
- digitalWrite(final_output_3, lower_3);
- }
- else if(operation_0 == 0 && operation_1 == 1){
- Serial.println("nasa 10");
- int sum_0 = (upper_0 + lower_0)%2;
- int carry_0 = (upper_0 + lower_0)/2;
- int sum_1 = (upper_1 + lower_1 + carry_0)%2;
- int carry_1 = (upper_1 + lower_1 + carry_0)/2;
- int sum_2 = (upper_2 + lower_2 + carry_1)%2;
- int carry_2 = (upper_2 + lower_2 + carry_1)/2;
- int sum_3 = (upper_3 + lower_3 + carry_2)%2;
- Serial.println("SUM: ");
- Serial.println(sum_3);
- Serial.println(sum_2);
- Serial.println(sum_1);
- Serial.println(sum_0);
- digitalWrite(final_output_0, sum_0);
- digitalWrite(final_output_1, sum_1);
- digitalWrite(final_output_2, sum_2);
- digitalWrite(final_output_3, sum_3);
- }
- delay(1000);
- //update the address of the I region
- first_input_0 = (first_input_0 + 1)%2;
- int input_carry_0 = (first_input_0 + 1)/2;
- first_input_1 = (first_input_1 + 1 + input_carry_0)%2;
- int input_carry_1 = (first_input_1 + 1 + input_carry_0)/2;
- first_input_2 = (first_input_2 + 1 + input_carry_1)%2;
- first_input_3 = 0;
- //supply the new address to EEPROM
- digitalWrite(pin_0, first_input_0);
- digitalWrite(pin_1, first_input_1);
- digitalWrite(pin_2, first_input_2);
- digitalWrite(pin_3, first_input_3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement