Embedded Programming

1. Group Assignment

We started by exploring the available microcontrollers in our local lab. We listed them to better organize our work. Then, we read a book about microcontrollers.

1.1 Understanding Microcontrollers

What is a Microcontroller?

A microcontroller is a compact integrated circuit that contains a processor, memory, and input/output (I/O) peripherals. It allows us to store and process data efficiently in a single chip.

Feature Microcontroller Microprocessor
Components CPU, memory, and I/O in one chip CPU only, needs external parts
Usage Used in embedded systems Used in computers

Bits and Bytes

A bit is the smallest unit of data in computing, representing either 0 or 1. A byte consists of 8 bits grouped together.

Understanding Number Systems

The importance of different number systems used in microcontrollers: - Decimal (Base-10): The system we commonly use. - Binary (Base-2): Used in digital electronics, consisting of only 0s and 1s. - Hexadecimal (Base-16): Commonly used in microcontrollers to simplify binary representations. - BCD (Binary-Coded Decimal): A system where each decimal digit is represented by its binary equivalent.

Registers

A register (or memory cell) is a small storage unit in a microcontroller that holds data temporarily.

Special Function Registers (SFR)

These are registers with predefined functions set by the manufacturer.

Memory Types

  • Read-Only Memory (ROM): Stores permanent data, such as firmware.
  • Masked ROM (MROM): Pre-programmed by the manufacturer.
  • One-Time Programmable ROM (OTP ROM): Can be programmed once; if an error occurs, a new chip is needed.
  • UV Erasable Programmable ROM (UV EPROM): Data can be erased using UV light, allowing reprogramming.

  • Random Access Memory (RAM): Stores temporary data that is lost when power is off.
  • Electrically Erasable Programmable ROM (EEPROM): Can be reprogrammed electronically while retaining data even after power loss.

Central Processing Unit (CPU)

The CPU is the core of the microcontroller, responsible for processing instructions and controlling all operations. It consists of:

  • Instruction Decoder: Deciphers program instructions.
  • Arithmetic Logic Unit (ALU): Performs mathematical and logical operations.
  • Accumulator: Temporarily stores data for processing.

Bus System

  • Address Bus: Transfers memory addresses from the CPU to memory.
  • Data Bus: Connects different components inside the microcontroller.

Serial Communication

For short distances, microcontrollers communicate via parallel connections. For longer distances, serial communication is used.

  • Baud Rate: The number of bits transmitted per second (bps).

Common Serial Communication Protocols

  • I2C (Inter-Integrated Circuit): Used for short-distance data exchange between multiple devices.

  • SPI (Serial Peripheral Interface): A fast communication protocol for short distances.

  • UART (Universal Asynchronous Receiver/Transmitter): Uses a single communication line for data exchange.
Feature I2C SPI UART
Communication Type Multi-master, multi-slave Single master, multiple slaves Full-duplex (one-to-one)
Wires 2 (SDA, SCL) 4 (MOSI, MISO, SCLK, SS) 2 (TX, RX)
Speed Medium Fast Slow
Devices Many Few Two
Complexity High Medium Low

Analog-to-Digital Conversion (ADC)

Converts analog signals into digital data that the CPU can process.

Internal Architecture

Von Neumann Architecture

Uses a single memory for both instructions and data, making it slower because the CPU can only access one at a time.

Harvard Architecture

Has separate memory for instructions and data, allowing simultaneous access for faster processing.

RISC (Reduced Instruction Set Computer)

Executes only simple operations (e.g., addition, subtraction) for higher efficiency.

CISC (Complex Instruction Set Computer)

Supports a large number of instructions, enabling more complex operations at high speed.

1.2 How to Choose the Right Microcontroller?

Selecting the right microcontroller can be challenging due to the vast number of options. Consider the following factors:

  • Number of input/output pins needed.
  • Complexity of operations (simple or advanced).
  • Requirement for serial communication.
  • and more..

Once you define your needs, narrow down the options and compare prices.

Steps to Get Started

  1. Select a manufacturer: Choose a microcontroller family that is easy to find.
  2. Study one model: Focus on learning the essentials without getting lost in details.
  3. Solve a practical problem: Applying knowledge to real-world tasks makes it easier to work with other models in the same family.

1.3 PIC Microcontroller Architecture

We explored the architecture of 8-bit PIC microcontrollers. With the knowledge gained from the previous sections, understanding different microcontroller architectures became easier.