Back to the 2025 paper

Module 3: Embedded Microcontrollers – PIC18F / Others

20257m

Explain the architecture of a microcontroller with neat block diagram. Describe the basics of assembly language and C-language programming used for microcontrollers.

Worked SolutionAI Assisted

Solution: Microcontroller Architecture, Assembly and C Programming

Microcontroller Architecture

A microcontroller is a compact integrated circuit containing a processor, memory, I/O and peripherals for embedded control applications.

              ┌─────────────────────┐
              │        CPU          │
              │ ALU + Control Unit  │
              │ Registers           │
              └──────────┬──────────┘
                         │ System Bus
        ┌────────────────┼────────────────┐
        ↓                ↓                ↓
   Program Memory    Data Memory       I/O Ports
   Flash/ROM         RAM/EEPROM        GPIO
        │                │                │
        └────────────────┼────────────────┘
                         ↓
              Timers / Counters
              ADC / PWM / DAC
              SPI / I²C / UART

Major blocks

  • CPU: Executes instructions.
  • ALU: Performs arithmetic and logical operations.
  • Registers: High-speed temporary storage.
  • Program memory: Stores firmware.
  • RAM: Stores temporary variables and stack data.
  • EEPROM/Flash: Stores non-volatile data or program code.
  • GPIO: Interfaces with external sensors and actuators.
  • Timers/Counters: Generate delays and measure/count events.
  • ADC/DAC/PWM: Interface between digital electronics and analog systems.
  • Communication peripherals: SPI, I²C, UART/USART and others.

Assembly Language Programming

Assembly language uses processor-specific mnemonics representing machine instructions.

Example:

MOVLW 05H
MOVWF COUNT
INCF  COUNT, F

The exact instructions depend on the microcontroller architecture.

Advantages

  • Precise hardware control.
  • Efficient execution.
  • Small and predictable code.

Limitations

  • Difficult to write and maintain for large applications.
  • Processor-specific.

C Language Programming

C provides structured, readable programming while still allowing direct hardware control through registers, pointers and bit operations.

Example:

#include <stdint.h>

int main(void)
{
    uint8_t count = 0;
    while (1)
    {
        count++;
    }
}

In practical firmware, initialization functions configure clocks, GPIO, ADC, timers and communication peripherals before the main loop executes.

Assembly vs C

Feature Assembly C
Readability Low High
Hardware control Very direct Direct through registers/APIs
Portability Low Higher
Development time Longer Shorter
Optimization Can be highly optimized Compiler-dependent

Conclusion

A microcontroller combines processing, memory and peripherals in one device. Assembly provides low-level control, while C provides a practical balance of performance, readability and portability for embedded DAQ applications.

Similar questions