OE-9.2 The PIC 18 Microcontroller
The NPTEL IIT Kharagpur embedded systems course — written September 2026
What this is and why it exists
The part number is not the point. This is the course's concrete small microcontroller, and what you are learning is the pattern: a processor surrounded by peripherals you configure through registers.
That pattern transfers to every microcontroller you will ever meet, from any manufacturer. The register names change; the shape does not.
One concept here is worth internalising above the others. Polling wastes the processor. Interrupts let it sleep until something happens, and on a battery-powered device that is the difference between months and days.
The vocabulary
- Microcontroller — a processor with memory and peripherals on one chip.
- Peripheral — a hardware block doing a job alongside the processor.
- Special function register — the memory location that configures or reads a peripheral.
- Addressing mode — how an instruction says where its data is.
- Timer — a counter driven by a clock.
- Polling — repeatedly asking whether something has happened.
- Interrupt — the hardware telling the processor something has happened.
- Interrupt service routine — the code that runs in response.
- Capture — recording the time at which an input changed.
- Compare — acting when a counter reaches a set value.
- Pulse-width modulation — a square wave whose on-fraction is controlled.
The mental model
Everything on the chip is configured by writing to registers, and read by reading registers. Once that lands, a datasheet stops being intimidating: you are looking for which register, which bits, and what they mean. That skill — reading a datasheet to find the bits — is more valuable than any specific part.
Timers are the foundation of most embedded work. A timer is a counter driven by a clock. From that one idea come delays, periodic tasks, measuring how long something took, and generating waveforms.
Now interrupts. Polling means asking, over and over, whether a thing has happened. The processor is fully occupied doing nothing useful, and it still might miss a brief event between two asks. An interrupt inverts it: the hardware raises a signal, the processor stops what it is doing, runs a short routine, and returns. Between events it can sleep. On a battery-powered device that inversion is decisive.
Interrupt routines have their own rules, and this is the part beginners get wrong. Keep them short. Anything slow inside one delays every other interrupt. Set a flag and let the main loop do the work. And a variable shared between an interrupt routine and the main loop can change between two lines of that loop. It is the same race condition as in any concurrent system, on a device with no operating system to blame.
Capture and compare are two sides of timing. Capture records *when* an input changed — for measuring frequency or pulse width. Compare acts when the counter *reaches* a value — for generating precisely timed output.
And pulse-width modulation is how a digital output controls an analog-seeming quantity. Switch fast and vary the fraction of time spent on, and a motor sees average power, a heater sees average heat, an eye sees brightness. The output is only ever fully on or fully off, which is exactly why it is efficient.
What you should now be able to explain or do
Describe the pattern of processor plus register-configured peripherals, and say why it transfers. Read a datasheet for which register and which bits. Use a timer for delays, periodic work and measurement. Say why interrupts beat polling, especially on battery power. Keep an interrupt routine short and explain what goes wrong otherwise. Distinguish capture from compare. Explain how pulse-width modulation controls average power efficiently.
Check yourself
What are you actually learning from a specific microcontroller?
The pattern — a processor surrounded by peripherals configured through registers. The register names change between parts and the shape does not.
Why do interrupts beat polling?
Polling occupies the processor doing nothing useful and can still miss brief events. With interrupts the processor sleeps until the hardware raises one.
Why must an interrupt routine be short?
Anything slow inside one delays every other interrupt. Set a flag and let the main loop do the work.
What is the hazard with a shared variable?
It can change between two lines of the main loop. That is a race condition, on a device with no operating system to blame it on.
How does pulse-width modulation control power?
By switching fully on and fully off quickly and varying the on-fraction, so the load sees an average. Being fully on or off is what makes it efficient.
Go deeper
We haven't checked most of these for screen reader use yet.
Back to The PIC 18 Microcontroller: work through the checklist