UGC NET · Electronic Science · Code 88 · Unit-Wise Notes

Unit 6 — 8086 Microprocessor & 8051 Microcontroller: Complete Exam Notes

8086: BIU/EU architecture · segmentation & physical address · addressing modes · instruction set · interrupts & vector table · memory and I/O interfacing. 8051: architecture & register set · memory organization & SFRs · addressing modes · full instruction set · stack, subroutines & interrupts · timer/counter programming · serial port & RS232 · LED/LCD, keyboard and stepper-motor interfacing.

SYLLABUS: NTA UGC NET (88) LEVEL: Asst. Professor / JRF FORMAT: Theory + Formulas + Revision

§ 6.18086 Architecture: BIU, EU & Segmentation

The 8086 (1978): 16-bit µP, 20-bit address bus → 1 MB memory, 16-bit data bus (multiplexed AD₀–AD₁₅), 5/8/10 MHz clocks, ~29,000 transistors, 40-pin DIP, +5 V. The 8088 is identical internally but has an 8-bit external data bus (original IBM PC).

Two-unit pipelined architecture

  • Bus Interface Unit (BIU): generates addresses, fetches instructions into a 6-byte prefetch queue (8088: 4 bytes), reads/writes data; contains segment registers + Instruction Pointer (IP).
  • Execution Unit (EU): decodes/executes from the queue; contains the general registers, ALU, flags.
  • Fetch overlaps execution → pipelining; the queue flushes on jumps/branches (the cost of transfers).

Register set

  • General (16-bit, byte-addressable halves): AX (accumulator — MUL/DIV/IO), BX (base — memory pointer), CX (count — loops, shifts, strings), DX (data — 32-bit MUL/DIV partner, port address); each splits into H/L bytes (AH/AL …).
  • Pointer/Index: SP (stack pointer), BP (base pointer — stack-frame access via SS), SI/DI (string source/destination indices).
  • Segment registers: CS (code), DS (data), SS (stack), ES (extra — string destination).
  • Flags (9 of 16 used): status — CF, PF, AF (auxiliary, BCD), ZF, SF, OF; control — TF (single-step trap), IF (INTR enable), DF (string direction: 0 → auto-increment).
Physical address generation — the Unit-6 signature formula $$ PA_{20\text{-bit}} = \text{Segment} \times 10_H + \text{Offset} \qquad \text{e.g. } CS{:}IP = 2000_H{:}1234_H \Rightarrow PA = 21234_H $$
  • Each segment ≤ 64 KB, starts on a 16-byte (paragraph) boundary; segments may overlap; many segment:offset pairs map to one PA (e.g., 2100:0234 → 21234H too).
  • Default pairs: CS:IP (code), DS:SI/BX (data), SS:SP/BP (stack), ES:DI (string destination); segment-override prefixes change defaults.
  • Benefits: 1 MB reach from 16-bit registers, relocatable code/data, natural program structure.

Pins & modes (essentials)

  • ALE demultiplexes AD lines (latch 74373); BHE̅ + A₀ select byte/word on the two banks (§6.6); READY inserts wait states; RESET → CS = FFFFH, IP = 0000H → first fetch at FFFF0H.
  • Minimum mode (MN/MX̅ = 1): single processor, 8086 generates control signals itself. Maximum mode (= 0): multiprocessor (with 8087 coprocessor / 8089 IOP); the 8288 bus controller decodes S̅₂S̅₁S̅₀ into bus commands; queue-status and LOCK̅ pins appear.
UGC NET focus PA computations (given segment:offset); queue length 6 vs 4 (8088); reset vector FFFF0H; register special roles (CX = counter, DX = port pointer); min/max mode trigger pin and the 8288; flag identification from an operation.

§ 6.28086 Addressing Modes

Addressing modes with examples and effective-address (EA) recipes
ModeExampleEA / source of operand
ImmediateMOV AX, 1234Hoperand inside the instruction
RegisterMOV AX, BXregister — fastest, no bus cycle
DirectMOV AX, [5000H]EA = displacement
Register indirectMOV AX, [BX]EA = BX / SI / DI
BasedMOV AX, [BX+10H]EA = BX or BP + disp (BP → SS!)
IndexedMOV AX, [SI+10H]EA = SI or DI + disp
Based-indexedMOV AX, [BX+SI]EA = base + index
Based-indexed + dispMOV AX, [BX+SI+10H]EA = base + index + disp (arrays of records)
StringMOVSBimplicit DS:SI → ES:DI, auto ±1/2 by DF
I/O direct / indirectIN AL, 80H / IN AL, DX8-bit fixed port / 16-bit port in DX (full 64 K ports)
Relative (branch)JMP SHORT L1IP + signed 8/16-bit displacement
Intrasegment vs intersegmentNEAR (IP) / FAR (CS:IP)jump/call reach
  • Valid memory-pointer registers: only BX, BP, SI, DI (never AX/CX/DX inside brackets) — a favourite trap.
  • BP defaults to the stack segment; all other pointers default to DS.
UGC NET focus Name-the-mode from an instruction; EA arithmetic with given register contents; BP→SS default; which registers can hold pointers; direct vs indirect I/O port-size limits (255 vs 65535).

§ 6.38086 Instruction Set

  • Data transfer (no flag effects): MOV, PUSH/POP (always 16-bit), XCHG, IN/OUT, LEA (EA → register; arithmetic without memory access), LDS/LES (load pointer + segment), XLAT (AL = [BX+AL] table lookup), LAHF/SAHF, PUSHF/POPF.
  • Arithmetic: ADD/ADC, SUB/SBB, INC/DEC (CF unaffected by INC/DEC!), NEG, CMP (subtract, flags only), MUL/IMUL (AX = AL×src; DX:AX = AX×src), DIV/IDIV (quotient AL/AX, remainder AH/DX; divide-by-zero → INT 0), CBW/CWD sign extensions; BCD adjusters DAA/DAS (packed), AAA/AAS/AAM/AAD (unpacked ASCII).
  • Logical & shifts: AND/OR/XOR/NOT, TEST (AND, flags only); SHL/SAL, SHR (0 → MSB), SAR (sign-preserving) — shift count 1 or CL; rotates ROL/ROR/RCL/RCR (through carry). SHL = ×2, SAR = ÷2 signed.
  • String instructions (the 8086's signature): MOVS, CMPS, SCAS, LODS, STOS (B/W suffix); SI/DI auto-update per DF (CLD/STD); REP (with CX), REPE/REPZ, REPNE/REPNZ prefixes — block move = CLD; MOV CX,N; REP MOVSB.
  • Control transfer: JMP (short ±127, near, far); conditional jumps (JZ/JNZ, JC, JO, JS, JP; signed JG/JL/JGE/JLE vs unsigned JA/JB/JAE/JBE — all short-range); LOOP/LOOPE/LOOPNE (CX-driven); CALL/RET (near/far; RET n cleans stack); INT n / INTO / IRET (§6.4).
  • Processor control: CLC/STC/CMC, CLI/STI, CLD/STD, HLT, NOP, WAIT, LOCK (bus lock prefix), ESC (coprocessor).
UGC NET focus MUL/DIV register conventions (where do results land?); INC/DEC sparing CF; signed-vs-unsigned jump pairs (JG vs JA); REP-string idioms; LEA vs MOV OFFSET equivalence; XLAT mechanics; PUSH/POP always word-sized.

§ 6.48086 Interrupts

  • Interrupt Vector Table (IVT): lowest 1 KB (00000–003FFH); 256 vectors × 4 bytes (IP low word, CS high word). Vector address = type × 4.
  • Response sequence: PUSH Flags → clear IF, TF → PUSH CS → PUSH IP → load CS:IP from IVT; IRET restores IP, CS, Flags.
  • Dedicated types: 0 divide error; 1 single-step (TF); 2 NMI (non-maskable pin, type fixed); 3 breakpoint (1-byte INT 3 — debuggers); 4 overflow (INTO). Types 5–31 reserved; 32–255 user/software.
  • Hardware: NMI (edge, unmaskable — power-fail, parity) and INTR (level, masked by IF; type supplied by the 8259A PIC during INTA̅ cycles; one 8259 → 8 levels, cascadable to 64).
  • Software: INT n (any type), INTO, and CPU-generated exceptions (divide error, single step).
  • Priority (highest → lowest): divide error/INT n/INTO (internal) → NMI → INTR → single-step.
  • Interrupt latency factors; nested interrupts re-enabled by STI inside the ISR; ISRs end with IRET (vs RET for procedures — a classic distinction).
UGC NET focus Vector address = 4×type numericals (type 8 → 00020H); the automatic flag/CS/IP push order; NMI vs INTR properties; INT 3 one-byte breakpoint; priority ordering; 8259A role.

§ 6.58086 Assembly Programming

  • Assembler directives (not instructions — generate no code): SEGMENT/ENDS, ASSUME, ORG, DB/DW/DD (define data), EQU, DUP, PROC/ENDP (NEAR/FAR), MACRO/ENDM, OFFSET/SEG/PTR operators, END.
  • Canonical patterns the exam recycles:
    • Block transfer: LEA SI, SRC / LEA DI, DST / MOV CX, N / CLD / REP MOVSB.
    • Largest element: load first into AL; loop CMP AL,[SI] / JAE skip / MOV AL,[SI] — JAE for unsigned, JGE for signed.
    • Sum with carry: ADD AL,[SI] / ADC AH, 0 — multiprecision via ADC/SBB chains.
    • BCD packed addition: ADD AL, BL / DAA.
    • ASCII↔binary: AND 0FH strips '0'–'9'; OR 30H restores; AAM splits AL into AH:AL digits (divide by 10).
    • Delay loops: MOV CX, N / L: LOOP L — time = N × (LOOP cycles)/f_clk.
  • Procedures: CALL pushes IP (near) or CS:IP (far); parameters via registers or stack (BP frame: PUSH BP / MOV BP,SP / […BP+4] = first parameter); preserve registers with PUSH/POP discipline.
  • Macros vs procedures: macro = inline expansion (faster, larger code, no CALL overhead); procedure = single copy (CALL/RET time cost).
  • Modular flow: .ASM → assembler (.OBJ) → linker (.EXE) → loader; DEBUG/emulators for tracing (TF single-step).
UGC NET focus Directive-vs-instruction identification; trace small loops (register/flag states after n iterations); DAA after ADD for BCD; macro/procedure trade-off; stack-frame parameter access via BP.

§ 6.68086 Memory & I/O Interfacing

Memory banks

  • 1 MB split into two 512 KB banks: even/lower bank (D₀–D₇, enabled by A₀ = 0) and odd/upper bank (D₈–D₁₅, enabled by BHE̅ = 0).
BHE̅ / A₀ truth table — memorize
BHE̅A₀Transfer
0016-bit word (both banks, one cycle — aligned)
01upper byte (odd address)
10lower byte (even address)
11none
  • Misaligned word (odd address) costs two bus cycles — why data alignment matters.
  • Address decoding: full (all lines → unique map) vs partial (aliases); 74138 decoders / PROM decoding; chip-select arithmetic: a 64 KB device needs A₀–A₁₅ internally, decoder on A₁₆–A₁₉ — compute address ranges (standard numericals).
  • EPROM placed at the top (must contain FFFF0H reset vector); RAM at the bottom (IVT at 00000H).

I/O interfacing

Isolated (I/O-mapped) vs memory-mapped I/O
IsolatedMemory-mapped
InstructionsIN/OUT onlyfull instruction set (MOV, AND…)
Address spaceseparate 64 KB portsconsumes memory map
Decoding signalM/IO̅ = 0M/IO̅ = 1
Hardwaresimpler decodenone extra, richer ops
  • 8255A PPI (the canonical port chip): three 8-bit ports A, B, C (C splittable); control word at the fourth address. Mode 0 simple I/O, Mode 1 strobed (handshake via port C), Mode 2 bidirectional (port A); BSR mode sets/resets individual PC bits. Control word: bit 7 = 1 for mode set (e.g., 80H = all ports output, mode 0; 9BH = all input).
  • Supporting cast: 8254 timer, 8259A PIC (§6.4), 8237 DMA, 8251 USART — recognize roles.
UGC NET focus BHE̅/A₀ table; odd-word two-cycle penalty; why ROM sits at the top of the map; address-range decoding numericals; 8255 control-word construction (80H/9BH style); isolated-vs-memory-mapped trade table.

§ 6.7Microcontrollers & the 8051: Overview

Microprocessor vs microcontroller — the framing question
Microprocessor (8086)Microcontroller (8051)
IntegrationCPU only; external RAM/ROM/I/OCPU + ROM + RAM + I/O + timers + serial on one chip
Design goalgeneral-purpose computingdedicated embedded control
System cost/size/powerhigherlow — single-chip solution
Bit operationsweakBoolean processor — single-bit I/O control
Memory architectureVon Neumann (shared)Harvard (separate program/data)

8051 (MCS-51, Intel 1981) feature card — quote these numbers

  • 8-bit CPU; on-chip 4 KB ROM, 128 B RAM; two 16-bit timers (T0, T1); 4 × 8-bit I/O ports (P0–P3, 32 lines); full-duplex UART; 5 interrupt sources (2 external, 2 timer, 1 serial) with 2 priority levels; 16-bit PC and DPTR; 64 KB external program + 64 KB external data reach; 40-pin DIP.
  • Clock: each machine cycle = 12 oscillator periods → 12 MHz crystal = 1 µs cycle; standard serial crystal 11.0592 MHz.
  • Family: 8031 (ROM-less), 8751 (EPROM), 8052 (8K ROM, 256 B RAM, third timer T2), 89C51/89S52 (flash, ISP).
  • Pins to know: EA̅ (0 = all code external — mandatory for 8031), PSEN̅ (external program-memory read strobe), ALE (latch A0–A7 from P0), RST (high ≥ 2 cycles).
UGC NET focus The 4K/128B/2-timer/5-interrupt/32-pin-I/O number set; Harvard architecture claim; 12-clock machine cycle arithmetic; EA̅ and PSEN̅ functions; 8051 vs 8052 deltas.

§ 6.88051 Architecture, Register Set & Memory Organization

Internal RAM map (128 bytes, 00–7FH)

  • 00–1FH: four register banks (Bank 0–3, R0–R7 each); active bank chosen by PSW bits RS1 RS0 (fast context switch for interrupts).
  • 20–2FH: bit-addressable area — 16 bytes = 128 bits, bit addresses 00–7FH (the Boolean processor's data field).
  • 30–7FH: scratch-pad general RAM (default stack growth region).
  • 8052 adds 80–FFH indirect-only upper RAM (overlaps SFR addresses, separated by addressing mode).

SFRs (80–FFH, direct-only)

  • A/ACC (E0H) accumulator, B (F0H) MUL/DIV partner, PSW (D0H), SP (81H — resets to 07H, pre-increments on PUSH), DPTR = DPH:DPL (16-bit pointer), P0–P3 (80, 90, A0, B0H), plus TMOD/TCON/TH/TL (§6.15), SCON/SBUF (§6.16), IE/IP (§6.14), PCON (SMOD, idle/power-down bits).
  • SFRs at addresses ending in 0H/8H are bit-addressable (P0–P3, PSW, ACC, B, TCON, SCON, IE, IP).
PSW (program status word) bit map — memorize CY (carry, PSW.7) · AC (auxiliary carry, BCD) · F0 (user flag) · RS1, RS0 (bank select: 00→Bank0 …) · OV (overflow, signed) · — · P (parity of A, even). Note: no zero flag — use JZ/JNZ which test A directly.

Ports (HW behaviour asked often)

  • P0: open-drain — needs external pull-ups as plain I/O; multiplexed AD0–AD7 in external-bus mode.
  • P1: dedicated I/O, internal pull-ups.
  • P2: I/O or high address byte A8–A15.
  • P3: I/O + alternates — P3.0 RXD, P3.1 TXD, P3.2 INT0̅, P3.3 INT1̅, P3.4 T0, P3.5 T1, P3.6 WR̅, P3.7 RD̅.
  • Quasi-bidirectional: write 1 to a pin before using it as input; read-pin vs read-latch (read-modify-write instructions read the latch).
UGC NET focus RAM map boundaries (00–1F/20–2F/30–7F) and the 128-bit field; SP reset = 07H; RS1RS0 bank arithmetic (bank 2 → R0 at 10H); P0 pull-up requirement; P3 alternate-function table; parity flag tracks A.

§ 6.98051 Addressing Modes

The five modes
ModeExampleNotes
ImmediateMOV A, #55H# marks data; MOV DPTR, #1234H is the lone 16-bit case
RegisterMOV A, R5active-bank R0–R7; no R-to-R MOV (must route via A or direct)
DirectMOV A, 30Hany internal RAM 00–7F or SFR; the only way to reach SFRs
Register indirectMOV A, @R0pointer must be R0 or R1 (or SP for stack); @Ri reaches 00–7FH (8052 upper RAM too); MOVX @Ri/@DPTR for external data
IndexedMOVC A, @A+DPTR / @A+PCprogram-memory tables (lookup, code constants); JMP @A+DPTR dispatch
  • Memory-space selectors: plain MOV = internal RAM/SFR; MOVX = external data RAM (uses RD̅/WR̅); MOVC = code/program memory (read-only, uses PSEN̅) — the Harvard separation in instruction form.
UGC NET focus #data vs direct-address confusion (MOV A,30H vs MOV A,#30H — the classic trap); only R0/R1 as @ pointers; MOVC vs MOVX space mapping; identify mode from instruction.

§ 6.108051 Data-Transfer Instructions

  • MOV family: MOV A,Rn / MOV Rn,A / MOV direct,direct (memory-to-memory — 8086 lacks this!) / MOV @Ri,#data / MOV DPTR,#data16. Flags unaffected (except writes to PSW/A affecting P).
  • External & code memory: MOVX A,@DPTR; MOVX @DPTR,A; MOVX A,@Ri (page mode, P2 supplies A8–A15); MOVC A,@A+DPTR; MOVC A,@A+PC (table within code).
  • Stack: PUSH direct / POP direct (direct addresses only — PUSH ACC, not PUSH A in many assemblers); SP increments before PUSH (grows upward), decrements after POP — §6.13.
  • Exchange: XCH A, source (full byte swap with A); XCHD A,@Ri — swaps lower nibbles only (BCD juggling); SWAP A — swaps A's nibbles (4-bit rotate).
  • Lookup-table idiom: MOV DPTR,#TABLE / MOV A,index / MOVC A,@A+DPTR — 7-segment patterns, linearization tables.
UGC NET focus Direct-to-direct MOV exists in 8051; SWAP vs XCHD effects; MOVX/MOVC selection; PUSH takes a direct address; trace A/RAM contents through short MOV/XCH sequences.

§ 6.118051 Arithmetic & Logic Instructions

Arithmetic (A-centric; affect CY, AC, OV, P)

  • ADD A,src / ADDC A,src (with carry — multibyte chains); SUBB A,src (always subtracts borrow — CLR C first for a plain subtract; there is no SUB!).
  • INC / DEC on A, Rn, direct, @Ri; INC DPTR (16-bit, no DEC DPTR!); INC/DEC do not touch CY.
  • MUL AB: A×B → B:A (high:low); OV = 1 if product > FFH; CY cleared. DIV AB: A÷B → quotient in A, remainder in B; OV flags divide-by-zero.
  • DA A: decimal adjust after ADD/ADDC only — adds 06/60H per nibble-carry rules for packed BCD.
  • Signed overflow: OV set when carry into MSB ≠ carry out (two-positive→negative etc.).

Logic (flags: only P via A, except RRC/RLC)

  • ANL, ORL, XRL — A,src or direct,A or direct,#data (logic directly on RAM/SFRs — masking port bits without touching A).
  • CLR A, CPL A; rotates: RL A / RR A (8-bit circular) and RLC A / RRC A (9-bit through carry — multibyte shifts, serial bit-banging); SWAP A (= RL A ×4).
  • Masking idioms: ANL clears selected bits (AND with 0), ORL sets (OR with 1), XRL toggles; ANL P1,#0F0H clears P1 low nibble in place.
UGC NET focus SUBB needs CLR C; MUL/DIV register placement (B:A; quotient A, remainder B); DA A only after addition; RLC vs RL distinction; compute A, CY after short instruction traces; in-place port masking with ANL/ORL direct.

§ 6.12Bit-Level & Control-Transfer Instructions

Boolean processor (the 8051's trademark)

  • Operates on 128 RAM bits (20–2FH) + bit-addressable SFR bits (e.g., P1.3, TR0, EA); carry CY acts as the 1-bit accumulator.
  • Instructions: SETB bit / CLR bit / CPL bit; MOV C,bit / MOV bit,C; ANL C,bit / ANL C,/bit (complemented operand); ORL C,bit; JB bit,rel / JNB / JBC (jump-if-bit-then-clear — atomic flag test); JC/JNC.
  • Single-instruction relay logic: MOV C,P1.0 / ANL C,P1.1 / MOV P2.0,C implements AND of two inputs to an output — no byte masking needed.

Control transfer

  • Jumps by reach: SJMP (relative, −128…+127), AJMP (absolute, same 2 KB page, 11-bit), LJMP (anywhere in 64 KB, 16-bit); JMP @A+DPTR (computed dispatch). Same trio for calls: ACALL / LCALL.
  • Conditional (all relative, ±127): JZ/JNZ (test A, since no Z flag), JC/JNC, bit jumps above, and the loop pair:
    • DJNZ Rn,rel / DJNZ direct,rel — decrement, jump if not zero: the canonical delay/loop primitive.
    • CJNE A,#data,rel (also A,direct / Rn,#data / @Ri,#data) — compare-jump-if-not-equal; sets CY = 1 if first operand < second → magnitude comparison follows with JC/JNC.
  • NOP (1 cycle — delay padding); RET / RETI in §6.13–6.14.
UGC NET focus SJMP/AJMP/LJMP range trio (−128/2K-page/64K); DJNZ loop-count traces; CJNE's CY convention for < tests; JBC atomicity; CY as bit accumulator; JZ tests A not a flag.

§ 6.13Stack Operations & Subroutines

  • Stack lives in internal RAM, grows upward; SP resets to 07H → first PUSH lands at 08H (inside Bank 1 — re-initialize, e.g., MOV SP,#5FH or #30H, when banks/bit area are needed).
  • PUSH direct: SP←SP+1, then store; POP direct: read, then SP←SP−1 (pre-increment/post-decrement — opposite vertical sense to the 8086's downward stack).
  • LCALL/ACALL: push PC (low byte first, then high) = return address, load new PC. RET: pop PC high then low. RETI additionally clears the interrupt-in-progress logic — using RET in an ISR blocks same/lower-priority interrupts thereafter (classic trap).
  • Nesting depth limited by RAM ceiling 7FH; each call costs 2 bytes; register preservation discipline: PUSH ACC / PUSH PSW … POP in reverse; or switch register banks (PSW RS bits) in the ISR for zero-cost context save.
  • Parameter passing: registers (fast), fixed RAM, or stack; subroutine archetypes — software delay (nested DJNZ), code-table reads, BCD/ASCII conversion.
  • Delay arithmetic example (12 MHz → 1 µs/cycle): MOV R2,#250 / L: DJNZ R2,L ≈ 250 × 2 µs = 500 µs (DJNZ = 2 cycles).
UGC NET focus SP = 07H default and collision with Bank 1; upward growth + pre-increment; RET vs RETI consequence; byte order of the pushed PC; nested-DJNZ delay computation at 12 MHz.

§ 6.148051 Interrupts

Five sources — vectors and defaults (memorize the address column)
SourceFlagVectorDefault priority
External INT0̅ (P3.2)IE00003H1 (highest)
Timer 0 overflowTF0000BH2
External INT1̅ (P3.3)IE10013H3
Timer 1 overflowTF1001BH4
Serial (RI or TI)RI/TI0023H5 (lowest)

Reset vector = 0000H; vectors are 8 bytes apart — short ISRs fit in place, longer ones LJMP out.

  • IE register (A8H, bit-addressable): EA | — | ET2 | ES | ET1 | EX1 | ET0 | EX0 — EA must be 1 plus the individual enable (two-key system). Example: MOV IE,#10000110B enables INT1 and Timer 0.
  • IP register (B8H): set bit → high priority; high can preempt low; equals resolve by the default order above. Two levels only.
  • External-interrupt triggering (TCON): IT0/IT1 = 0 → level (low) triggered (source must release before RETI or it re-fires); = 1 → falling-edge triggered (IE0/IE1 latched, auto-cleared on vectoring).
  • Timer flags TF auto-clear on vectoring; serial RI/TI must be cleared in software (the ISR must test which one fired).
  • Hardware ISR entry: PC pushed (only PC! — save PSW/ACC yourself), vector loaded; RETI ends it (§6.13).
  • Latency: 3–8 machine cycles (instruction completion + vectoring).
UGC NET focus Vector table 0003/000B/0013/001B/0023H; IE bit layout and the EA master bit; level vs edge config via IT bits; RI/TI manual clearing; only PC is auto-saved; default priority order.

§ 6.158051 Timers/Counters

  • Two 16-bit up-counters T0 (TH0:TL0), T1 (TH1:TL1); count machine cycles (f_osc/12) as a timer, or external pulses on T0/T1 pins (P3.4/3.5, max f_osc/24) as a counter — selected by the C/T̅ bit.
  • TMOD (89H, not bit-addressable): upper nibble T1, lower T0; each nibble = GATE | C/T̅ | M1 | M0. GATE = 1 → run only while INTx̅ pin high (hardware gating — pulse-width measurement).
  • TCON (88H, bit-addressable): TF1 TR1 TF0 TR0 (+ IE/IT bits §6.14) — TRx run control (SETB TR0), TFx overflow flags.
Timer modes
ModeM1M0ConfigurationMax count / use
00013-bit (legacy 8048)8192
10116-bit; reload by software65536 — general delays
2108-bit auto-reload (TL from TH)256 — baud-rate generation, periodic ticks
311T0 splits into two 8-bit timers (TL0, TH0); T1 frozen-countextra timer when T1 does baud
Delay design (the standard numerical) $$ \text{count} = \frac{t_{delay}}{T_{machine}} \;;\quad \text{load} = 65536 - \text{count (mode 1)} \quad\text{or}\quad 256 - \text{count (mode 2)} $$ $$ \text{e.g. 12 MHz, 50 ms: count} = 50000 \Rightarrow TH0{:}TL0 = 65536-50000 = 15536 = 3CB0_H $$
  • Recipe (mode 1, polling): MOV TMOD,#01H → load THx:TLx → SETB TRx → JNB TFx,$ → CLR TRx → CLR TFx → reload for the next round. Interrupt version: ET0/EA set, reload inside the ISR.
  • Square wave of period T: toggle a pin each T/2 overflow; frequency measurement: count pulses (counter mode) over a gated 1 s timer window.
UGC NET focus TMOD nibble construction (e.g., #20H = T1 mode 2); 65536−count loading numericals at 12 MHz/11.0592 MHz; mode-2 auto-reload for baud; GATE-bit pulse-width trick; TF polling vs interrupt skeletons.

§ 6.168051 Serial Communication & RS232

  • Full-duplex UART: TXD (P3.1), RXD (P3.0); SBUF (99H) is two registers at one address (write → transmit shift register; read → receive buffer; double-buffered receive).
  • SCON (98H, bit-addressable): SM0 SM1 | SM2 (multiprocessor) | REN (receive enable) | TB8 RB8 (9th bits) | TI RI (transmit/receive complete — software-cleared).
Serial modes
ModeSM0SM1FrameBaud
0008-bit shift register (synchronous; RXD = data, TXD = clock)f_osc/12 — port expansion via 74164/165
10110 bits: start + 8 data + stop (standard UART)variable — Timer 1
21011 bits (9 data: TB8/RB8)f_osc/64 or /32 (SMOD)
31111 bits as mode 2variable — Timer 1
Mode-1 baud rate (Timer 1, mode 2 auto-reload) $$ \text{Baud} = \frac{2^{SMOD}}{32}\times\frac{f_{osc}/12}{256 - TH1} $$ $$ \text{11.0592 MHz, SMOD = 0: } TH1 = FD_H(-3) \to 9600;\ FA_H(-6) \to 4800;\ F4_H(-12) \to 2400;\ E8_H(-24) \to 1200 $$

11.0592 MHz exists precisely because 11.0592M/12/32 = 28800 divides into standard baud rates exactly; SMOD (PCON.7) doubles the rate.

  • Transmit: MOV SBUF,A → poll JNB TI,$ → CLR TI. Receive: SETB REN → JNB RI,$ → MOV A,SBUF → CLR RI. Interrupt-driven via vector 0023H (test TI vs RI inside).
  • RS-232: the EIA standard — logic 1 = −3…−15 V (mark), logic 0 = +3…+15 V (space): inverted, bipolar → TTL-incompatible. MAX232 level shifter (on-chip charge pumps generate ±10 V from +5 V with four 1–10 µF capacitors; two drivers + two receivers) sits between 8051 TXD/RXD and the DB9 (pin 2 RXD, 3 TXD, 5 GND on PC side); null-modem cross TX↔RX. Handshake lines (RTS/CTS, DTR/DSR) optional; distance ≤ ~15 m, rates to 115.2 kbaud.
UGC NET focus TH1 = FDH → 9600 (the single most repeated 8051 numerical); SBUF dual nature; TI/RI software-cleared and polled; mode 1 = 10-bit frame; RS-232 negative-true levels and MAX232's job; why 11.0592 MHz.

§ 6.17Interfacing: LED, LCD, Keyboard, Stepper Motor

LED & 7-segment

  • Single LED: series resistor R = (V_CC − V_F)/I_F (5 V, 2 V, 10 mA → 330 Ω); ports sink better than they source → common practice: active-low drive (LED to V_CC through R, pin sinks). P0 needs pull-ups.
  • 7-segment: common-anode (segment lit by 0) vs common-cathode (lit by 1); code table in ROM read by MOVC; multiplexed multi-digit: one digit at a time > ~50 Hz refresh — persistence of vision; transistor drivers per digit.

LCD (16×2, HD44780)

  • Pins: RS (0 = command, 1 = data), R/W̅ (usually grounded = write), EN (falling-edge latches the byte), D0–D7 (or 4-bit mode on D4–D7 — two nibbles per byte, saves pins), V_EE contrast pot.
  • Command set to quote: 38H 8-bit/2-line/5×7 · 0EH display+cursor on · 01H clear · 06H entry mode (increment) · 80H cursor to line-1 home (C0H = line 2).
  • Sequence: command/data on port → set RS → pulse EN high→low → delay (or poll busy flag D7 with R/W̅ = 1). Clear/home commands need ~1.6 ms; others ~40 µs.

Matrix keyboard (4×4)

  • 16 keys on 8 lines (4 rows out + 4 columns in with pull-ups) instead of 16. Scanning: ground one row at a time, read columns; a low column identifies (row, col) → key code via table.
  • Essentials: debouncing (~10–20 ms wait or double-read — contacts bounce mechanically), ghosting/rollover limits (diodes for n-key rollover), wait-for-release to avoid repeats; interrupt variant: all rows low, columns AND-ed into INT0̅.

Stepper motor

  • Brushless motor moving in discrete steps — open-loop position control. Unipolar (center-tapped, simple drive) vs bipolar (H-bridge, more torque).
  • Drive sequences (4-coil unipolar): wave (one coil: 8→4→2→1), full-step (two coils: 9→C→6→3 — more torque), half-step (alternating 1-and-2 coils, 8 patterns → halves the step angle, doubles resolution). Reverse the sequence to reverse rotation.
  • Interface: port nibble → ULN2003 Darlington array (or transistors) with freewheeling diodes (inductive kick) → coils; never drive coils from port pins directly.
  • Stepper arithmetic $$ \text{steps/rev} = \frac{360^\circ}{\text{step angle}}\ \ (1.8^\circ \to 200);\qquad \text{RPM} = \frac{60\,f_{step}}{\text{steps/rev}} $$
    Speed set by inter-step delay (DJNZ/timer); too fast → missed steps (torque–speed curve).
UGC NET focus LCD command bytes (38/0E/01/06/80H) and the RS/EN protocol; 4-bit-mode rationale; keyboard scan algorithm + debounce timing; stepper sequences and the 1.8° → 200 steps computation; ULN2003 + diode necessity; multiplexed-display refresh ≥ 50 Hz.

§ 6.18Unit-6 Formula Sheet

One-stop reference table — Unit 6
TopicResultNotes
8086 physical addressPA = Segment × 10H + Offset20-bit, 1 MB; segment ≤ 64 KB
Reset / IVTreset fetch FFFF0H; vector addr = 4 × typeIVT = 00000–003FFH, 256 × 4 B
Prefetch queue8086: 6 bytes; 8088: 4 bytesflushed on branches
BanksA₀ = 0 even/low; BHE̅ = 0 odd/highodd-aligned word = 2 cycles
Interrupt priorityinternal > NMI > INTR > single-stepNMI = type 2, INT 3 = 1 byte
MUL/DIV (8086)AX = AL×s; DX:AX = AX×s; quotient AL/AX, rem AH/DXdiv error → INT 0
8255 control80H = all out (mode 0); 9BH = all inBSR: bit 7 = 0
8051 feature card4K ROM, 128 B RAM, 2×16-bit timers, 4 ports, UART, 5 interruptsmachine cycle = 12 clocks
RAM map00–1F banks; 20–2F bit field (128 bits); 30–7F scratchSP reset = 07H, grows up
PSWCY AC F0 RS1 RS0 OV — Pno Z flag; JZ tests A
8051 vectors0003 / 000B / 0013 / 001B / 0023Hreset 0000H; 8-byte spacing
Jump rangesSJMP ±127; AJMP 2 KB page; LJMP 64 KBsame for ACALL/LCALL
CJNE ruleCY = 1 if op1 < op2magnitude tests via JC
MUL/DIV (8051)MUL AB → B:A; DIV AB → A quo, B remOV on overflow / ÷0
Timer loadload = 65536 − count (M1); 256 − count (M2)count = t/T_machine
50 ms @ 12 MHzTH:TL = 3CB0H65536 − 50000
Baud (mode 1)(2^SMOD/32)·(f_osc/12)/(256 − TH1)11.0592 MHz: FDH → 9600
TMOD nibbleGATE C/T̅ M1 M0 (T1 high, T0 low)#20H = T1 mode 2
RS-232 levels1 = −3…−15 V; 0 = +3…+15 VMAX232 converts; ≤ 15 m
LCD commands38H init, 0EH on, 01H clear, 06H entry, 80H homeRS = 0 cmd; EN falling edge
LED resistorR = (V_CC − V_F)/I_F5 V, 2 V, 10 mA → 330 Ω
Steppersteps/rev = 360/step angle; RPM = 60f/steps1.8° → 200; half-step doubles res.

§ 6.19Quick Revision Notes — Unit 6 in 25 Points

Rapid-fire recap (last-day revision)

  1. 8086: 16-bit CPU, 20-bit address (1 MB), BIU (fetch, 6-byte queue, segment registers) + EU (execute) = pipelining; queue flushes on jumps; 8088 = 8-bit bus, 4-byte queue.
  2. PA = segment×10H + offset; segments 64 KB max, paragraph-aligned, can overlap; many seg:off pairs → one PA.
  3. Defaults: CS:IP, DS:SI/BX, SS:SP/BP, ES:DI; only BX/BP/SI/DI may sit inside [ ]; BP implies SS.
  4. Reset → FFFF0H (ROM at top); IVT at 00000H (RAM at bottom); vector address = 4 × type; INT 3 is one byte.
  5. Interrupt entry pushes Flags, CS, IP and clears IF, TF; exit = IRET; priority: internal > NMI > INTR > single-step; INTR type comes from the 8259A.
  6. MUL/DIV homes: AL×s→AX, AX×s→DX:AX; quotient AL/AX, remainder AH/DX; INC/DEC never touch CF; DAA fixes packed BCD after ADD.
  7. Strings: DS:SI → ES:DI, DF chooses direction (CLD = increment), REP uses CX; signed jumps JG/JL vs unsigned JA/JB.
  8. Even bank A₀ = 0 (D0–D7), odd bank BHE̅ = 0 (D8–D15); aligned word = 1 cycle, misaligned = 2.
  9. Isolated I/O: IN/OUT, M/IO̅ = 0, separate 64 K ports; memory-mapped: any instruction, costs address space. 8255: A, B, C + control; 80H all-out, 9BH all-in; BSR sets PC bits.
  10. Microcontroller = CPU + memory + I/O + timers on-chip, Harvard organization, Boolean (bit) processing — the embedded contrast with the 8086.
  11. 8051 card: 4 KB ROM / 128 B RAM / 2 × 16-bit timers / 32 I/O lines / UART / 5 interrupts / machine cycle = 12 clocks (12 MHz → 1 µs); 8052 adds T2, 8 KB, 256 B.
  12. RAM: 00–1F = 4 register banks (RS1RS0 select), 20–2F = 128 addressable bits, 30–7F scratch; SFRs 80–FF direct-only; X0/X8 addresses bit-addressable.
  13. PSW: CY AC F0 RS1 RS0 OV – P; no zero flag — JZ/JNZ read A; P keeps even parity of A.
  14. Ports: P0 open-drain (pull-ups!) + AD0–7; P2 = A8–15; P3 alternates RXD TXD INT0 INT1 T0 T1 WR RD; write 1 before reading a pin.
  15. Five modes: immediate (#), register, direct (SFR access), @R0/@R1 indirect, indexed MOVC @A+DPTR; MOVX = external RAM, MOVC = code space.
  16. MOV direct,direct exists; SWAP A swaps nibbles; XCHD swaps low nibbles with @Ri; PUSH/POP take direct addresses; SP = 07H at reset, pre-increments, grows up.
  17. No SUB — SUBB always includes borrow (CLR C first); MUL AB → B:A; DIV AB → A quotient, B remainder; DA A only after ADD/ADDC; INC DPTR exists, DEC DPTR doesn't.
  18. Boolean processor: CY = bit accumulator; SETB/CLR/CPL bit; JB/JNB/JBC (test-and-clear); single-bit relay logic on P-pins.
  19. Ranges: SJMP ±127, AJMP 2 KB page, LJMP 64 KB; DJNZ = loop primitive; CJNE sets CY when first < second.
  20. LCALL pushes PC low-then-high; RET pops; RETI (not RET) ends ISRs or further interrupts lock out; only PC auto-saved — preserve PSW/ACC or swap banks.
  21. Vectors: INT0 0003H, T0 000BH, INT1 0013H, T1 001BH, serial 0023H; IE needs EA + source bit; IT bits pick level/edge; RI/TI cleared by software.
  22. Timers: TMOD nibbles (GATE C/T̅ M1 M0); mode 1 = 16-bit (load 65536−count), mode 2 = 8-bit auto-reload (baud), mode 3 splits T0; TR run bits and TF flags in TCON; 50 ms @12 MHz → 3CB0H.
  23. Serial mode 1 = 10-bit frame, baud from Timer-1 mode 2: 11.0592 MHz + TH1 = FDH → 9600 (SMOD doubles); SBUF is two registers at 99H; poll TI before next byte.
  24. RS-232: negative logic ±3–15 V → MAX232 charge-pump shifter to TTL; DB9 2-RXD/3-TXD/5-GND; ≤15 m.
  25. Interfacing set: LCD 38/0E/01/06/80H with RS, EN-pulse, busy-flag; keyboard = row-scan + 10–20 ms debounce; 7-seg multiplexing ≥ 50 Hz; stepper 1.8° → 200 steps/rev, wave/full/half sequences through ULN2003 with flyback diodes.

↑ Back to top of Unit 6