Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "rims.h"
- /*
- Exercise 1 Instructions:
- 1. A lock has two switches. These are A0 and A1. Once the proper sequence is followed, the lock
- will open. Write C code for the lock using while loops to wait.
- Start at State 0, waiting for State 1 to become true, pseudocode is:
- while (!(State 1)) then wait for the correct next state condition to occur
- State A1 A0
- 0 0 0
- 1 0 1
- 2 1 1
- 3 1 0 – open the lock
- */
- unsigned char state = 0; //we initiate a variable state to zero
- //We will foollow through the sequence and B0 will work as our lock
- void main()
- {
- while (1) {
- if(state == 0 && (!A0 && !A1))
- {
- state++;
- }
- if(state == 1 && (A0 && !A1))
- {
- state++;
- }
- if(state == 2 && (A0 && A1))
- {
- state++;
- }
- if(state == 3 && (A0 && !A1))
- {
- //Open the lock
- B0 = 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement