Start Here: What Embedded Means
Before any C, it helps to know what you are writing it for. This volume explains what an embedded system is, what sits inside a microcontroller, and the path your code takes from a text file to a running chip. Then you write and run your first program, with nothing to install.
- What an embedded system is, and where you meet one every day
- What is inside a microcontroller, and how it differs from a laptop
- How your C becomes machine code that a chip runs at power-on
- How to compile and run every program in this course, free in a browser
- How to get the most out of this course
- Nothing at all. This is the first volume, and it assumes no programming and no electronics.
0.1 What an embedded system is
An embedded system is a computer hidden inside something that is not a computer. It does one job, for years, and nobody thinks of it as a computer at all.
Your microwave has one. So does your washing machine, your car's wing mirror, the fitness band on your wrist and the charger for your phone. None of them has a screen full of apps. Each one has a small chip running a program that was written once and never changes.
That program is called firmware, and it is usually written in C.
Where you meet them
| The thing | What its chip does | Why not just a switch? |
|---|---|---|
| Washing machine | Runs the wash: fill, wash, rinse, spin, each for a set time | The order and the timing change with the programme you pick |
| Car wing mirror | Folds the mirror, heats the glass, dips it when reversing | It has to listen to the door lock, the heater button and the gearbox |
| Fitness band | Reads the heart sensor, counts steps, drives the screen | It must run for days on one small battery |
| Phone charger | Watches voltage and current, and stops if something is wrong | Safety rules need a decision many times a second |
| Smoke alarm | Samples the sensor, sounds the horn, checks its own battery | It must work, untouched, for ten years |
"Embedded" means the computer is built into the product. You cannot install anything on it, and most people never learn it is there. The job is fixed, and the chip does only that.
What makes embedded different
- One job, forever. The program starts when the power comes on and runs until the power goes off.
- Very little memory. A laptop has gigabytes. A small chip has a few kilobytes, and you count every byte.
- It cannot crash. Nobody reboots a smoke alarm. The code has to keep going for years.
- It touches the real world. Pins, sensors, motors and lights, not files and windows.
- Timing is part of the job. A late answer can be as wrong as no answer.
Thinking embedded C is a different language. It is the same C. What changes is where it runs: no operating system underneath, no hard disk, no printing to a screen unless you wire one up. The rules you learn here are the rules of C everywhere.
Which of these is an embedded system?
Show the answer
Answer: C. The washing machine's controller is a computer built into a product, doing one fixed job. The others are general-purpose computers or programs that run on one.
0.2 Microcontrollers vs computers
A microcontroller is a whole computer on one chip: a processor, its memory, and the hardware that reaches the outside world. It is small, cheap and slow by laptop standards, and that is exactly the point.
The same parts, a thousand times smaller
| Laptop | Small microcontroller | |
|---|---|---|
| Processor speed | a few GHz, several cores | 8 MHz to 200 MHz, usually one core |
| Working memory | 8 to 32 GB of RAM | 2 KB to 256 KB of SRAM |
| Program storage | a disk holding hundreds of GB | 16 KB to 2 MB of flash, on the chip |
| Operating system | Windows, macOS or Linux | often none at all |
| Power | tens of watts | a few milliwatts, sometimes less |
| Price | hundreds of pounds | under a pound, often well under |
| Starts in | tens of seconds | a few milliseconds |
Look at the memory row again. A single photo would not fit in the SRAM of a small chip. That one fact shapes everything in this course.
Two kinds of memory, and the difference matters every day. Flash keeps what it holds when the power goes off, so the program lives there. SRAM forgets everything the moment the power goes, so your variables live there and start again at every power-on.
Assuming the chip will "just run faster if I write better code". On a laptop you can often trade memory for speed. On a microcontroller you may have 8 KB of SRAM, full stop. Design for the size first, and the speed usually follows.
Where does a microcontroller keep your program, so that it is still there after the power has been off?
Show the answer
Answer: B. Flash keeps its contents with no power, so the program is stored there. SRAM is the working memory for variables, and it is empty at every power-on.
0.3 How code becomes a running chip
A chip cannot read C. Your text file is turned into numbers the processor understands, given addresses, and copied into the chip's flash. At power-on, the chip starts running those numbers.
Four steps, every time
- You write C. A file of plain text, such as blink.c. A person can read it; a chip cannot.
- The compiler translates it. The compiler turns your C into machine code: the numbers this one processor knows how to obey.
- The linker arranges it. The linker joins your pieces with the library pieces, and decides which address each part lives at.
- The image is flashed. The finished firmware image is copied into the chip's flash over a cable. From then on the chip runs it every time it is powered.
Together, those programs are called the toolchain. When the compiler runs on your computer but makes code for a different processor, it is a cross-compiler. That is the normal case in embedded work: you write on a laptop, the code runs on a chip.
Think of a recipe. Your C is the recipe in English. The compiler translates it into the language of one particular kitchen. The linker decides which shelf each ingredient sits on. Flashing is taping the finished, translated recipe inside that kitchen, so the cook follows it every morning.
Going deeper: the same C, two different chips
Compile the same C file for two different processors and you get two different sets of numbers. Neither chip can run the other's code. That is why a program built for an Arm chip will not run on your laptop's processor, even though both came from one text file. The C is portable; the machine code is not.
Here is a program of the kind this course builds towards. It will not run in an online compiler, because your computer has no pin called LED - but a chip does.
#include "board.h"
int main(void)
{
led_init(); /* set the LED pin as an output */
for (;;) { /* forever */
led_on();
delay_ms(500);
led_off();
delay_ms(500);
}
}
Notice the for (;;) loop with no end. On a computer, a program finishes and gives control back to
the operating system. On a chip, there is nothing to go back to, so firmware loops for ever.
What does the linker do?
Show the answer
Answer: A. The compiler translates C into machine code, one file at a time. The linker then joins those pieces with the libraries and lays them out at real addresses, producing the image that gets flashed.
0.4 Tools: an online compiler, GCC and a simulator
You need nothing but a browser to do this course. Every program here compiles and runs in a free online C compiler, and prints its answer where you can see it.
Your first program
#include <stdio.h>
#include <stdint.h>
int main(void)
{
printf("Hello, embedded world!\n");
printf("char %zu, short %zu, int %zu, long %zu bytes\n",
sizeof(char), sizeof(short), sizeof(int), sizeof(long));
return 0;
}
Run it, and you get:
Hello, embedded world!
char 1, short 2, int 4, long 8 bytes
The first line is the traditional greeting. The second asks the compiler how big its number types are, in bytes. Those sizes are not the same on every machine, and that turns out to matter a great deal in embedded work. Volume 02 comes back to it.
- Open a free online C compiler in another tab.
- Delete whatever example it starts with.
- Type the program above. Typing it beats pasting: your fingers remember what your eyes skim.
- Press Run, and read the output.
The three ways to run C in this course
| Way | Good for | What it costs |
|---|---|---|
| An online compiler, in a browser | Everything in Volumes 01 to 09 | Nothing, and nothing to install |
| GCC on your own computer | Working offline, and bigger projects | Free. Built in on Linux and macOS; on Windows use WSL or MinGW |
| A browser simulator with a virtual board | Watching an LED blink without buying one | Nothing. Wokwi is one free example |
Trying to run chip-only code, such as the blink above, in an online compiler. Your computer has no LED pin, so it cannot work. Every listing in this course says where it runs. When a program needs hardware, the course gives you a small stand-in written in plain C, so you can still run it.
What do you need before you can start Volume 01?
Show the answer
Answer: B. Everything in the early volumes runs in a browser. A board is welcome later if you have one, but the course never depends on it.
0.5 How to use this course
Read in order, type every program yourself, and change one thing before you move on. That habit is worth more than any amount of reading.
How to work through a volume
- Read the sub-module. Each one is short, and ends with a quick check.
- Type the program. Not paste - type. You will meet the compiler's error messages, which is the point.
- Run it, and read the output. Compare it with what the lesson says you should see.
- Change one thing. A number, a type, an operator. Predict what happens, then run it again.
- Take the quick check. If it goes wrong, the answer says why, and which idea to re-read.
What the boxes mean
| Box | What it holds |
|---|---|
| The big idea | The one sentence to remember from that sub-module |
| In plain words | The same idea again, with no jargon at all |
| Think of it like this | An everyday comparison |
| Common mistake | The trap most beginners fall into, and how to avoid it |
| Going deeper | Optional detail. Skip it on a first read |
| Quick check | One question. Answer it before moving on |
Every C program in this course was compiled with warnings turned on, and run, before it was published. When a lesson shows output, that is the real output. If yours differs, something interesting is happening - and that is worth chasing.
A word about hardware
Nothing here needs a board. Where a lesson talks about registers or pins, it models them in plain C so the program still runs on your computer. Later, if you do pick up a board, everything transfers: the same C, the same ideas, real pins.
The course says: type the programs rather than paste them. Why?
Show the answer
Answer: C. Typing produces small mistakes, and small mistakes produce error messages. Reading those messages is a large part of learning C, and it is much easier to practise on a five-line program.
What you learned
- An embedded system is a computer built into a product, doing one fixed job for years.
- A microcontroller holds a processor, flash, SRAM and peripherals on a single chip.
- Flash keeps the program with the power off; SRAM holds the variables while it runs.
- Your C is compiled to machine code, linked to addresses, and flashed into the chip.
- A cross-compiler runs on your computer but makes code for the chip.
- Firmware loops for ever, because there is no operating system to return to.
- Everything in this course runs free in a browser; a board is optional.
Key words from this volume
Every word below has a plain-English entry in the glossary.
- Embedded system
- Firmware
- Microcontroller
- Compiler
- Machine code
- Linker
- Firmware image
- Toolchain
- Cross-compiler
- Byte
Practice
Spot the embedded system
Which of these contain an embedded system: a fridge with a digital thermostat, a paper notebook, a wireless mouse, a hammer, a set of smart bulbs?
Show the solution
The fridge, the wireless mouse and the smart bulbs. Each holds a small chip running fixed firmware. The fridge measures temperature and switches the compressor. The mouse reads its sensor and sends movement over radio. A bulb listens for commands and drives its LEDs. The notebook and the hammer have no electronics at all.
Read the sizes
Run the first program. On most computers it prints that an int is 4 bytes. If a chip's compiler
told you an int was 2 bytes, what is the largest positive number you could store in a plain
int there?
Show the solution
Two bytes are 16 bits. One bit records the sign, so 15 bits are left for the value. That gives a largest positive value of 2¹⁵ − 1 = 32,767.
This is a real difference, not a curiosity: small 8-bit and 16-bit chips often have a 16-bit int.
A loop counting to 40,000 in an int would never finish there. Volume 02 shows how to say exactly
what you mean with types such as uint32_t.
Why the endless loop?
The blink program ends with a loop that never finishes. On a computer, that would be a bug. Why is it right here?
Show the solution
Because there is nowhere to return to. On a computer, when main ends, the operating system takes the processor back and runs something else. A bare-metal chip has no operating system: if main ended, the processor would carry on into whatever numbers came next in memory, which is a crash waiting to happen. So firmware keeps a loop running for the life of the power supply.
Interview corner
Why C for firmware?
"Why is so much firmware still written in C?"
Show the solution
"Because C matches the hardware closely without hiding it. A line of C turns into a handful of instructions you can predict, it needs almost no run-time support, and it can read and write any address. Every chip maker ships a C compiler, and decades of drivers are already written in it. C++ and Rust are used as well, but C remains the language every firmware engineer is expected to read."
Microcontroller or microprocessor?
"What is the difference between a microcontroller and a microprocessor?"
Show the solution
"A microcontroller has the processor, the memory and the peripherals on one chip, so it can run a product on its own. A microprocessor is the processor alone: it needs external memory, and usually external chips for everything else. That is why a phone or a laptop uses a processor plus separate memory, while a washing machine uses a single microcontroller costing a few pence."
Next, Volume 01 writes real C: variables, decisions, loops and your own functions, with every program small enough to type in a minute.