Microcontrollers and Embedded Basics
What this domain covers
Microcontrollers and Embedded Basics introduces the architecture and programming model of an 8-bit microcontroller, its peripherals and typical interfacing tasks.
Core rules
- The classic 8051 is an 8-bit microcontroller with 4 KB on-chip ROM, 128 bytes RAM, four 8-bit ports (P0–P3), two 16-bit timers/counters, five interrupt sources and a full-duplex serial port.
- Registers: accumulator A for arithmetic, B for multiply/divide, DPTR as a 16-bit data pointer, PC for program address and SP for the stack. PSW holds the carry and other flags.
- Port 0 needs external pull-up resistors when used as general I/O because it has open-drain outputs; ports 1–3 have internal pull-ups.
- With a 12 MHz crystal the machine cycle is 12/12 MHz = 1 µs.
- Common instructions: MOV, ADD, DJNZ and SJMP; DJNZ decrements and jumps if not zero, ideal for delay loops.
Worked example
To create a delay of about 1 ms with a 12 MHz crystal, use a register loop. Each DJNZ takes 2 machine cycles = 2 µs; loading R2 with 250 and looping gives 250 × 2 µs = 500 µs, so nest the loop twice to reach about 1 ms.
Traps that cost marks
Forgetting that Port 0 needs pull-ups; assuming one machine cycle equals one clock period; ignoring that the 8051 reset is active high; and confusing internal ROM (program) with RAM (data).