Understanding Microcontrollers and Their Uses
Understanding Microcontrollers and Their Uses
In that sense, a microcontroller can be called an SoC (System on Chip) built typically for
embedded system use. One way to look at µC is a complete 'Chip' that contains other necessary
chips to perform a few specialized tasks which are characteristics of a typical embedded
system. At the same time, µP is a processing unit 'Chip' which is quite powerful and complex
and is typically used for general-purpose computing. Due to limited processing characteristics,
µC is typically cheaper than µP. Besides, µC is typically quite compact when compared with
µP. Examples of µC are the ARM Cortex-M series, Intel 8051, etc. Examples of µP are the
ARM Cortex-A series, Intel Pentium series, etc. We can find the use of µC in home appliances
such as Washing machines, Ovens, etc. while we can find the use of µP in desktop computers,
laptops, etc. It's not the question of which one is better. Instead, it's a question of what's the
need for a system. If someone is devising an embedded system where specific and customized
tasks need to be done, picking µC is a typical choice. On the contrary, picking µP is a typical
choice if someone devises a general-purpose computing device.
What is a Microprocessor?
A Microprocessor is an important part of a computer architecture without which you will not
be able to perform anything on your computer. It is a programmable device that takes in input
performs some arithmetic and logical operations over it and produces the desired output. In
simple words, a Microprocessor is a digital device on a chip that can fetch instructions from
memory, decode and execute them, and give results.
What is Microcontroller?
A microcontroller (MCU) is a small computer on a single integrated circuit that is designed to
control specific tasks within electronic systems. It combines the functions of a central
processing unit (CPU), memory, and input/output interfaces, all on a single
chip. Microcontrollers are widely used in embedded systems, such as home appliances,
automotive systems, medical devices, and industrial control systems. They are also used in
consumer electronics products, such as gaming systems, digital cameras, and audio players.
Microcontroller Microprocessor
It is a chip which is called single chip It is a general purpose device which is called a CPU.
computer.
Feature
Architecture Single-chip computer system with on- CPU with minimal on-board
board memory, peripherals, and I/O memory, peripherals, and
interfaces I/O interfaces
Clock speed Lower clock speed, typically less than 100 Higher clock speed,
MHz typically greater than 1 GHz
Pinout Description:
Different Types of Microcontrollers:
The microcontrollers are characterized regarding buswidth, instruction set, and memory
structure. The types of microcontrollers is shown in figure, they are characterized by their
bits, memory architecture, memory/devices and instruction set.
• The 16bit microcontroller performs greater precision and performance as compared to 8bit.
For example, 8-bit microcontrollers can only use 8 bits, resulting in a final range of
0×00 – 0xFF (0255) for every cycle. 16-bit microcontrollers with its 16-bit data width has a
range of 0×0000 – 0xFFFF (065535) for every cycle.
Some examples of 16bit microcontroller are 16bit MCUs are extended 8051XA, PIC2x,
Intel 8096 and Motorola MC68HC12 families.
• The 32bit microcontroller uses the 32bit instructions to perform the arithmetic and
logic operations. These are used in automatically controlled devices including
implantable medical devices, engine control systems, office machines, appliances
and other types of embedded systems. Some examples are Intel/Atmel 251 family, PIC3x.
RISC: The RISC stands for Reduced Instruction set [Link] type of instruction sets
reduces the design of microprocessor for industry standards. It allows each instruction to
operate on any register or use any addressing mode and simultaneous access of program
and data. RISC systems shorten execution time by reducing the clock cycles per instruction
and CISC systems shorten execution time by reducing the number of instructions per
program. The RISC gives a better execution than the CISC.
Harvard Memory Architecture Microcontroller: Many years ago, in the late 1940's, the US G
overnment asked Harvard and Princeton universities to come up with a computer
architecture to be used in computing distances of
Naval artillery shell for defence applications.
Princeton suggested computer architecture with a single memory interface. It is also known
as Von Neumann architecture after the name of the chief scientist of the project in
Princeton University John Von Neumann.
Harvard suggested a computer with two different memory interfaces, one for the data /
variables and the other for program / instructions. Although Princeton architecture was accep
ted for simplicity and ease of implementation,
Harvard architecture became popular later, due to the parallelism of instruction execution.
The point when a microcontroller unit has a dissimilar memory address space for
the program and data memory, the microcontroller has Harvard memory architecture in the
processor.
Microcontroller Families
A) PIC Microcontrollers
• Developer: Microchip Technology
• Architecture: RISC (Reduced Instruction Set Computing)
• Key Features:
o Multiple I/O ports
o Timers and counters
o Built-in ADC (Analog-to-Digital Converter)
o UART, SPI, I²C communication support
• Advantages:
o Low cost
o Reliable and stable
o Wide range of models
• Common Uses:
o Home appliances
o Industrial automation
o Basic robotics
Example: PIC16F877A used in washing machines for motor control.
B) AVR Microcontrollers
• Developer: Atmel (now Microchip Technology)
• Architecture: RISC (8-bit / 16-bit)
• Key Features:
o In-system programmable flash memory
o High-speed processing
o Wide peripheral set
o Low power consumption
• Advantages:
o Easy to program
o Popular for hobbyists and education
• Common Uses:
o Arduino boards (ATmega328P)
o IoT devices
o Robotics competitions
Example: Arduino Uno used in smart greenhouse automation.
C) ARM Microcontrollers
• Developer: ARM Holdings (IP licensed to others like ST, NXP, Texas Instruments)
• Architecture: RISC (32-bit, sometimes 64-bit)
• Key Features:
o High-performance CPU
o Advanced peripherals
o Ultra-low power operation
o Scalability across Cortex-M, Cortex-R, Cortex-A series
• Advantages:
o High speed and processing power
o Wide adoption in industry
o Supports complex OS (e.g., embedded Linux in higher-end versions)
• Common Uses:
o Smartphones
o Advanced automotive systems
o Industrial control panels
Example: STM32 series used in drones for flight control.
3. Comparison Table
Feature PIC AVR ARM
Architecture RISC (8/16-bit) RISC (8/16-bit) RISC (32-bit)
Performance Moderate High Very High
Power Usage Low Low Very Low
Cost Low Moderate Moderate to High
Ease of Use Moderate Easy Medium to Complex
Typical Apps Appliances, industry Education, robotics Smartphones, automotive
Applications of Microcontrollers
A) Automotive
• Examples:
o Engine Control Unit (ECU) → Optimizes fuel injection
o Anti-lock Braking System (ABS) → Ensures safe braking
o Airbag Deployment → Instant crash response
o In-vehicle Infotainment → Touchscreen control
• MCU Examples: ARM Cortex-M4 in ECU systems.
B) Consumer Electronics
• Examples:
o Remote Controls → Infrared signal control
o Washing Machines → Motor speed regulation
o Microwave Ovens → Timer and heating control
o Smart TVs → User interface control
• MCU Examples: PIC16F and ATmega in home appliances.
C) Industrial Control
• Examples:
o Process Automation → Conveyor belt regulation
o Robotics → Motion control and sensors
o Motor Control → VFD integration
o Safety Monitoring → Emergency shutoff systems
• MCU Examples: STM32 series for factory automation.
. Summary
• PIC: Best for cost-effective, small to medium tasks.
• AVR: Ideal for learning, prototyping, and low-power IoT.
• ARM: Suited for high-performance and complex applications.
• The right MCU choice depends on performance needs, cost constraints, and
peripheral requirements.
Difference between 8051, ARM, AVR, And PIC Microcontrollers
1 1 12 4
Speed clock/instructio clock/instructio clock/instructio clock/instructio
n cycle n cycle n cycle n cycle
32 bit mostly
8 bit for the
Bus width 8/32 bit also available in 8/16/32 bit
standard core
64 bit
Apple, Nvidia,
NXP, Atmel,
Qualcomm,
Silicon Labs, Microchip
Manufacturer Atmel Samsung
Dallas, Cyprus, Average
Electronics, and
Infineon, etc
TI
Modified
Memory Von Neumann Harvard
Modified Harvard
Architecture Architecture Architecture
Architecture
Power
Low Low Average Low
Consumption
UART, USART,
UART, USART,
LIN, I2C, SPI,
SPI, I2C, PIC, UART,
CAN, USB,
Communication (special purpose UART, USART, USART, LIN,
Ethernet, 12S,
Protocols AVR support SPI, I2C CAN, Ethernet,
DSP, SAI (serial
CAN, USB, SPI, I2S
audio interface),
Ethernet)
IrDA
LPC2148,
Popular Atmega8, 16, PIC18fXX8,
ARM Cortex- AT89C51,
Microcontroller 32, Arduino PIC16f88X,
M0 to ARM P89v51, etc
s Community PIC32MXX
Cortex-M7, etc
Flash, SRAM, Flash, SDRAM, ROM, SRAM,
Memory SRAM, FLASH
EEPROM EEPROM FLASH
Integrating features like software editing, building, testing, and packaging in a simple-to-use
tool, IDEs help boost developer productivity. IDEs are commonly used by programmers and
software developers to make their programming journey smoother.
One certainly does not need an IDE to code or develop applications. Even a simple text editor
like notepad can be used to write code. However, IDEs offer some stunning features that go
beyond ordinary editing. By providing frequently used developer tools all in one simple
interface, one can directly get on to building their applications without going through the
hardship of manually configuring and integrating the development environment.
• Editor: Typically a text editor can help you write software code by highlighting syntax
with visual cues, providing language-specific auto-completion, and checking for bugs
as you type.
• Debugger: A tool that can assist developers to test and debug their applications and
graphically point out the locations of bugs or errors if any.
• Version Control: Version control helps bring clarity to the development of the
software. Some IDEs also support version control tools like Git, through which a user
can track and manage the changes to the software code.
• Code snippets: IDEs support code snippets that are usually used to accomplish a single
task and can also reduce redundant work to some great extent.
• Extensions and Plugins: Extensions and Plugins are used to extend the functionality
of the IDEs with respect to specific programming languages.
• Code navigation: IDEs come with tools like code folding, class and method
navigation, and refactoring tools that make it simple to go through and analyze code.
Code Compiler Debugger Terminal Version
Editor – – – Step- – Run Control
Syntax Converts through comman Integratio
highlighti code to code, ds n – Built-
ng, machine/ inspect directly in *Git,
autocom executabl variables, history
plete e form breakpoin tracking
ts
Why do Developers Use IDE (Integrated Development Environment)?
By providing a single, unified environment for managing all aspects of the development
process, IDEs can help improve a developer's productivity, code quality, and overall
development experience.
• Code Quality: IDEs come with built-in tools as a part of a single GUI, through which
developers can execute actions without switching between applications. Furthermore,
it can also help in Syntax highlighting, code refactoring, and code analysis boosting
overall code quality.
IDEs come in various forms, some are designed to work for a specific language whereas some
are targeted to a particular platform like mobile devices. Hence, it becomes equally important
to choose an IDE best suited to one's needs.
This type includes the IDEs that can be configured locally. They do not need an active internet
connection to build/run programs. Desktop IDEs are highly customizable to suit developer-
specific needs and provide performance irrespective of the internet
speed. Examples: include Microsoft Visual Studio, Eclipse, Netbeans, Arduino IDE etc.
2. Cloud IDEs
Cloud IDEs eliminate the overhead of configuring the software locally. They run on
remote servers and can be accessed through desktop browsers. Cloud IDEs provide better
accessibility and platform independence making them accessible through the Internet
Irrespective of the Client Operating System. Cloud IDEs can be used freely or can have pricing
models with respect to the provider. Examples: Include Gitpod, AWS Cloud 9, Replit, etc.
One can find many IDEs available in the market, while some are open-source and free to use,
others may work with subscription models. Popular IDEs include Visual Studio, PyCharm,
Android Studio, etc.
2. Operating System: Mostly all IDEs work with different Operating systems, but there exist
IDEs that might only work best on specific platforms. You may take into account the IDEs'
compatibility with various platforms and operating systems.
3. Pricing Model: Some IDEs might be freely available while some may require a premium
subscription model to unlock the majority of the features. Taking your budget and your needs,
go with the IDE that suits you the best.
4. Features: Features like version control, debugger, code highlighter, integrated terminal, and
code refactoring are some of the features that can be considered white choosing an IDE.
• Project Management: IDEs make viewing the project directory structure much
simpler which breaks down the tedious tasks of working with multiple files. Typically
IDEs also include a number of tools, such as syntax highlighting, code completion, and
code folding, which makes it easier to manage the overall project.
• Saving plenty of time and Effort: IDEs often include a variety of tools that can not
only assist you in organizing your code but also quickly highlight the error in your code.
They also include a flexible combination of tools for compiling, building, testing, and
deploying your code, through which you can automate these tasks eliminating the need
to manually run each task.
• Not beginner Friendly: IDEs are complex tools and generally provide quite an
intimidating UI, which can be a little tough to comprehend for a beginner. Maximizing
their benefit generally needs a dedicated effort.
• Frequent Updates: It's difficult to keep up with constant updates, such as new samples,
templates, and features.
void main(void)
{
unsigned char mybyte;
P0=0xFF; //make P0 input port
while (1)
{
mybyte=P0; //get a byte from P0
if (mybyte<100)
P1=mybyte; //send it to P1
else
P2=mybyte; //send it to P2
}
}
I/O Write an 8051 C program to monitor bit P1.5. If it is high, send 55H
PROGRAMMING to P0; otherwise, send AAH to P2.
Solution:
Bit-addressable #include <reg51.h>
sbit mybit=P1^5;
I/O
(cont’) void main(void)
{
mybit=1; //make mybit an input
while (1)
{
if (mybit==1)
P0=0x55;
else
P2=0xAA;
}
}
A door sensor is connected to the P1.1 pin, and a buzzer is connected
to P1.7. Write an 8051 C program to monitor the door sensor, and
I/O when it opens, sound the buzzer. You can sound the buzzer by
PROGRAMMING sending a square wave of a few hundred Hz.
Solution:
Bit-addressable #include <reg51.h>
void MSDelay(unsigned int);
I/O sbit Dsensor=P1^1;
(cont’) sbit Buzzer=P1^7;
void main(void)
{
Dsensor=1; //make P1.1 an input
while (1)
{
while (Dsensor==1)//while it opens
{
Buzzer=0;
MSDelay(200);
Buzzer=1;
MSDelay(200);
}
}
}
I/O Write an 8051 C program to turn bit P1.5 on and off 50,000 times.
PROGRAMMING Solution: We can access a single bit of any
sbit MYBIT=0x95; SFR if we specify the bit address
Accessing SFR
void main(void)
Addresses {
80 - FFH unsigned int z;
(cont’) for (z=0;z<50000;z++)
{
MYBIT=1;
MYBIT=0;
}
}
void main(void)
{
while (1)
{
membit=inbit; //get a bit from P1.0
outbit=~membit; //invert it and send
//it to P2.7
}
}
LOGIC Write an 8051 C program to read the P1.0 and P1.1 bits and issue an
OPERATIONS ASCII character to P0 according to the following table.
P1.1 P1.0
0 0 send ‘0’ to P0
Bit-wise 0 1 send ‘1’ to P0
Operators in C 1 0 send ‘2’ to P0
1 1 send ‘3’ to P0
(cont’)
Solution:
#include <reg51.h>
void main(void)
{
unsignbed char z;
z=P1;
z=z&0x3;
...
...
switch (z)
LOGIC {
OPERATIONS case(0):
{
P0=‘0’;
break;
Bit-wise }
Operators in C case(1):
{
(cont’) P0=‘1’;
break;
}
case(2):
{
P0=‘2’;
break;
}
case(3):
{
P0=‘3’;
break;
}
}
}
8051 Input/Output
Interfacing
01
Digital I/O Essentials
8051 Port Architecture
Port Overview
The 8051 microcontroller features four 8-bit ports (P0-P3) that serve dual roles as
GPIO and special-function lines. Each port has unique characteristics, such as internal
pull-ups and open-drain capabilities, which are crucial for digital interfacing.
Assembly Code
Interfacing DAC0808
To generate analog voltages, connect a
DAC0808 to the 8051. Ensure proper reference
voltage selection and settling time
considerations. The DAC converts digital values
from the microcontroller to analog signals.
Waveform Generation
Using timer-triggered updates, the 8051 can
output sine, ramp, and custom waveforms.
Sample code demonstrates how to update the
DAC values periodically to generate these
waveforms.
03
Sensor Integration
Digital Sensor Links
Edge-Triggered
ISRs
Edge-triggered interrupt service
routines (ISRs) provide responsive
event capture. When a button press
Interfacing is detected, the ISR can trigger
specific actions, such as toggling an
Pushbuttons LED or updating a display.
Connect pushbuttons to the 8051
using polling or external interrupts.
Debounce algorithms are essential
to ensure reliable event capture.
Proper pull-up resistor sizing
prevents ghosting and ensures
stable readings.
Connecting LM35
To read temperature using an LM35 sensor, connect it to an ADC
channel. The LM35 provides a linear output proportional to the
temperature, making it easy to convert readings to temperature
values.
Calibration Formulas
Analog Sensor Readout Use calibration formulas to convert raw ADC counts to engineering
units. For example, the LM35 outputs 10 mV per degree Celsius.
Calibration ensures accurate temperature readings.
Temperature Compensation
Implement temperature compensation techniques to account for
sensor drift and environmental variations. This ensures that the
readings remain accurate across different operating conditions.
Multi-Sensor Scanning
Efficient Data Handling
Threshold Alarms
Ensure efficient data handling
Round-Robin Scanning Sample Code
by optimizing the scanning
Set threshold alarms to trigger routine. This includes
Implement a round-robin actions when sensor readings Provide sample code that minimizing delays and ensuring
scanning routine to exceed predefined limits. This is demonstrates the scanning that the microcontroller can
sequentially sample multiple useful for monitoring critical routine. The code should process data quickly.
analog sensors. This method parameters and taking corrective include initialization, data
ensures efficient time- actions. acquisition, and alarm triggering
multiplexed data acquisition, for multiple sensors.
storing results in RAM arrays.
04
Actuator & Switch Control
Relay & Motor Drivers
02
01 03
Motor Control
Control small DC motors using ULN2003
Driving Relays arrays. These arrays provide the necessary Safe Port Current Limits
current drive and protection for the motors.
Use NPN transistors or MOSFETs to drive Adhere to safe port current limits to prevent
Ensure proper current calculations to avoid
relays. Ensure proper flyback diodes are in damage to the microcontroller. Ensure that
overloading the microcontroller.
place to protect the microcontroller from the total current drawn by the actuators
inductive spikes. Calculate current limits to does not exceed the specified limits.
avoid damage.
LED & Display Arrays Controlling LED Control LED strips using multiplexing techniques.
Ensure proper duty-cycle timing to achieve
Strips
persistence of vision and avoid flickering. Provide
sample code for interrupt-driven refresh.
Mini-Project Overview
Demonstrate a complete mini-project that integrates
temperature reading, display on 7-segment LEDs, a. This
project illustrates cohesive I/O control and practical
application of the concepts discussed.
Digital Thermometer using
LM35 and 8051
LM35 Features Interface Details
LM35 Sensor Overview
The LM35 interfaces seamlessly
The LM35 is a precision
with microcontrollers through a
temperature sensor with a linear
single analog line.
output of 10 mV per degree
Celsius.
It requires a 5V supply and
provides a linear output that
It operates within a range of 0
can be directly connected to an
to 100 degrees Celsius and
ADC pin for temperature
requires no external calibration.
readings.
Display Type
Common-cathode 7-segment displays are
used to show temperature readings. These
displays require multiplexing to drive
multiple digits using a limited number of
GPIO pins. Each segment is driven through
current-limiting resistors to ensure stable
operation.
Circuit Diagram:
THANK
YOU
R A M M EMORY SPACE
ALLOCATION
&
ADDRESSING MODES
8051 – Microcontroller
R AM A LLOCATION
R EGISTER BANKS & STACK
R EGISTER BANKS
R EGISTER BANKS
R EGISTER BANK SELECTION MNEMONIC
A DDRESSI NG MODES
I MMEDIATE ADDRESSING MODE
R EGISTER ADDR E SSIN G MODE
D IRECT ADDRESSING MODE
S PE CIAL F U N CTIO N REGISTER
R EGISTER INDIRECT ADDRESSING MODE
R EGISTER INDIRECT ADDRESSING MODE
I NDEXED ADDRESSING MODE
Debugging Tools & Techniques for Embedded Systems
Debugging tools are hardware or software instruments that let engineers observe,
control, and correct the behavior of an embedded system while code is running—by
halting, stepping, tracing, and inspecting memory, registers, and peripherals
Process of Debugging
• To start, you need to recreate the conditions that caused the bug. This means
making the error happen again so you can see it firsthand.
• Seeing the bug in action helps you understand the problem better and gather
important details for fixing it.
• Next, find where the bug is in your code. This involves looking closely at your
code and checking any error messages or logs.
• Now, figure out why the bug happened. Examine the logic and flow of your code
and see how different parts interact under the conditions that caused the bug.
• Once you know the cause, fix the code. This involves making changes and then
testing the program to ensure the bug is gone.
• Sometimes, you might need to try several times, as initial fixes might not work or
could create new issues.
• Using a version control system helps track changes and undo any that don't solve
the problem.
After fixing the bug, run tests to ensure everything works correctly. These tests include:
• Unit Tests: Check the specific part of the code that was changed.
• Integration Tests: Verify the entire module where the bug was found.
• Regression Tests: Make sure the fix didn’t cause any new problems elsewhere in
the application.
• Finally, record what you did. Write down what caused the bug, how you fixed it,
and any other important details.
From a very high level there are only 2 ways to debug an Embedded System.
1. Direct Debugging
2. In Direct Debugging
On-chip debugging involves the use of dedicated hardware circuitry to view and control
the microcontroller or microprocessor directly. JTAG (Joint Test Action Group) is a
commonly used on-chip debugging protocol.
Key Features:
6. In-Direct Debugging
Key Features:
Tools for debugging embedded systems range from software monitors and simulators,
which are independent of the hardware under development, to custom silicon for in-
circuit emulation, which replaces the target processor for maximum hardware control.
Several tools combine these approaches and vary greatly in cost and performance. In
general, the higher the level of integration with the end-product hardware, the greater the
benefit of a tool in shortening product development time, but the greater the cost as well.
1. Simulators
Software instruction simulators provide simulated program execution with read and write
access to the internal processor registers. Beyond that, the tools vary in capability. Some
are limited to simulation of instruction execution only. Most offer breakpoints, which
allow fast execution until a specified instruction is executed. Many also offer trace
capability, which shows instruction execution history.
2. In-circuit emulators
In-circuit emulators are plugged into a system in place of the embedded processor. They
offer real-time code execution, full peripheral implementation, and breakpoint capability.
High-end emulators also offer real-time trace buffers, and some will time-stamp
instruction execution for code profiling (see figure ).
Some in-circuit emulators have special ASICs or FPGAs that imitate core processor code
execution and peripherals, but there may be behavioral differences between the actual
device and the emulator. The problem is sidestepped with “bond-out” emulation devices
that provide direct I/O and peripheral access using the same circuit technology as the
processor and that provide access to the internal data registers, program memory, and
peripherals.
This is accomplished by using emulation RAM instead of the processor’s internal program
memory. The microcontroller firmware is downloaded into the emulation RAM and the
bond-out processor executes instructions using the same data registers and peripherals
as the target processor. The I/Os of the bond-out silicon are made available on a socket
that is plugged into the system under development instead of the target processor being
emulated.
State-of-the-art emulators provide multilevel conditional breakpoints and instruction
trace, including code coverage and timestamping. Some even allow code tracing without
halting the processor.
There is a large gap in performance and price between software simulators and hardware
emulators. Between the two extremes, there is a lot of room for intermediate solutions.
3. Burn-and-learn method
Simulation is most often used with the burn-and-learn method of run-time firmware
development. A chip is burned with a device programmer; and after plugging it into the
hardware, the system crashes.
At this point, an attempt is made to figure out what went wrong; the source code is
changed, the executable is rebuilt, and another chip is burned. This cycle is repeated until
the chip works properly.
Routines can be added to dump vital debugging information to a serial port for display on
a terminal. I/O pins can be toggled to indicate program flow.
If more symptoms are provided by the system as it runs, then more logical changes to the
source code can be made. Overall, this method of debugging is inefficient, slow, and
tedious.
4. In-circuit simulators
When simulating code where branches are conditional on the state of an input pin or
other hardware condition, a simulator can get information on that state from the
hardware using simulator stimulus. This is the first step away from software-only
simulation, allowing a certain amount of hardware debug.
However, such tools run at the speed of a simulator, so they can’t set and clear output
pins fast enough to implement timing-critical features like a software UART. They often
don’t support complex peripheral features such as A/Ds and PWMs.
5. Run-time monitors
Software breakpoints can be built in at compile time. Other features, such as hooking
into a periodic timer interrupt to copy data of interest from the target to the host, can also
be included when building the executable. Since these techniques don’t require writing
to program memory at run time, they can be used with burn-and-learn debug using one-
time-programmable devices.
The routines required to transfer debug data to the host or to download a new executable–
the monitor code itself–occupy a certain amount of program memory on the target
device. They also use data memory and bandwidth in addition to the UART or other
communication device. However, most of this overhead occurs when code execution is
not in progress.
Use of a software run-time monitor is a great step forward from simulation in isolation
from the target hardware. Adding just a few simple support features in the silicon of the
target processor can turn the monitor into a system that provides all the basic features of
an emulator.
6. In-circuit debuggers
The system becomes more than a software monitor when custom silicon features are
added to the target processor. Development tools with special silicon features to support
code debug and having serial communication between host and target are typically
referred to as “debuggers.”
In the past, some systems have used external RAM program memory to support this
feature. Now reprogrammable flash memory has made in-circuit debuggers (ICDs)
practical for single-chip embedded microcontrollers. ICDs allow the embedded
processor to “self-emulate.”
This feature, along with the In-Circuit Serial Programming (ICSP) protocol, offers cost-
effective in-circuit flash program load and debugging from the graphical user interface of
the MPLAB Integrated Development Environment. The designer can develop and debug
source code by watching variables, single-stepping, and setting breakpoints. Running the
device at full speed enables testing hardware in real time.
The in-circuit debugger consists of three basic components: the ICD module, ICD
header, and ICD demo board. The MPLAB software environment is connected to the ICD
module via a serial or full-speed USB port.
When instructed by MPLAB, the ICD module programs and issues debug commands to
the target microcontroller using the ICSP protocol, which is communicated via a five-
conductor cable using a modular RJ-12 plug and jack. A modular jack can be designed
into a target circuit board to support direct connection to the ICD module, or the ICD
header can be used to plug into a DIP socket.
The ICD header contains a target microcontroller and a modular jack to connect to the
ICD module. Male 40- and 28-pin DIP headers are provided to plug into a target circuit
board. The ICD header may be plugged into either the included ICD demo board or the
user’s custom hardware.
The demo board provides 40- and 28-pin DIP sockets that will accept either a
microcontroller device or the ICD header. It also offers LEDs, DIP switches, an analog
potentiometer, and a prototyping area.
Immediate prototype development and evaluation are feasible even if hardware isn’t yet
available. The complete hardware development system, along with the host software,
provides a powerful run-time development tool at a very reasonable price.
7. Run-time operation
The debug kernel is downloaded along with the target firmware via the ICSP interface. A
nonmaskable interrupt vectors execution to the kernel under three conditions: when the
program counter equals a preselected hardware breakpoint address, after a single step,
or when a halt command is received from MPLAB.
As with all interrupts, this pushes the return address onto the stack. On reset, the
breakpoint register is set equal to the reset vector, so the kernel is entered immediately
when the device comes out of any reset.
The ICD module issues a reset to the target microcontroller immediately after a
download. Thus, after a download the kernel is entered, and control is passed to the host.
The user can now issue commands to the target processor and modify or interrogate all
RAM registers, including the PC and other special function registers. The user can single-
step, set a breakpoint, animate, or start full-speed execution.
Once started, a halt of program execution causes the PC address prior to kernel entry to
be stored, which allows the software to display where execution halted in the source
code. When the host is commanded to run again, the kernel code executes a return from
interrupt instruction, and execution continues at the address that pops off the hardware
stack.
The breakpoint address register and comparator make up most of what is needed in
silicon, along with some logic to single-step and recognize asynchronous commands
from the host. Since the ICSP programming interface is already in place to support
programming of the device, this doesn’t constitute an additional silicon requirement.
When this channel is used for in-circuit debug, these two I/O pins may not be used for
other run-time functions.
With the basic run-time features of single-step, full-speed execution and watching
variables, an in-circuit debugger can help in a lot of designs where only an emulator
would have done before. Investing in the right development tools up front will pay back
handsomely in faster development and debug cycles and a shorter time to market.