ExamBank Scot · AH Engineering Science question bank · All AH Engineering Science questions

AH Engineering Science 2025 Question 8

3 marks · Programming control

A stair lift carries a person between two floors (floor 1 and floor 2) of a house. During the design of a microcontroller-based control system for this stair lift, a student needs to produce an 8-bit variable, called ‘flag’, containing the logical state of the five input switches connected to pins 2–6 of the data port. Pins 7, 1 and 0 are used as outputs and should be set to zero in the variable ‘flag’. INPUT PORT OUTPUT 7 Emergency 6 Call floor 1 5 Call floor 2 4 Floor 1 limit switch 3 Floor 2 limit switch 2 1 0 The student sets the PORT register to the binary value 11111111, so that the required value of ‘flag’ becomes binary value 01111100. The student tests three commands that perform bitwise logic between two registers: PBASIC (1) flag = PORTB | %01111100 (bitwise OR) (2) flag = PORTB & %01111100 (bitwise AND) (3) flag = PORTB ^ %01111100 (bitwise XOR) ARDUINO (1) flag = PORTD | 0b01111100 (bitwise OR) (2) flag = PORTD & 0b01111100 (bitwise AND) (3) flag = PORTD ^ 0b01111100 (bitwise XOR) Note that 00110000 | 01010000 gives the result 01110000, where numbers are binary. Determine which of the three commands should be used, stating the binary value of ‘flag’ that results in each case.

Marking scheme

PBASIC flag = PORTB | %01111100 flag = %11111111 | %01111100 flag = %11111111 flag = PORTB & %01111100 flag = %11111111 & %01111100 flag = %01111100 flag = PORTB ^ %01111100 flag = %11111111 ^ %01111100 flag = %10000011 Using the second command, bitwise AND, produces the required value in flag. ARDUINO flag = PORTD | 0b01111100 flag = 0b11111111 | 0b01111100 flag = 0b11111111 flag = PORTD & 0b01111100 flag = 0b11111111 & 0b01111100 flag = 0b01111100 flag = PORTD ^ 0b01111100 flag = 0b11111111 ^ 0b01111100 flag = 0b10000011 Using the second command, bitwise AND, produces the required value in flag. 1 mark Any two of the three logical outcomes correct. 1 mark Third logical outcome correct. 1 mark Statement of correct logic to use to fit the specification (must be supported by working).

Previous question: AH Engineering Science 2025 Question 7

Next question: AH Engineering Science 2025 Question 9