Advertisement
Guest User

Untitled

a guest
Jan 9th, 2017
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // Notes
  6. //
  7. // s = SET pin, this is the value we want to store
  8. // r = RESET pin, this resets the stored value to 0
  9. // q = OUTPUT pin, this is the result of our SR latch
  10. //
  11. // If s = 1 and r = 0 then we write 1 to q (so notQ should be 0) and all further s = 0 and r = 0 inputs should keep q as 1
  12. // If s = 0 and r = 1 then we write 0 to q (so notQ should be 1) and all further s = 0 and r = 0 inputs should keep q as 0
  13.  
  14. // Q output:
  15. int s[] = { 0, 1, 0, 0, 1, 0, 0, 0, 0, 0 }; // Signal - this is what we want to store
  16. int r[] = { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }; // Reset - this changes the stored signal to zero
  17. int q[10];
  18. int notQ[10];
  19.  
  20. int nor(int a, int b) { return !(a || b); }
  21.  
  22. // Sets values in q and notQ
  23. void srLatch(int s, int r, int &q, int &notQ)
  24. {
  25. // Help appreciated, you can't nor stuff in sequence... =/
  26. }
  27.  
  28. void print(int i)
  29. {
  30. cout << "Loop is: " << i << ", \tS is: " << s[i] << ", R is: " << r[i] << ",\t Q is: " << q[i] << ", NotQ is: " << notQ[i] << endl;
  31. }
  32.  
  33. int main()
  34. {
  35. for (int loop = 0; loop < 10; loop++)
  36. {
  37. srLatch(s[loop], r[loop], q[loop], notQ[loop]);
  38. print(loop);
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement