Microcontrollers, Embedded Basics and Practical Applications
This domain tests the 8051 architecture, timing calculations, interrupts and the sensor–controller–actuator pattern of embedded systems.
Core concepts
- The 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. Port 0 is open-drain and needs external pull-up resistors.
- Timing: with a 12 MHz crystal the oscillator period is 1/12 µs and a machine cycle (12 clocks) is 1 µs.
- SFRs include ACC, B, PSW, SP, DPTR, TMOD, TCON, SCON, IE and IP. Timer mode 2 is 8-bit auto-reload; mode 1 is 16-bit.
- Interrupt vectors are 8 bytes apart: external 0 at 0003H, Timer 0 at 000BH, external 1 at 0013H, Timer 1 at 001BH, serial at 0023H.
- Embedded system chain: sensor → signal conditioning → microcontroller → driver → actuator, with interrupts, polling and watchdog supervision.
Worked example
For a 50 ms delay with a 12 MHz crystal, the machine cycle is 1 µs, so 50 000 cycles are needed. A nested DJNZ loop of 200 × 250 = 50 000 machine cycles gives about 50 ms, ignoring the loop overhead instructions. For a timer instead, mode 1 would load 65536 − 50000 = 15536 = 3CB0H.
Traps
Confusing crystal period with machine-cycle period; forgetting P0 pull-ups; thinking Timer mode 2 is 16-bit; assuming interrupt vectors are 16 bytes apart; overlooking loop overhead and watchdog resets in delay code.