0% found this document useful (0 votes)
15 views15 pages

Combinepdf

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)
15 views15 pages

Combinepdf

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
You are on page 1/ 15

MICROCONTROLLERS AND EMBEDDED SYSTEMS

(Established Under Punjab Act No. 35 of 1961)

Abdullahi Yahye Ahmed


(12492007)
Assignment 3 & $4

DEPARTMENT OF ELECTRONIC AND COMMUNICATION ENGINEERING


PUNJABI UNIVERSITY, PATIALA
Assignment 3
1. Microcontroller Architecture
A microcontroller is a compact integrated circuit designed to perform specific control functions
within an embedded system. The 8051-microcontroller architecture includes the following key
components:
1. Central Processing Unit (CPU):
o Executes instructions, processes data, and manages overall control of the
microcontroller.
o Performs arithmetic and logical operations.
2. Memory:
o ROM (Read-Only Memory): Stores the program code (firmware).
o RAM (Random Access Memory): Used for temporary data storage during
execution.
o In 8051:
▪ 4KB ROM.
▪ 128 bytes RAM.
3. I/O Ports:
o Provides an interface for input and output devices.
o In 8051, there are four 8-bit ports (P0, P1, P2, P3).
4. Timers/Counters:
o Two 16-bit timers (Timer 0 and Timer 1) for generating delays or counting
external events.
5. Serial Communication Interface:
o UART for serial data transfer.
6. Interrupt Control:
o 8051 supports five interrupts, enabling the microcontroller to handle
asynchronous events.
7. Oscillator and Clock:
o Provides the timing required for instruction execution using an external
crystal oscillator.
8. Special Function Registers (SFRs):
o Registers used for controlling specific functions like timers, interrupts, and
serial communication.
2. Addressing Modes with Examples

Addressing modes define how an instruction accesses data in memory or registers. The 8051
microcontroller supports the following addressing modes:
1. Immediate Addressing Mode:
o The operand is directly specified in the instruction.
o Example: MOV A, #25H (Move the immediate value 25H into
accumulator A).
2. Register Addressing Mode:
o The operand is located in one of the registers (R0 to R7).
o Example: MOV A, R1 (Move the value in register R1 to accumulator A).
3. Direct Addressing Mode:
o The operand is specified by its address in RAM.
o Example: MOV A, 30H (Move the value at address 30H into accumulator
A).
4. Indirect Addressing Mode:
o The operand’s address is stored in a register (R0 or R1).
o Example: MOV A, @R0 (Move the value at the address pointed to by R0
into A).
5. Indexed Addressing Mode:
o Used to access program memory.
o Example: MOVC A, @A+DPTR (Move the code byte at the address
formed by A and the DPTR to A).

3. RAM Organization
The RAM in the 8051 microcontroller is organized into three main sections:
1. General Purpose RAM:
o 80 bytes (30H to 7FH) used for temporary data storage.
o Accessible via direct and indirect addressing modes.
2. Bit-Addressable Area:
o 16 bytes (20H to 2FH) where each bit can be individually addressed.
o Useful for flags or control bits.
o Example: SETB 20H.0 (Set bit 0 of address 20H).
3. Register Banks:
o First 32 bytes (00H to 1FH) divided into four banks (Bank 0 to Bank 3),
each containing eight registers (R0 to R7).
o The active bank is determined by the PSW (Program Status Word)
register.
4. Special Function Registers (SFRs):
o Located in the address range 80H to FFH.
o Used for control and configuration of microcontroller features (e.g.,
timers, interrupts).
o Example: ACC (Accumulator), TMOD (Timer Mode), PCON (Power
Control).
4. Steps to Send and Receive Data Serially

Serial communication involves transferring data one bit at a time. Here are the detailed steps:

Sending Data Serially:

1. Initialize the Serial Port:


o
Configure the serial communication settings (baud rate, data bits, parity)
using the SCON register.
o Example for 8051: Set SCON = 50H for 8-bit UART mode.
2. Set the Baud Rate:
o Use Timer 1 in Mode 2 to generate the desired baud rate.
o Example: Set TH1 = -3 for a baud rate of 9600.
3. Load Data into the Transmit Buffer:
o Place the data byte to be transmitted into the SBUF register.
o Example: MOV SBUF, #‘A’ (Send character 'A').
4. Monitor Transmit Interrupt Flag:
o Wait for the TI (Transmit Interrupt) flag to indicate that the transmission is
complete.
5. Clear the TI Flag:
o Clear the TI flag to prepare for the next transmission.
Receiving Data Serially:
1. Enable the Serial Port:
o Configure the SCON register for reception.
2. Wait for the RI (Receive Interrupt) Flag:
o Monitor the RI flag to check if data has been received.
3. Read Data from SBUF:
o Read the received byte from the SBUF register.
4. Clear the RI Flag:
o Clear the RI flag to prepare for receiving the next byte.

5. Timer Modes Operations


The 8051 microcontroller has two 16-bit timers (Timer 0 and Timer 1). Each timer can operate in
different modes, controlled by the TMOD register.
Timer Modes:
1. Mode 0 (13-bit Timer/Counter):
o Timer operates as a 13-bit counter, with the upper 3 bits of TLx
ignored.
o Example: Used for applications requiring low-resolution timing.
2. Mode 1 (16-bit Timer/Counter):
o Full 16-bit timer mode (THx and TLx together form a 16-bit
counter).
o Example: Used for accurate time delays.
3. Mode 2 (8-bit Auto-Reload):
o Timer operates as an 8-bit counter.
o The value in THx is automatically reloaded into TLx after
overflow.
o Example: Used for generating periodic interrupts or baud rate
generation.
4. Mode 3 (Split Timer Mode):
o Timer 0 is split into two 8-bit timers (TL0 and TH0 act as
independent timers).
o Example: Allows two separate 8-bit timers to run simultaneously.
Applications of Timer Modes:
• Mode 0 and 1: Generating delays or measuring time intervals.
• Mode 2: Generating precise baud rates for serial communication.
• Mode 3: Running multiple tasks requiring separate timers.
Steps to Use a Timer:
1. Select the Timer Mode:
o Set the desired mode in the TMOD register.
o Example: TMOD = 01H (Timer 0 in Mode 1).
2. Load the Initial Value:
o Load the starting count into THx and TLx registers.
3. Start the Timer:
o Set the TRx (Timer Run) bit in the TCON register.
o Example: SETB TR0 (Start Timer 0).
4. Monitor the Timer Overflow Flag:
o Check the TFx flag to detect timer overflow.
5. Stop the Timer:
o Clear the TRx bit to stop the timer.
6. Clear the Overflow Flag:
o Clear the TFx flag for subsequent operations.
Assignment 4
Q1: List various arithmetic instructions for 8051 microcontrollers with examples.
Ans1:
The 8051 microcontroller supports several arithmetic instructions for performing
mathematical operations. Here are the key ones:
1. Addition (ADD):
o Syntax: ADD A, source
o Adds the source value to the accumulator.
o Example: ADD A, #25H (Adds immediate value 25H to the value in A).
2. Subtraction (SUBB):
o Syntax: SUBB A, source
o Subtracts the source value from the accumulator, including the borrow.
o Example: SUBB A, #10H (Subtracts immediate value 10H with borrow from A).
3. Multiplication (MUL):
o Syntax: MUL AB
o Multiplies the values of A and B, and the result is stored in A (low byte) and B
(high byte).
o Example: If A = 02H and B = 03H, MUL AB results in A = 06H, B = 00H.
4. Division (DIV):
o Syntax: DIV AB
o Divides the value in A by the value in B, storing the quotient in A and remainder
in B.
o Example: If A = 08H and B = 02H, DIV AB results in A = 04H (quotient), B =
00H (remainder).
5. Increment/Decrement:
o Increment: INC A (Adds 1 to the value in the accumulator).
o Decrement: DEC A (Subtracts 1 from the value in the accumulator).
Q2: Discuss the pin diagram of 8051 microcontroller.
Ans2:
The 8051 microcontroller has 40 pins with specific functions:
1. Ports:
o Port 0 (Pins 32-39): Serves as both a general-purpose I/O port and the lower-order
address/data bus.
o Port 1 (Pins 1-8): Used only as general-purpose I/O pins.
o Port 2 (Pins 21-28): Serves as the higher-order address bus when accessing
external memory.
o Port 3 (Pins 10-17): Used for special functions like serial communication and
external interrupts.
2. Control Pins:
o Reset (Pin 9): Resets the microcontroller.
o ALE (Pin 30): Used to latch the lower-order address during external memory
access.
o PSEN (Pin 29): Program store enable, used to access external program memory.
o EA (Pin 31): External access enable; determines whether internal or external
memory is used.
3. Power Pins:
o VCC (Pin 40): Power supply (5V).
o GND (Pin 20): Ground.
4. Oscillator Pins:
o XTAL1 and XTAL2 (Pins 18 and 19): For connecting the external crystal
oscillator to set the clock frequency.

Q3: Discuss the I/O devices in embedded systems.


Ans3:
Input/output devices in embedded systems are essential for interaction with the environment.
1. Input Devices:
o Sensors: Measure physical parameters like temperature, light, pressure (e.g.,
LM35, LDR).
o Keypads: Allow manual data entry.
2. Output Devices:
o Actuators: Convert electrical signals into physical movement (e.g., motors,
solenoids).
o Displays: Visual output devices like LEDs, LCDs, and seven-segment displays.
3. Communication Devices:
o Used for interfacing with other systems.
o Examples: UART (serial communication), I2C, SPI.
Q4: Discuss the various issues in Embedded System Design.
Ans4:
1. Power Management:
• Ensuring efficient energy use, especially for battery-operated devices.
2. Real-Time Processing:
• Completing tasks within strict time limits.
3. Cost Constraints:
• Balancing performance with affordability.
4. Memory Limitations:
• Optimizing the use of limited RAM and ROM.
5. Reliability:
• Ensuring the system works in extreme environmental conditions.
6. Hardware-Software Integration:
• Achieving smooth communication between hardware and software components.

Q5: Discuss Real Time Clock.


Ans5:
A Real Time Clock (RTC) is a specialized clock module used in embedded systems.
• Purpose:
o Keeps track of time and date even when the system is powered off.
• Working:
o Powered by an external battery.
o Uses crystal oscillators for high-precision timekeeping.
• Applications:
o Digital clocks, time-stamping in data loggers, and scheduling tasks.

Q6: Explain the interrupts available in microcontroller 8051.


Ans6:
1. Types of Interrupts:
• External Interrupts (INT0 and INT1):
o Triggered by external events, mapped to pins P3.2 and P3.3.
• Timer Interrupts:
o Generated when Timer 0 or Timer 1 overflows.
• Serial Communication Interrupt:
o Triggered when data is transmitted or received.
2. Interrupt Priority:
• Two priority levels (high and low).
3. Interrupt Vector Table:
• Specifies the memory location for each interrupt service routine.
Q7: Discuss the role of the processor in embedded systems.
Ans7:
• Executes instructions to control the system.
• Manages communication between devices.
• Handles real-time operations.
• Examples:

• ARM Cortex-M processors for real-time applications.


• AVR processors for small-scale embedded devices.
Q8: Discuss the role of buses in serial and parallel communication between networked multiple
devices.
Ans8:
A bus is a communication pathway used for data transfer between components or devices. In
embedded systems, buses are critical for enabling communication between a microcontroller,
memory, and peripherals.
Serial Communication Bus
• Definition: Data is transmitted one bit at a time over a single wire or pair of wires.
• Example Buses: UART, I2C, SPI, and USB.
• Characteristics:
o Uses fewer wires (often just 2 or 3).
o Easier to implement and cost-effective for long-distance communication.
o Slower compared to parallel buses because bits are transmitted sequentially.
• Role in Embedded Systems:
o Useful in compact systems where space and wiring must be minimized.
o Suitable for connecting devices like sensors, displays, and memory modules.
Parallel Communication Bus
• Definition: Data is transmitted several bits at a time over multiple wire.
• Example Buses: Address/Data bus, PCI, and Parallel Ports.
• Characteristics:
o Requires multiple wires, which increases complexity and cost.
o Faster data transfer since multiple bits are transmitted simultaneously.
o Typically used over short distances (e.g., within a microcontroller or a computer).
• Role in Embedded Systems:
o Used where high-speed communication is critical, such as between a CPU and
memory.
o Ideal for applications requiring high data bandwidth.
Q9: Differentiate serial and parallel communication.
Ans9:
Serial Communication
• Data is transferred one bit at a time over a single wire or channel.
• Uses protocols like UART, SPI, and I2C.
• Advantages:
o Requires fewer wires, reducing complexity and cost.
o Suitable for long-distance communication.
• Disadvantages:
o Slower than parallel communication.
o Requires synchronization to ensure accurate data transfer.
Parallel Communication
• Data is transferred several bits at once, typically using one wire per bit.
• Commonly used in buses like PCI and between the CPU and RAM.
• Advantages:
o Much faster than serial communication because multiple bits are transferred
simultaneously.
o High throughput is ideal for tasks like memory access.
• Disadvantages:
o Requires more wires, increasing complexity and cost.
o Unsuitable for long-distance communication due to signal degradation and skew.
Q10: Discuss the steps to transfer data serially.
Ans10:
Serial data transfer involves transmitting one bit of data at a time over a single communication
line. Here's a step-by-step explanation:
1. Initialize the Serial Port:
o Configure the serial communication settings (e.g., baud rate, data bits, parity, and
stop bits).
o In the 8051 microcontrollers, this is done by setting the Serial Control Register
(SCON).
2. Set the Baud Rate:
o Define the speed of communication using a timer (e.g., Timer 1 in 8051).
3. Load Data to the Transmit Buffer:
o Place the data to be transmitted into the Serial Data Buffer (SBUF).
4. Enable Transmission:
o Start the transmission by enabling the serial port.
5. Monitor the Transmission:
o Check the Transmit Interrupt Flag (TI) to confirm the data has been sent.
6. Acknowledge Reception (if applicable):
o If using bidirectional communication, ensure the receiver sends an
acknowledgment.

Q11: Steps to send and receive data serially.


Ans11:
Steps to Send Data:
1. Initialize the Serial Communication Module:
o Set up the serial mode and baud rate using the control registers.
o For 8051, set the SCON register to the desired mode (e.g., Mode 1 for 8-bit
UART communication).
2. Load Data:
o Place the data byte to be transmitted in the SBUF register.
3. Enable Transmission:
o Activate the serial transmission control bit.
4. Monitor Transmit Completion:
o Wait for the TI (Transmit Interrupt) flag to indicate that the transmission is
complete.
5. Repeat for Additional Bytes:
o Clear the TI flag and load the next byte of data.
Steps to Receive Data:
1. Enable Serial Reception:
o Set the receiver enable bit in the serial control register.
2. Wait for Data:
o Monitor the RI (Receive Interrupt) flag to know when a byte has been received.
3. Read Received Data:
o Read the received byte from the SBUF register.
4. Clear the RI Flag:
o Clear the flag to prepare for receiving the next byte.
Q12: What is the function of subroutine?
Ans12:
Definition:
A subroutine is a small section of code designed to perform a specific task within a program. It
can be called multiple times from different parts of the program, improving modularity and
reducing redundancy.
Functions:
1. Reusability:
o Subroutines allow the same code block to be used multiple times, saving memory
and reducing the size of the program.
2. Modularity:
o Programs can be broken into smaller, manageable parts, making them easier to
understand and maintain.
3. Easier Debugging:
o Errors are easier to isolate in smaller blocks of code.
4. Improved Efficiency:
o Reduces code duplication, saving memory and improving execution efficiency.
Structure in Assembly (8051 Example):
1. Main Program:
MOV A, #5 ; Load value into accumulator
CALL ADDITION ; Call subroutine to perform addition
END
2. Subroutine:

ADDITION:
ADD A, #10 ; Add 10 to the value in A
RET ; Return to the main program

Applications of Subroutines:
• Performing mathematical operations (e.g., addition, multiplication).
• Handling repetitive tasks like displaying data or managing sensors.
• Managing I/O device communication.

You might also like