Program "Elevator" for the HT46F47 microcontroller | (vs. 20160310) | ||||||
addr. | instr. | mnemonics | jmps&clls | addr.high | comments | ||
Initialize | |||||||
00 | 41 | A = 0001 | Elevator on ground floor | ||||
01 | 11 | Port = 0001 | Set the 4 leds accordingly | ||||
02 | 53 | D = A | Keep track of elevator in register D | ||||
02 | |||||||
02 | Main loop | ||||||
03 | 82 | Page = 2 | 2 | Set addr.high | |||
04 | 90 | Jump 20 | Jump 20 | Wait for user input - return choice in register C | |||
04 | |||||||
05 | 81 | Page = 1 | 1 | User input returns here---------------- | Set addr.high | ||
06 | D3 | Call 13 | Call 13 | Show departure from current floor by flashing several times | |||
06 | |||||||
07 | 63 | A = D | Get current and chosen floor to determine direction to go | ||||
08 | 51 | B = A | Store current floor in B | ||||
09 | 62 | A = C | Store chosen floor in A | ||||
09 | |||||||
0A | 83 | Page = 3 | 3 | Set addr.high | |||
0B | C2 | Skip if A<B | Is chosen floor above or below current floor? | ||||
0C | 9C | Jump 3C | Jump 3C | Above, go up | |||
0D | 85 | Page = 5 | 5 | Set addr.high | |||
0E | 9E | Jump 5E | Jump 5E | Below, go down | |||
0E | |||||||
0F | 63 | A = D | We arrived at chosen floor | ('Up' and 'Down' returns here) | |||
10 | 54 | Dout = A | Get floor and show in the 4 leds | ||||
10 | |||||||
11 | 80 | Page = 0 | 0 | Set addr.high | |||
12 | 93 | Jump 03 | Jump 03 | Loop back to get new floor choice | |||
12 | |||||||
12 | Show current floor | ||||||
13 | 62 | A = C | Save chosen floor | ||||
14 | 51 | B = A | in register B | ||||
14 | |||||||
15 | 43 | A = 3 | Set counter to 4 - 1 = 3 | ||||
16 | 52 | C = A | to flash 4 times | ||||
17 | 63 | A = D | Put current floor in A | ||||
17 | |||||||
18 | 10 | Port = 0000 | Flash leds current floor ------------ | All leds off | |||
19 | 27 | Wait 200 ms | Wait some time | ||||
1A | 54 | Dout = A | Led current floor on | ||||
1B | 27 | Wait 200 ms | Wait some time | ||||
1C | A8 | C-Jump 18 | Jump 18 | Do this another C times | |||
1C | |||||||
1D | 61 | A = B | Restore chosen floor | ||||
1E | 52 | C = A | in register C | ||||
1F | E0 | Return | Return | ||||
1F | |||||||
1F | Get floor choice (invoked by main loop - addr.04; return - addr.05) | ||||||
20 | C8 | Skip if Din.0 = 0 | Ground floor button pressed? | If ... | |||
21 | 94 | Jump 24 | Jump 24 | No, test 1st floor button | Else ... | ||
22 | 41 | A = 0001 | Yes, set A accordingly | Then ... | |||
23 | 9F | Jump 2F | Jump 2F | and leave loop | Then ... | ||
24 | C9 | Skip if Din.1 = 0 | First floor button pressed? | If ... | |||
25 | 98 | Jump 28 | Jump 28 | No, test 2nd floor button | Else ... | ||
26 | 42 | A = 0010 | Yes, set A accordingly | Then ... | |||
27 | 9F | Jump 2F | Jump 2F | and leave loop | Then ... | ||
28 | CA | Skip if Din.2 = 0 | Second floor button pressed? | If ... | |||
29 | 9C | Jump 2C | Jump 2C | No, test 3st floor button | Else ... | ||
2A | 44 | A = 0100 | Yes, set A accordingly | Then ... | |||
2B | 9F | Jump 2F | Jump 2F | and leave loop | Then ... | ||
2C | CB | Skip if Din.3 = 0 | Third floor button pressed? | If ... | |||
2D | 90 | Jump 20 | Jump 20 | No, jump back | Else ... | ||
2E | 48 | A = 1000 | Yes, set A accordingly | Then ... | |||
2F | 51 | B = A | Store choice in register B for now | Then ... | |||
2F | |||||||
30 | 63 | A = D | Test need to move ------------------- | Get current floor | |||
31 | 83 | Page = 3 | 3 | Set addr.high | |||
32 | C3 | Skip if A = B | Are we on chosen floor? | ||||
33 | 98 | Jump 38 | Jump 38 | No, continue | |||
34 | 81 | Page = 1 | 1 | Set addr.high | |||
35 | D3 | Call 13 | Call 13 | Yes, signalize we are already there - stay where we are | |||
36 | 82 | Page = 2 | 2 | Set addr.high | |||
37 | 90 | Jump 20 | Jump 20 | and jump back to wait for new choice | |||
37 | |||||||
38 | 61 | A = B | Get user choice | ||||
39 | 52 | C = A | Chosen floor is stored in C | ||||
3A | 80 | Page = 0 | 0 | Set addr.high | |||
3B | 95 | Jump 05 | Jump 05 | Jump back to main loop to depart from floor | |||
3B | |||||||
3B | Go up (invoked by main loop - addr.0C; return - addr.0F) | ||||||
3C | 84 | Page = 4 | 4 | Set addr.high | |||
3D | DD | Call 4D | Call 4D | Simulate going up | |||
3D | |||||||
3E | 42 | A = 2 | We are one floor higher ------------ | Get 2 | |||
3F | 51 | B = A | B = 2 | ||||
40 | 63 | A = D | Get old current floor | ||||
41 | 75 | A = AxB | multiplicate by 2 -- shift left | ||||
42 | 53 | D = A | Store new current floor in register D | ||||
42 | |||||||
43 | 81 | Page = 1 | 1 | Set addr.high | |||
44 | D3 | Call 13 | Call 13 | Show arrival on new floor | |||
44 | |||||||
45 | 63 | A = D | Compare floors ------------------------ | Get current floor | |||
46 | 51 | B = A | B = (new) current floor | ||||
47 | 62 | A = C | Get chosen floor | ||||
47 | |||||||
48 | 83 | Page = 3 | 3 | Set addr.high | |||
49 | C3 | Skip if A = B | Test wether we arrived at chosen floor | ||||
4A | 9C | Jump 3C | Jump 3C | No, another floor up | |||
4B | 80 | Page = 0 | 0 | Yes, we are on chosen floor | |||
4C | 9F | Jump 0F | Jump 0F | Jump back to finish main loop | |||
4C | |||||||
4C | Simulate going up | ||||||
4D | 62 | A = C | Save chosen floor | ||||
4E | 51 | B = A | in B | ||||
4E | |||||||
4F | 42 | A = 2 | Set counter to 3 - 1 = 2 | ||||
50 | 52 | C = A | in order to signalize ‘up’ 3 times | ||||
50 | |||||||
51 | 85 | Page = 5 | 5 | Set addr.high | |||
52 | 11 | Port = 0001 | Simulate going up ------------------- | Low | |||
53 | 27 | Wait 200 ms | Wait | ||||
54 | 12 | Port = 0010 | Higher | ||||
55 | 27 | Wait 200 ms | Wait | ||||
56 | 14 | Port = 0100 | Higher | ||||
57 | 27 | Wait 200 ms | Wait | ||||
58 | 18 | Port = 1000 | High | ||||
59 | 27 | Wait 200 ms | Wait | ||||
5A | A2 | C-Jump 52 | Jump 52 | Jump back C times | |||
5A | |||||||
5B | 61 | A = B | Restore chosen floor | ||||
5C | 52 | C = A | in C | ||||
5D | E0 | Return | Return | ||||
5D | |||||||
5D | Go down (invoked by main loop - addr.0E; return - addr.0F) | ||||||
5E | 86 | Page = 6 | 6 | Set addr.high | |||
5F | DF | Call 6F | Call 6F | Simulate going down | |||
5F | |||||||
60 | 42 | A = 2 | We are one floor lower ------------- | Get 2 | |||
61 | 51 | B = A | B = 2 | ||||
62 | 63 | A = D | Get old current floor | ||||
63 | 76 | A = A/B | divide by 2 -- shift right | ||||
64 | 53 | D = A | Store new current floor in register D | ||||
64 | |||||||
65 | 81 | Page = 1 | 1 | Set addr.high | |||
66 | D3 | Call 13 | Call 13 | Show arrival on new floor | |||
66 | |||||||
67 | 63 | A = D | Compare floors ------------------------ | Get current floor | |||
68 | 51 | B = A | B = (new) current floor | ||||
69 | 62 | A = C | Get chosen floor | ||||
69 | |||||||
6A | 85 | Page = 5 | 5 | Set addr.high | |||
6B | C3 | Skip if A = B | Test wether we arrived at chosen floor | ||||
6C | 9E | Jump 5E | Jump 5E | No, another floor down | |||
6D | 80 | Page = 0 | 0 | Yes, we are on chosen floor | |||
6E | 9F | Jump 0F | Jump 0F | Jump back to finish main loop | |||
6E | |||||||
6E | Simulate going down | ||||||
6F | 62 | A = C | Save chosen floor | ||||
70 | 51 | B = A | in register B | ||||
70 | |||||||
71 | 42 | A = 2 | Set counter to 3 - 1 = 2 | ||||
72 | 52 | C = A | in order to signalize ‘down’ 3 times | ||||
72 | |||||||
73 | 87 | Page = 7 | 7 | Set addr.high | |||
74 | 18 | Port = 1000 | Simulate going down --------------- | High | |||
75 | 27 | Wait 200 ms | Wait | ||||
76 | 14 | Port = 0100 | Lower | ||||
77 | 27 | Wait 200 ms | Wait | ||||
78 | 12 | Port = 0010 | Lower | ||||
79 | 27 | Wait 200 ms | Wait | ||||
7A | 11 | Port = 0001 | Low | ||||
7B | 27 | Wait 200 ms | Wait | ||||
7C | A4 | C-Jump 74 | Jump 74 | Jump back C times | |||
7C | |||||||
7D | 61 | A = B | Restore chosen floor | ||||
7E | 52 | C = A | in C | ||||
7F | E0 | Return | Return | ||||
7F |