Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include "rims.h"
  2.  
  3. /*
  4. Exercise 1 Instructions:
  5.  
  6. 1. A lock has two switches. These are A0 and A1. Once the proper sequence is followed, the lock
  7. will open. Write C code for the lock using while loops to wait.
  8. Start at State 0, waiting for State 1 to become true, pseudocode is:
  9. while (!(State 1)) then wait for the correct next state condition to occur
  10. State A1 A0
  11. 0 0 0
  12. 1 0 1
  13. 2 1 1
  14. 3 1 0 – open the lock
  15.       */
  16. unsigned char state = 0; //we initiate a variable state to zero
  17.      
  18. //We will foollow through the sequence and B0 will work as our lock
  19.  
  20. void main()
  21. {
  22.    while (1) {
  23.       if(state == 0 && (!A0 && !A1))
  24.       {
  25.           state++;
  26.       }
  27.       if(state == 1 && (A0 && !A1))
  28.       {
  29.           state++;
  30.       }
  31.          if(state == 2 && (A0 && A1))
  32.       {
  33.           state++;
  34.       }
  35.            if(state == 3 && (A0 && !A1))
  36.       {
  37.           //Open the lock
  38.           B0 = 1;
  39.       }
  40.    }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement