How is a microcontroller program structured, and how do flowcharts represent decisions, loops and subroutines?
Microcontroller programming: flowcharts, sequence, selection and iteration, input and output instructions, time delays, subroutines, and translating a system specification into a program.
A focused answer to WJEC A-Level Electronics microcontroller programming, covering flowcharts, the program structures of sequence, selection and iteration, input and output instructions, time delays, subroutines, and turning a system specification into a working program.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this dot point is asking
A microcontroller does nothing without a program, and Component 2 expects you to design and read programs using flowcharts. WJEC expects you to use the three program structures (sequence, selection, iteration), write input and output and delay instructions, use subroutines, and translate a worded system specification into a program. The flowchart design question and the subroutine explanation are reliable, high-mark exam content.
The answer
The three program structures
Flowcharts
Flowcharts are the WJEC-preferred way to plan and present a program, because they make the sequence, decisions and loops visible at a glance.
Inputs, outputs and time delays
A program reads inputs (the state of switches and sensors), drives outputs (turning pins high or low to control LEDs, motors and so on), and uses time delays to control timing, for example to flash a light or debounce a switch.
Subroutines
Examples in context
- Example 1. A pedestrian crossing controller
- The program is a loop: it waits for the button (selection), then runs a timed sequence of light changes using delays, before returning to wait again. The three structures appear together, and the timed light sequence is a subroutine reused for each cycle.
- Example 2. Reading a sensor and reacting
- A program reads a temperature through the ADC each loop (input), decides with a selection whether it is above a threshold, and drives a fan output accordingly. The forever loop means the system keeps responding to changing temperature, which a single pass could not.
- Example 3. Debouncing a switch
- When a switch is pressed, its contacts bounce, giving several quick transitions. A short delay subroutine after detecting a press lets the bounce settle before the program reads again, so one press registers once. This shows a time delay solving a real interfacing problem in software.
Try this
Q1. Name the three basic program structures and say what each does. [3 marks]
- Cue. Sequence (steps in order), selection (a decision that branches, an if), iteration (a loop that repeats).
Q2. Give one advantage of using a subroutine in a microcontroller program. [1 mark]
- Cue. It avoids repeating code (write once, call many times), saving program memory; or it makes the program clearer and easier to test.
Exam-style practice questions
Practice questions written in the style of WJEC exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
WJEC Eduqas 20206 marksA microcontroller must flash an LED on for 1 second and off for 1 second, repeating forever, while also checking a switch each cycle and stopping the flashing if the switch is pressed. Describe, using flowchart structures, how the program would be organised.Show worked answer →
The program is an iteration (loop) containing output, delay and a selection.
Start: set the LED pin as an output and the switch pin as an input.
Main loop (repeat forever): turn the LED on; wait 1 second (a time delay or delay subroutine); turn the LED off; wait 1 second; then check the switch with a selection (decision): if the switch is pressed, branch out of the loop to a stopped state (LED off); if not, loop back to the start of the main loop.
The structures used are sequence (the ordered steps), iteration (the repeating loop), and selection (the if-switch-pressed decision), with a delay subroutine called twice.
Markers reward the loop structure, the on/delay/off/delay sequence, the switch decision (selection) branching out, and the use of a delay.
WJEC Eduqas 20184 marksExplain what a subroutine is in a microcontroller program and give two advantages of using one.Show worked answer →
A subroutine is a named, self-contained block of code that performs a specific task and can be called from anywhere in the program; when it finishes it returns to the point it was called from.
Advantages: it avoids repeating the same code (a task such as a time delay is written once and called many times, saving program memory), it makes the program easier to read and structure, and it makes testing and maintenance easier because the block can be checked on its own. Any two of these are acceptable.
Markers reward the definition (reusable called block that returns) and two valid advantages (no repetition/saves memory, readability, easier testing).
Related dot points
- Microcontroller architecture and interfacing: the structure of a microcontroller (CPU, memory, ports), digital input and output ports, interfacing switches, sensors and output devices, and the on-chip ADC.
A focused answer to WJEC A-Level Electronics microcontroller architecture and interfacing, covering the structure of a microcontroller (CPU, memory and ports), digital input and output ports, interfacing switches, sensors and output devices, and the on-chip analogue-to-digital converter.
- Sequential logic and flip-flops: the difference between combinational and sequential logic, the SR latch, D-type and JK flip-flops, clocking, and using flip-flops to build counters and shift registers.
A focused answer to WJEC A-Level Electronics sequential logic, covering the difference between combinational and sequential logic, the SR latch, D-type and JK flip-flops, clocking and edge triggering, and how flip-flops are connected to make counters and shift registers.
- Timing circuits and oscillators: RC timing, the monostable and astable using the 555 timer or op-amp, the period and frequency equations, and the production of square waves and clock signals.
A focused answer to WJEC A-Level Electronics timing circuits and oscillators, covering RC timing, the monostable (one-shot) and astable multivibrator using the 555 timer or an op-amp, the period and frequency equations, and the generation of square waves and clock signals.
- Combinational logic design: deriving a circuit from a truth table or specification, sum-of-products form, simplification with Karnaugh maps, and building any function from NAND gates only.
A focused answer to WJEC A-Level Electronics combinational logic design, covering deriving a circuit from a truth table, sum-of-products form, simplification using Karnaugh maps, the universality of the NAND gate, and the design process from specification to gates.
- Input and output sub-systems: sensors and input transducers (LDR, thermistor, switches) in potential dividers, and output transducers (LED, buzzer, relay, motor) with their driver and interfacing requirements.
A focused answer to the WJEC A-Level Electronics core concept of input and output sub-systems, covering input transducers such as the LDR and thermistor in potential dividers, switch inputs, and output transducers including LEDs, buzzers, relays and motors with their driver requirements.
Sources & how we know this
- WJEC Eduqas GCE A-level Electronics specification — WJEC Eduqas (2017)