0% found this document useful (0 votes)
3 views16 pages

Unit 4 Embedded Notes

The document outlines the process of designing embedded systems using the 8051 microcontroller, detailing steps from requirement analysis to testing and debugging. It emphasizes the importance of selecting appropriate controllers based on performance, resources, and cost, and provides an overview of the 8051 architecture and programming considerations. Additionally, it discusses the compiling, linking, and debugging processes essential for executing programs on the microcontroller.

Uploaded by

heena.18.2006
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views16 pages

Unit 4 Embedded Notes

The document outlines the process of designing embedded systems using the 8051 microcontroller, detailing steps from requirement analysis to testing and debugging. It emphasizes the importance of selecting appropriate controllers based on performance, resources, and cost, and provides an overview of the 8051 architecture and programming considerations. Additionally, it discusses the compiling, linking, and debugging processes essential for executing programs on the microcontroller.

Uploaded by

heena.18.2006
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIT - IV DESIGNING EMBEDDED SYSTEM WITH 8051 MICROCONTROLLER

FACTORS TO BE CONSIDERED IN SELECTING A CONTROLLER – 8051


MICROCONTROLLER – DESIGNING WITH 8051 PROGRAMMING:
STRUCTURE OF EMBEDDED PROGRAM – INFINITE LOOP – COMPILING,
LINKING & DEBUGGING.

DESIGNING EMBEDDED SYSTEM WITH 8051 MICROCONTROLLER:

Designing an embedded system using the 8051 microcontroller involves integrating


hardware and software to perform a specific control task. The 8051 is widely used in
embedded applications because of its simple architecture, built-in peripherals, and ease of
programming.

1. Definition

Designing an Embedded System with 8051 is the process of creating a dedicated electronic
system using the 8051 microcontroller to control devices, process inputs, and produce
outputs for a specific application.

2. Steps in Designing an Embedded System with 8051

1. Requirement Analysis

 Identify the purpose of the system.


 Determine inputs, outputs, processing needs, and performance requirements.

2. Hardware Selection

Select the required components:

 8051 Microcontroller
 Power supply circuit
 Crystal oscillator
 Reset circuit
 Input devices (switches, sensors)
 Output devices (LEDs, motors, displays)
 External memory (if needed)

3. Hardware Design

 Connect components to the 8051 ports (P0, P1, P2, P3).


 Design circuits for input/output interfacing.
 Ensure proper voltage levels and protection circuits.

4. Software Development

 Write the control program in Assembly language or Embedded C.


 The program controls how the microcontroller reads inputs and generates outputs.

5. Program Compilation

 Convert the source code into machine code (HEX file) using a compiler.

6. Simulation and Testing

 Use software tools (like Keil or Proteus) to test the program before hardware
implementation.

7. Programming the Microcontroller

 Load the compiled program into the 8051 microcontroller memory using a
programmer.

8. System Integration

 Combine the hardware circuit and the programmed microcontroller.


9. Testing and Debugging

 Test the complete system.


 Fix errors in hardware or software if necessary.

3. Components Required

 8051 Microcontroller
 Crystal Oscillator
 Reset Circuit
 Power Supply
 Input Devices (Switches, Sensors)
 Output Devices (LED, LCD, Motor)
 External Memory (optional)

4. Advantages of Designing Embedded Systems with 8051

 Simple architecture
 Low cost
 Easy programming
 Built-in timers and serial communication
 Widely available development tools

5. Applications

 Home automation systems


 Traffic light control
 Industrial automation
 Security systems
 Consumer electronics

FACTORS TO BE CONSIDERED IN SELECTING A CONTROLLER:

A microcontroller is a compact integrated circuit designed to govern specific operations in


embedded systems. Selecting the right controller is crucial to ensure efficiency, cost-
effectiveness, and suitability for the intended application. Several factors must be considered
to make the optimal choice.
1. High Performance

 Refers to the processing speed and computational capability of the controller.


 Important for applications requiring fast response times, real-time control, or heavy
computation.
 High-performance controllers improve efficiency but may increase cost and power
consumption.

2. On-Chip Resources

 These are the built-in peripherals like timers, ADCs, DACs, communication
interfaces (UART, SPI, I2C), and memory.
 Controllers with sufficient on-chip resources reduce the need for external
components, making the system smaller, cheaper, and easier to design.

3. Compatibility and Upgradeability

 Ensures that the controller works with existing hardware and software.
 Upgradeable controllers allow future enhancements, firmware updates, or migration
to more advanced models without redesigning the system.
4. Development Tool

 Availability of IDE, compilers, debuggers, and libraries.


 Easier development leads to faster prototyping and debugging, reducing design
time.
 Good tool support is crucial, especially for beginners or complex applications.

5. Provider

 Refers to the manufacturer or supplier of the microcontroller.


 Factors like reliability of supply, after-sales support, documentation, and
community resources affect the selection.
 Established providers often offer better reliability and long-term availability.

6. Cost

 The total price of the microcontroller, including per-unit cost, development cost,
and external components savings.
 Cost must align with the project budget, especially for large-scale production.

7. Power Consumption

 Critical for battery-operated or energy-sensitive applications.


 Controllers with low power modes or efficient energy usage prolong battery life.
 Power consumption also affects thermal management of the system.

8. Other Factors

 Miscellaneous considerations like physical package, temperature range, EMI/ESD


resistance, reliability, and longevity.
 These factors ensure the controller is robust, durable, and suitable for
environmental conditions.

8051 MICROCONTROLLER

1. Definition of 8051 Microcontroller


 The 8051 Microcontroller is an 8-bit microcontroller developed by Intel in 1980.
 It is designed for embedded systems to control specific tasks efficiently.
 Contains CPU, memory, and I/O ports on a single chip, making it compact and
cost-effective.

2. Architecture of 8051 Microcontroller

The 8051 has a Harvard architecture, meaning separate memory for program and data.
Key components:

1. CPU (Central Processing Unit)


o Performs arithmetic, logic, and control operations.
2. ROM/Flash (Program Memory)
o Stores the program code permanently.
3. RAM (Data Memory)
o Stores temporary data and variables during execution.
4. I/O Ports (P0, P1, P2, P3)
o 4 parallel input/output ports used to interface with external devices.
5. Timers/Counters
o Two 16-bit timers for timing operations and counting external events.
6. Serial Port (UART)
o Used for serial communication with other devices.
7. Interrupts
o Five interrupt sources to handle real-time events.
8. Oscillator and Clock Circuit
o Provides clock pulses for timing and operation.

3. Features of 8051 Microcontroller

1. 8-bit CPU – can process 8 bits of data at a time.


2. On-chip 4 KB ROM for program storage.
3. 128 bytes RAM for data storage.
4. 32 I/O pins through 4 ports (P0–P3).
5. Two 16-bit timers/counters for time-based tasks.
6. Supports serial communication via UART.
7. Five interrupt sources for responsive operations.
8. Low power consumption with idle and power-down modes.

4. Applications of 8051 Microcontroller

 Embedded systems: washing machines, microwave ovens, and remote controls.


 Industrial automation: motor control, robotics, sensors.
 Communication: UART-based data transfer.
 Consumer electronics: calculators, digital clocks, toys.

DESIGNING WITH 8051 PROGRAMMING

1. Introduction to 8051 Programming

The 8051 microcontroller is an 8-bit microcontroller widely used in embedded systems for
controlling hardware. Programming it involves writing instructions to perform tasks like I/O
control, arithmetic, logic operations, and interfacing with peripherals.

 Programming Languages: Assembly language (low-level) or C language (high-


level).
 Execution Model: Harvard architecture (separate program and data memory).
 Purpose: Control devices, read sensors, manage displays, communicate with
peripherals.

2. Designing Steps with 8051 Programming

Step 1: Define System Requirements

 Identify what the embedded system should do.


 Examples: Temperature monitoring, motor control, LED display, sensor data logging.
 Points to consider:
1. Input types (switch, sensor, keyboard).
2. Output types (LEDs, motors, displays).
3. Timing requirements (real-time, periodic).
4. Communication interfaces (UART, SPI, I2C).
5. Memory requirements (ROM, RAM, EEPROM).

Step 2: Choose the 8051 Microcontroller

 Select based on system requirements.


 Factors for Selection:
1. Number of I/O pins.
2. Available timers/counters.
3. On-chip memory (ROM, RAM).
4. Clock speed requirements.
5. Peripheral support (serial ports, ADC/DAC).

Step 3: Hardware Design

 Design the circuit connecting microcontroller to inputs and outputs.


 Important components:
1. Power supply (regulated 5V for 8051).
2. Clock oscillator (12 MHz typical).
3. Reset circuitry.
4. Input devices (switches, sensors).
5. Output devices (LEDs, motors, relays).
Step 4: Write the Program

 Program logic based on system requirements.


 Programming Tips:
1. Start with small test routines.
2. Use modular functions for readability.
3. Implement delays using timers for precise control.
4. Use interrupts for real-time responses.
5. Simulate and debug before loading on hardware.

Step 5: Compile and Load Program

 Use Keil μVision or similar IDE for compiling.


 Convert the code to hex file.
 Load hex file into 8051 via programmer.

Step 6: Testing and Debugging

 Test each module separately: input reading, output control, communication.


 Debugging techniques:
1. LED indicators for flow tracking.
2. Serial output for monitoring values.
3. Oscilloscope/logic analyzer for timing issues.

Step 7: Optimization

 Optimize program for memory and speed.


 Reduce unnecessary loops and delays.
 Use bit manipulation for I/O efficiency.

3. Example Program in 8051 (LED Blinking)

Assembly Language Example:

ORG 0H ; Program starting address


START:
MOV P1, #0FFH ; Set Port1 as output
LOOP:
CPL P1 ; Toggle all pins of Port1
ACALL DELAY ; Call delay subroutine
SJMP LOOP ; Repeat loop
DELAY:
MOV R2, #255
D1: MOV R1, #255
D2: DJNZ R1, D2
DJNZ R2, D1
RET
END

Explanation:

 Toggles all LEDs connected to Port 1.


 Uses a software delay loop to make LED blinking visible.

4. Programming Considerations

1. Memory Management: Ensure code fits in program memory.


2. Timing Accuracy: Use timers for precise delays.
3. Interrupt Handling: For real-time applications like alarms or sensors.
4. Power Consumption: Optimize for low power if battery-operated.
5. Peripheral Compatibility: Match interfaces (UART, SPI) with devices.

STRUCTURE OF EMBEDDED PROGRAM:

An embedded program is designed to continuously control hardware. The typical structure:

a) Header / Include Files (C programs)

Definition:
Header or include files contain predefined definitions, macros, and declarations for the
microcontroller’s special function registers (SFRs), ports, and hardware features. They allow
the program to recognize and use microcontroller-specific resources.
Purpose:

 Provide names for SFRs like P0, P1, TMOD, TH0.


 Include standard library functions.
 Avoid manually defining hardware addresses.

Example:

#include <reg51.h> // 8051 register definitions


#include <stdio.h> // Standard input-output library

b) Initialization Section

Definition:
The initialization section is the part of the program where the microcontroller and its
peripherals are configured before starting the main tasks.

Purpose:

 Prepare hardware for operation.


 Set input/output directions for ports.
 Configure timers, counters, serial communication, and interrupts.

Key Components:

1. Port Initialization: Set pins as input or output.

P1 = 0x00; // Port1 as output


P2 = 0xFF; // Port2 as input

2. Timer Initialization: Configure timers for delays or events.

TMOD = 0x01; // Timer0 mode1


TR0 = 1; // Start Timer0

3. Interrupt Setup: Enable interrupts if required.

IE = 0x85; // Enable Timer0 and External interrupt 0


C Subroutines / Functions
Subroutines or functions are separate blocks of code that perform specific tasks and can be
called multiple times from the main program or other subroutines.

 Breaks the program into manageable, reusable modules.


 Examples:
1. Delay Function:

void delay_ms(unsigned int ms) {


unsigned int i, j;
for(i=0;i<ms;i++)
for(j=0;j<1275;j++);
}

2. LCD Display Routine


3. UART Transmit/Receive Function

INFINITE LOOP:

1. Definition of Infinite Loop

An infinite loop is a loop that runs continuously without termination until the
microcontroller is powered off or reset.

 In embedded systems, infinite loops are used because the system must continuously
monitor inputs and control outputs in real time.
 The microcontroller never “exits” the program like a PC application; it runs
indefinitely.

2. Purpose of Infinite Loop in 8051

1. Continuous Monitoring: Keep checking sensors, switches, or inputs.


2. Real-Time Response: Respond to events, alarms, or inputs as they occur.
3. Task Repetition: Execute tasks repeatedly, like blinking LEDs or reading data.
4. Supports Interrupts: Allows asynchronous interrupts to preempt the loop while the
main program keeps running.
5. System Reliability: Ensures the system doesn’t stop unexpectedly.

3. Infinite Loop in C Language

Syntax:

while(1) {
// Main program tasks
}

Example: Blinking an LED on Port 1

#include <reg51.h>

void delay_ms(unsigned int ms);

void main() {
P1 = 0x00; // Port1 as output
while(1) { // Infinite loop
P1 = 0xFF; // Turn ON LEDs
delay_ms(500);
P1 = 0x00; // Turn OFF LEDs
delay_ms(500);
}
}

void delay_ms(unsigned int ms) {


unsigned int i, j;
for(i=0; i<ms; i++)
for(j=0; j<1275; j++);
}

Explanation:

 The while(1) ensures the LED blinking repeats forever.


 The program never exits the main loop.
COMPILING, LINKING & DEBUGGING.

When programming the 8051 microcontroller, writing code in C or Assembly is just the
first step. To run the program on the hardware, it must go through three key processes:

1. Compiling – Converts source code into machine-understandable object code.


2. Linking – Combines object code and libraries into a single executable (HEX) file.
3. Debugging – Detects and corrects errors, ensuring correct program execution.

2. Compiling

Definition:
Compiling is the process of converting high-level code (C) or assembly code into object
code (binary instructions the 8051 can execute).

Purpose:

 Translate human-readable instructions into machine code.


 Detect syntax errors in code.
 Prepare code for linking.

Workflow:

1. Source code (.c or .asm) is input to the compiler.


2. Compiler checks syntax and semantics.
3. Generates object code (.obj) or intermediate code.

Example in C (Keil μVision):

#include <reg51.h>
void main() {
P1 = 0xFF; // Turn on LEDs
}

 Compiler converts this into machine code instructions stored in memory.

Common Compiler Errors:


 Missing semicolons ;
 Undeclared variables or functions
 Invalid register names

3. Linking

Definition:
Linking is the process of combining compiled object code with library routines to produce
a single executable file (HEX) that can be loaded onto the microcontroller.

Purpose:

 Resolve addresses of functions and variables.


 Combine multiple modules or files into one program.
 Include predefined libraries for hardware control.

Example:

 Your main program calls a delay function in another file.


 The linker ensures the correct memory address for the delay function is included in
the HEX file.

Output:

 A HEX file (e.g., [Link]) ready to be programmed into the 8051’s memory.

Note:

 Linking is crucial for modular programs with multiple subroutines or library calls.

4. Debugging

Definition:
Debugging is the process of finding and correcting errors (bugs) in the program to ensure
proper operation on the microcontroller.
Purpose:

 Ensure the program functions as intended.


 Detect logical errors or timing issues.
 Monitor the microcontroller’s internal registers and memory.

You might also like