vaayaa Inclusive Education
Micro-Diploma

Microcontroller Programming

5-Year Access Self-Paced Learning Certificate Included

Unlock Full Course

Get instant access to all sections and earn your verified certificate.

$9.99

Table of Contents

FREE PREVIEW — Section 1 of Module 1

What is a Microcontroller?

Unit
  • Definition: A microcontroller is a compact integrated circuit designed to govern a specific operation in an embedded system. It combines a processor, memory, and input/output peripherals on a single chip, making it ideal for cost-sensitive and power-constrained applications such as home appliances, automotive controls, and IoT devices.
  • Comparison with Microprocessor: Unlike a microprocessor, which requires external components for memory and I/O, a microcontroller integrates all necessary resources on-chip. This reduces system complexity, board space, and cost, but also limits expandability and processing power. Microcontrollers are typically optimized for deterministic control tasks rather than general-purpose computing.
  • Common Architectures: Popular microcontroller families include ARM Cortex-M (used in STM32, NXP LPC), Atmel AVR (used in Arduino), Microchip PIC, and Espressif ESP32. Each architecture offers different trade-offs in performance, power consumption, and peripheral set. ARM Cortex-M dominates the 32-bit market due to its ecosystem and efficiency.
  • Memory Organization: Microcontrollers use Harvard or von Neumann architectures. Harvard architecture separates program and data buses, allowing simultaneous access and improving speed. Flash memory stores firmware, SRAM holds runtime data, and EEPROM stores non-volatile configuration parameters. Memory sizes range from kilobytes to a few megabytes.
  • Clock Sources: Microcontrollers operate using internal oscillators or external crystal/resonator circuits. Internal RC oscillators are low-cost but less accurate, while external crystals provide stable timing for communication and real-time clocks. Many microcontrollers include PLL circuits to multiply the clock frequency for higher performance.
  • Operating Voltage and Power: Typical supply voltages range from 1.8V to 5.5V. Low-power modes such as sleep, deep sleep, and hibernate allow microcontrollers to operate on battery power for months. Designers must select microcontrollers with appropriate power profiles for their specific application needs.
  • Peripheral Integration: On-chip peripherals include general-purpose I/O (GPIO), analog-to-digital converters (ADC), timers, pulse-width modulation (PWM), and various serial communication interfaces (UART, I2C, SPI). These peripherals reduce the need for external components, lowering cost and improving reliability.
  • Development Ecosystem: Manufacturers provide software development kits (SDK), hardware abstraction layers (HAL), and integrated development environments (IDE) such as STM32CubeIDE, MPLAB X, and IAR Embedded Workbench. Open-source toolchains like GCC and OpenOCD are also widely used for flexibility.
System Architecture

Pattern: Microcontroller Core with Integrated Peripherals

Components:

  • CPU Core: Executes instructions fetched from flash memory; includes ALU, control unit, and registers.
  • Memory: Flash for code, SRAM for data, optional EEPROM for persistent storage.
  • System Bus: Connects CPU to memory and peripherals; typically uses a memory-mapped I/O scheme.
  • Peripherals: Accessed via memory-mapped registers; include GPIO, timers, ADC, communication modules.
  • Clock Generation: Internal RC oscillator or external crystal with PLL for clock multiplication.
  • Power Management: Voltage regulator and multiple sleep modes to reduce power consumption.
Code Example
C
#include <avr/io.h>
#include <util/delay.h>

int main(void) {
DDRB |= (1 << PB5); // Set PB5 as output (LED on Arduino Uno)
while (1) {
PORTB |= (1 << PB5); // Turn LED on
_delay_ms(1000); // Wait 1 second
PORTB &= ~(1 << PB5); // Turn LED off
_delay_ms(1000); // Wait 1 second
}
}

This minimal example configures pin PB5 as an output, then loops forever toggling the LED on and off with one-second delays. The DDRB register controls data direction, and PORTB sets output levels. The _delay_ms function provides a simple blocking delay.

Quick Revision
  • A microcontroller integrates CPU, memory, and peripherals on a single chip for embedded control.
  • Microcontrollers differ from microprocessors in integration level, cost, and power consumption.
  • Common architectures include ARM Cortex-M, AVR, PIC, and ESP32, each with unique strengths.
  • The development ecosystem includes manufacturer IDEs, HAL libraries, and open-source toolchains.
  • First firmware example toggles an LED using GPIO and delay functions, demonstrating basic I/O control.

Like what you see? Unlock the full course to continue.

Limited Offer
$9.99
Limited Offer $9.99