Microcontrollers and Embedded Systems
Microcontrollers and Embedded Systems tests the architecture and practical use of small controllers, especially the 8051 family and Arduino-style boards: GPIO, registers, timers, interrupts, ADC, serial communication and program flow.
Core rules
- A microcontroller integrates CPU, memory, timers, I/O and serial ports; a microprocessor needs external memory and peripherals.
- 8051 uses Harvard architecture: separate program and data memory. Port pins are quasi-bidirectional and need external pull-ups for some loads.
- Machine cycle on a classic 8051 = 12 oscillator periods. With a 12 MHz crystal, one machine cycle = 1 µs.
- Timers count machine cycles; interrupts vector to fixed addresses; the 8051 reset is active-low.
- Arduino: pinMode(), digitalWrite(), analogRead() (10-bit ADC, 0–1023), delay() in milliseconds.
Worked example
An 8051 runs from a 12 MHz crystal. One machine cycle is 12/12 MHz = 1 µs. The loop MOV R0,#250; AGAIN: DJNZ R0,AGAIN uses DJNZ, which takes 2 machine cycles = 2 µs per pass. 250 passes give 250 × 2 µs = 500 µs, plus the MOV. To get about 1 ms, repeat the 250-count loop twice or use a timer.
Traps
- Using the crystal frequency directly as the instruction rate; divide by 12 for a classic 8051.
- Forgetting that a button input needs a defined level: pull-up or pull-down, plus debounce.
- Assuming analogRead() returns volts; it returns a 10-bit count unless converted.
- Loading a pin beyond its current limit; use a transistor or driver for relays and motors.