Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. //initial input of the EEPROM
  2. int first_input_0 = 0;
  3. int first_input_1 = 0;
  4. int first_input_2 = 0;
  5. int first_input_3 = 0;
  6.  
  7. //pins of initial input
  8. int pin_0 = 2; //LSB
  9. int pin_1 = 3;
  10. int pin_2 = 4;
  11. int pin_3 = 5;
  12.  
  13. //pins of output of EEPROM (I region), becomes input of arduino
  14. int eeprom_out_0 = 6;
  15. int eeprom_out_1 = 7;
  16. int eeprom_out_2 = 8;
  17. int eeprom_out_3 = 9;
  18. int eeprom_out_4 = 10;
  19. int eeprom_out_5 = 11;
  20. int eeprom_out_6 = 12;
  21. int eeprom_out_7 = 13;
  22.  
  23. //output to be displayed in 7segment LED
  24. int final_output_0 = A0;
  25. int final_output_1 = A1;
  26. int final_output_2 = A2;
  27. int final_output_3 = A3;
  28.  
  29. void setup() {
  30. // put your setup code here, to run once:
  31. Serial.begin(9600);
  32.  
  33. pinMode(pin_0, OUTPUT);
  34. pinMode(pin_1, OUTPUT);
  35. pinMode(pin_2, OUTPUT);
  36. pinMode(pin_3, OUTPUT);
  37.  
  38. pinMode(eeprom_out_0, INPUT);
  39. pinMode(eeprom_out_1, INPUT);
  40. pinMode(eeprom_out_2, INPUT);
  41. pinMode(eeprom_out_3, INPUT);
  42. pinMode(eeprom_out_4, INPUT);
  43. pinMode(eeprom_out_5, INPUT);
  44. pinMode(eeprom_out_6, INPUT);
  45. pinMode(eeprom_out_7, INPUT);
  46.  
  47. pinMode(final_output_0, OUTPUT);
  48. pinMode(final_output_1, OUTPUT);
  49. pinMode(final_output_2, OUTPUT);
  50. pinMode(final_output_3, OUTPUT);
  51.  
  52.  
  53. //SETUP 000 AS ADDRESS OF EEPROM
  54. digitalWrite(pin_0, LOW);
  55. digitalWrite(pin_1, LOW);
  56. digitalWrite(pin_2, LOW);
  57. digitalWrite(pin_3, LOW);
  58. }
  59.  
  60. void loop() {
  61. Serial.println("address of eeprom");
  62. Serial.println(first_input_3);
  63. Serial.println(first_input_2);
  64. Serial.println(first_input_1);
  65. Serial.println(first_input_0);
  66.  
  67. //i region bits coming from eeprom output
  68. int i_0 = digitalRead(eeprom_out_0);
  69. int i_1 = digitalRead(eeprom_out_1);
  70. int i_2 = digitalRead(eeprom_out_2);
  71. int i_3 = digitalRead(eeprom_out_3);
  72. int i_4 = digitalRead(eeprom_out_4);
  73. int i_5 = digitalRead(eeprom_out_5);
  74. int i_6 = digitalRead(eeprom_out_6);
  75. int i_7 = digitalRead(eeprom_out_7);
  76.  
  77. //save operation (5 bits of i region but only 2 bits is necessary 00, 01, and 10)
  78. int operation_0 = i_3;
  79. int operation_1 = i_4;
  80.  
  81. //address of D region
  82. int d_0 = i_0;
  83. int d_1 = i_1;
  84. int d_2 = i_2;
  85. int d_3 = 1; //constant + 8
  86.  
  87. //supply the new address of eeprom to find the D
  88. digitalWrite(pin_0, d_0);
  89. digitalWrite(pin_1, d_1);
  90. digitalWrite(pin_2, d_2);
  91. digitalWrite(pin_3, d_3);
  92.  
  93. //get d region bits from EEPROM
  94. i_0 = digitalRead(eeprom_out_0);
  95. i_1 = digitalRead(eeprom_out_1);
  96. i_2 = digitalRead(eeprom_out_2);
  97. i_3 = digitalRead(eeprom_out_3);
  98. i_4 = digitalRead(eeprom_out_4);
  99. i_5 = digitalRead(eeprom_out_5);
  100. i_6 = digitalRead(eeprom_out_6);
  101. i_7 = digitalRead(eeprom_out_7);
  102.  
  103. //classify upper and lower nibble
  104. int upper_0 = i_4;
  105. int upper_1 = i_5;
  106. int upper_2 = i_6;
  107. int upper_3 = i_7;
  108.  
  109. int lower_0 = i_0;
  110. int lower_1 = i_1;
  111. int lower_2 = i_2;
  112. int lower_3 = i_3;
  113.  
  114. //output upper nibble
  115. if(operation_0 == 0 && operation_1 == 0){
  116. digitalWrite(final_output_0, upper_0);
  117. digitalWrite(final_output_1, upper_1);
  118. digitalWrite(final_output_2, upper_2);
  119. digitalWrite(final_output_3, upper_3);
  120. }
  121. else if(operation_0 == 1 && operation_1 == 0){
  122. digitalWrite(final_output_0, lower_0);
  123. digitalWrite(final_output_1, lower_1);
  124. digitalWrite(final_output_2, lower_2);
  125. digitalWrite(final_output_3, lower_3);
  126. }
  127. else if(operation_0 == 0 && operation_1 == 1){
  128. Serial.println("nasa 10");
  129. int sum_0 = (upper_0 + lower_0)%2;
  130. int carry_0 = (upper_0 + lower_0)/2;
  131.  
  132. int sum_1 = (upper_1 + lower_1 + carry_0)%2;
  133. int carry_1 = (upper_1 + lower_1 + carry_0)/2;
  134.  
  135. int sum_2 = (upper_2 + lower_2 + carry_1)%2;
  136. int carry_2 = (upper_2 + lower_2 + carry_1)/2;
  137.  
  138. int sum_3 = (upper_3 + lower_3 + carry_2)%2;
  139. Serial.println("SUM: ");
  140. Serial.println(sum_3);
  141. Serial.println(sum_2);
  142. Serial.println(sum_1);
  143. Serial.println(sum_0);
  144.  
  145. digitalWrite(final_output_0, sum_0);
  146. digitalWrite(final_output_1, sum_1);
  147. digitalWrite(final_output_2, sum_2);
  148. digitalWrite(final_output_3, sum_3);
  149. }
  150.  
  151. delay(1000);
  152.  
  153. //update the address of the I region
  154. first_input_0 = (first_input_0 + 1)%2;
  155. int input_carry_0 = (first_input_0 + 1)/2;
  156.  
  157. first_input_1 = (first_input_1 + 1 + input_carry_0)%2;
  158. int input_carry_1 = (first_input_1 + 1 + input_carry_0)/2;
  159.  
  160. first_input_2 = (first_input_2 + 1 + input_carry_1)%2;
  161. first_input_3 = 0;
  162.  
  163. //supply the new address to EEPROM
  164. digitalWrite(pin_0, first_input_0);
  165. digitalWrite(pin_1, first_input_1);
  166. digitalWrite(pin_2, first_input_2);
  167. digitalWrite(pin_3, first_input_3);
  168.  
  169.  
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement