Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // Notes
- //
- // s = SET pin, this is the value we want to store
- // r = RESET pin, this resets the stored value to 0
- // q = OUTPUT pin, this is the result of our SR latch
- //
- // 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
- // 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
- // Q output:
- int s[] = { 0, 1, 0, 0, 1, 0, 0, 0, 0, 0 }; // Signal - this is what we want to store
- int r[] = { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }; // Reset - this changes the stored signal to zero
- int q[10];
- int notQ[10];
- int nor(int a, int b) { return !(a || b); }
- // Sets values in q and notQ
- void srLatch(int s, int r, int &q, int ¬Q)
- {
- // Help appreciated, you can't nor stuff in sequence... =/
- }
- void print(int i)
- {
- cout << "Loop is: " << i << ", \tS is: " << s[i] << ", R is: " << r[i] << ",\t Q is: " << q[i] << ", NotQ is: " << notQ[i] << endl;
- }
- int main()
- {
- for (int loop = 0; loop < 10; loop++)
- {
- srLatch(s[loop], r[loop], q[loop], notQ[loop]);
- print(loop);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement