Digital Circuits
Microcontroller Principles
20 questions By Tony R. Kuphaldt
-
Question 7 of 20
Examine the following schematic diagram and program listing (written in “pseudocode” rather than a formal programming language) to determine what type of basic logic function is being implemented in this microcontroller unit:

Pseudocode listing Declare Pin0 as an output
Declare Pin1 and Pin2 as inputs
LOOP
IF Pin1 is LOW, set Pin0 HIGH
ELSEIF Pin2 is LOW, set Pin0 HIGH
ELSE set Pin0 LOW
ENDIF
ENDLOOP
Reveal answerThis microcontroller implements the logical NAND function.
Notes:Although this logic function could have been implemented easier and cheaper in hard-wired (gate) logic, the purpose is to get students to think of performing logical operations by a sequenced set of instructions inside a programmable device (the MCU). This is a conceptual leap, basic but very important.
In case you’re wondering why I write in pseudocode, here are a few reasons:
- No prior experience with programming required to understand pseudocode
- It never goes out of style
- Hardware independent
- No syntax errors
If I had decided to showcase code that would actually run in a microcontroller, I would be dooming the question to obsolescence. This way, I can communicate the spirit of the program without being chained to an actual programming standard. The only drawback is that students will have to translate my pseudocode to real code that will actually run on their particular MCU hardware, but that is a problem guaranteed for some regardless of which real programming language I would choose.
Of course, I could have taken the Donald Knuth approach and invented my own (imaginary) hardware and instruction set . . .
-
Question 8 of 20
Examine the following schematic diagram and program listing (written in “pseudocode” rather than a formal programming language) to determine what type of basic logic function is being implemented in this microcontroller unit:

Pseudocode listing Declare Pin0 as an output
Declare Pin1 and Pin2 as inputs
LOOP
IF Pin1 is HIGH, set Pin0 LOW
ELSEIF Pin2 is HIGH, set Pin0 LOW
ELSE set Pin0 HIGH
ENDIF
ENDLOOP
Reveal answerThis microcontroller implements the logical NOR function.
Notes:Although this logic function could have been implemented easier and cheaper in hard-wired (gate) logic, the purpose is to get students to think of performing logical operations by a sequenced set of instructions inside a programmable device (the MCU). This is a conceptual leap, basic but very important.
In case you’re wondering why I write in pseudocode, here are a few reasons:
- No prior experience with programming required to understand pseudocode
- It never goes out of style
- Hardware independent
- No syntax errors
If I had decided to showcase code that would actually run in a microcontroller, I would be dooming the question to obsolescence. This way, I can communicate the spirit of the program without being chained to an actual programming standard. The only drawback is that students will have to translate my pseudocode to real code that will actually run on their particular MCU hardware, but that is a problem guaranteed for some regardless of which real programming language I would choose.
Of course, I could have taken the Donald Knuth approach and invented my own (imaginary) hardware and instruction set . . .
-
Question 9 of 20
Examine the following schematic diagram and program listing (written in “pseudocode” rather than a formal programming language) to determine what type of basic logic function is being implemented in this microcontroller unit:

Pseudocode listing Declare Pin0 as an output
Declare Pin1 and Pin2 as inputs
LOOP
IF Pin1 is same as Pin2, set Pin0 LOW
ELSE set Pin0 HIGH
ENDIF
ENDLOOP
Reveal answerThis microcontroller implements the logical Exclusive-OR function.
Notes:Although this logic function could have been implemented easier and cheaper in hard-wired (gate) logic, the purpose is to get students to think of performing logical operations by a sequenced set of instructions inside a programmable device (the MCU). This is a conceptual leap, basic but very important.
In case you’re wondering why I write in pseudocode, here are a few reasons:
- No prior experience with programming required to understand pseudocode
- It never goes out of style
- Hardware independent
- No syntax errors
If I had decided to showcase code that would actually run in a microcontroller, I would be dooming the question to obsolescence. This way, I can communicate the spirit of the program without being chained to an actual programming standard. The only drawback is that students will have to translate my pseudocode to real code that will actually run on their particular MCU hardware, but that is a problem guaranteed for some regardless of which real programming language I would choose.
Of course, I could have taken the Donald Knuth approach and invented my own (imaginary) hardware and instruction set . . .


