EuraStudy
A microcontroller replaces hard-wired logic with a small programmable computer on a chip. This chapter develops the internal structure of the PIC microcontroller, the input-process-output systems view expressed as flowcharts, the essentials of assembler programming and port control, and the reasoned choice between a programmable and a hard-wired solution.
4 sections~16 min reading time3 competenciesLevel Standard 2 · Advanced 2
basic level
At AS the focus is the idea of a programmable device and the input-process-output flowchart.
higher level
The full A-Level develops the PIC architecture, assembler and port control, and the evaluation of programmable versus hard-wired designs.
Reading depth: In depth
Text size: Standard
PIC microcontroller architecture
Instruction cycle
The CPU repeatedly fetches, decodes and executes stored instructions.
A PIC controls a battery-powered timer. Explain what happens to its program and its stored count when the battery is briefly removed and replaced.
The program is held in non-volatile flash program memory, so it survives the loss of power and is still there when the battery returns.
The running count is held in volatile RAM (data memory), which loses its contents when power is removed, so the count is lost.
On power-up the program runs again from the start, but the count restarts from its initial value unless it was saved to non-volatile memory (EEPROM).
Result: The program survives (flash) but the count is lost (RAM); persistent data would need to be stored in non-volatile EEPROM.
Typical mistakes
Active revision
State which PIC memory holds the program and which holds the variables, and explain what the TRIS and PORT registers do for an I/O pin connected to a switch.
Active recall
Recall the key points — then reveal.
Sources: WJEC/Eduqas GCE Electronics specification (WJEC / Eduqas)
Flowchart: switch-controlled LED
Structured programming
The three constructs from which any program is built.
A flowchart reads a switch, and if it is pressed turns an LED on, otherwise turns it off, then loops back to read the switch. Describe the behaviour and identify the three structured-programming constructs used.
The program continuously reads the switch and drives the LED to match: on while pressed, off while released — a real-time responsive control.
The decision 'switch pressed?' is a selection: it chooses between the 'LED on' and 'LED off' branches.
Within each branch the steps run in sequence; the loop-back arrow gives iteration, so the whole thing repeats forever.
Result: The LED tracks the switch in real time; the flowchart uses sequence (steps in order), selection (the decision) and iteration (the loop).
Typical mistakes
Active revision
Draw a flowchart for a program that turns an LED on while a switch is pressed and off when it is released, repeating continuously, using the correct flowchart symbols.
Active recall
Recall the key points — then reveal.
Sources: WJEC/Eduqas GCE Electronics specification (WJEC / Eduqas)
A short PIC assembler routine
Port direction
The TRIS register sets each pin as input or output before PORT is used.
In the routine above, describe what happens on each pass of the loop when the switch (RB0) is pressed (reads 1) and when it is released (reads 0).
BTFSS tests RB0; because it is 1 the next instruction (BCF, LED off) is skipped, so BSF runs and the LED is turned on.
BTFSS tests RB0; because it is 0 the next instruction is not skipped, so BCF runs and turns the LED off (the following BSF would then turn it on, so a correct program would branch past it).
GOTO loop returns to the test, so the LED is updated continuously to follow the switch.
Result: When pressed the skip causes the LED to be set on; when released the LED is cleared off; the GOTO makes it repeat, so the LED tracks the switch.
Typical mistakes
Active revision
Write, in words or as assembler, the steps to configure PORTB bit 0 as an input (a switch) and bit 1 as an output (an LED), then continuously make the LED match the switch.
Active recall
Recall the key points — then reveal.
Sources: WJEC/Eduqas GCE Electronics specification (WJEC / Eduqas)
Programmable versus hard-wired
The core trade-off
Programmable gives flexibility and low part count; hard-wired gives raw speed for simple fixed tasks.
Recommend a solution for (a) a washing machine with several selectable wash programmes and (b) a simple two-input priority encoder needing the fastest possible response.
The task is complex (timing, sequencing, several programmes) and may need updating, so a microcontroller is ideal: the programmes are software, changeable without rewiring, and one chip replaces much logic.
The task is trivial and purely combinational but must be as fast as possible; hard-wired gates respond in nanoseconds with no instruction overhead, so hard-wired logic is the better choice.
The decision follows the demands: complexity and changeability favour the microcontroller; raw speed and simplicity favour hard-wired logic.
Result: Use a microcontroller for the washing machine (complex, changeable) and hard-wired logic for the priority encoder (simple, fastest).
Typical mistakes
Active revision
Recommend, with reasons, whether to use a microcontroller or hard-wired logic for (a) a washing-machine controller with several programmes, and (b) a simple, very fast two-input priority encoder.
Active recall
Recall the key points — then reveal.
Sources: WJEC/Eduqas GCE Electronics specification (WJEC / Eduqas)
References & sources
WJEC / Eduqas