MM Assignmemt 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

MM - ASSIGNMENT-3

(ANSWERS)

1. Draw and explain internal architecture of AVR ATmega32


microcontroller.(7M)
The ATmega32 microcontroller utilizes a Harvard architecture,
separating program and data storage. Here's a breakdown of its internal
components and a typical block diagram:

Components:
 Central Processing Unit (CPU): This is the brain of the microcontroller,
responsible for executing instructions. It follows a Reduced Instruction Set
Computing (RISC) architecture for efficient operation.
 Memory:
o Program Flash: Stores the program code (32kB).
o Static Random-access Memory (SRAM): Holds temporary data during
program execution (2kB).
o Electrically Erasable Programmable Read-Only Memory (EEPROM):
Stores non-volatile data that can be electrically modified (1kB).
 Input/Output (I/O): Provides 32 programmable pins for interfacing with
external devices.
 Timers/Counters: Three timers for precise timing and counting operations
(one 16-bit and two 8-bit).
 Analog-to-Digital Converter (ADC): Converts analog signals from
sensors into digital values (8 channels, 10-bit resolution).
 Serial Communication Interfaces: USART for asynchronous serial
communication and SPI for synchronous communication.
 Clock System: Provides the timing signal for the microcontroller (internal
oscillator or external crystal).
Block Diagram:
1|Page
This block diagram represents the core functional blocks of the ATmega32.
Each block interacts with the CPU to perform specific tasks.

2. Explain PORTA functionality of ATMEGA32.(4M)


PORTA on the ATmega32 is an 8-bit bidirectional I/O (Input/Output) port.
This means it can be configured to either:

1. Input: Receive digital signals from external devices like sensors, buttons,
or switches. The voltage level on each pin (PA0 to PA7) determines the
input value (high or low).
2. Output: Drive external devices like LEDs, LCDs, or other digital circuits.
You can write digital values (0 or 1) to each pin to control the voltage level
output.
Common Applications of PORTA:
 Reading sensor data:

o Connect sensors (temperature, light, etc.) to PORTA pins.

o Read the voltage levels on the pins to determine sensor readings.

2|Page
 Controlling LEDs:
o Connect LEDs to PORTA pins with appropriate resistors.
o Write digital values (1 for high, 0 for low) to control the on/off state of the
LEDs.
 Interfacing with external devices:
o PORTA can be used for various communication protocols (SPI, I2C) to
interact with external devices like displays, memory chips, or
communication modules.
 User input:
o Connect buttons or switches to PORTA pins.
o Read the pin states to detect button presses or switch changes.
Control Registers:

PORTA functionality is controlled by two registers:

1. Data Direction Register (DDRA): This 8-bit register determines the


direction (input or output) of each pin on PORTA.
o Setting a bit in DDRA (e.g., DDRA |= (1 << PA0)) configures the

corresponding pin (PA0 in this example) as output.


o Clearing a bit in DDRA sets the corresponding pin as input.

2. PORTA Register: This 8-bit register is used to:


o Write data (output mode): Write digital values (0 or 1) to the PORTA

register to control the voltage level on each output pin.


o Read data (input mode): Read the digital values from the PORTA pins to

determine the state of connected devices.

By manipulating these registers in your program, you can define the


functionality of each pin on PORTA for your specific application in the
ATmega32.

3|Page
3. Write an AVR C program to convert packed BCD 0X29 to
ASCII and display the bytes on PORTB and PORTC(7M)
Here's the AVR C program to convert packed BCD 0x29 to ASCII and
display the bytes on PORTB and PORTC:
#include <avr/io.h>

int main(void)
{
unsigned char packed_bcd = 0x29; // Packed BCD value
unsigned char upper_nibble, lower_nibble;

// Set PORTB and PORTC as output


DDRB = 0xFF;
DDRC = 0xFF;

// Extract upper and lower nibbles


upper_nibble = (packed_bcd & 0xF0) >> 4;
lower_nibble = packed_bcd & 0x0F;

// Add offset (30) to convert BCD to ASCII for digits


upper_nibble += 0x30;
lower_nibble += 0x30;

// Display ASCII values on PORTB and PORTC


PORTB = lower_nibble;
PORTC = upper_nibble;

return 0;
}

4. What is the role of DDR register in inputting data for AVR


Controller?(4M)
The DDR (Data Direction Register) in AVR controllers doesn't directly
participate in inputting data. It plays a crucial role in configuring the pins of

4|Page
a port (PORTA, PORTB, etc.) as inputs or outputs, essentially determining
how the controller interacts with external devices.

Here's a breakdown of how DDR affects data input:

1. Input vs. Output: The DDR register is an 8-bit register, with each bit
corresponding to a pin on the port (e.g., DDRA for PORTA). Setting a bit to
1 in the DDR register marks the corresponding pin as an output.
Conversely, clearing a bit to 0 sets the corresponding pin as an input.
2. Input Mode (DDR bit = 0): When a pin is configured as input (DDR bit =
0), the AVR controller allows external devices to drive the voltage level on
that pin (high or low). The controller can then read the state of the pin using
the corresponding PORT register (e.g., PINA for PORTA).
3. External Control: In input mode, the external device connected to the pin
determines the voltage level. The controller doesn't actively control or
influence this voltage.
4. Reading Input Data: The controller reads the input data by accessing the
corresponding PORT register. The value in the PORT register reflects the
current voltage level on the pin set as input.

In summary, the DDR register acts as a switch that determines the data
flow direction for each pin. When a pin is configured as input (DDR bit = 0),
the controller can passively read the data (voltage level) driven by external
devices connected to that pin.

5. What is the role of assembler directive? Explain .SET and


.EQU assembler directives with example.(4M)
In assembly language programming, assembler directives are special
instructions that guide the assembler during the assembly process. They

5|Page
don't translate into machine code that the processor executes but instead
provide information or perform actions to aid assembly.

Here's a breakdown of the .EQU and .SET directives commonly used to


define constants:
1. .EQU Directive:
 Purpose: Assigns a fixed value (constant) to a symbol (label).
 Behavior:
o The symbol can be used throughout the program wherever the constant
value is needed.
o The value assigned cannot be changed later in the code. It acts like a
constant definition.
Example:
MESSAGE_START .EQU 0x100 ; Set constant for message starting address

loop:
; ... instructions using MESSAGE_START ...
In this example:
* MESSAGE_START is assigned the value 0x100.
* Anywhere MESSAGE_START is used, the assembler will substitute it with
0x100.
2. .SET Directive:
 Purpose: Similar to .EQU, it assigns a value to a symbol.
 Behavior:
o The symbol represents a value that can be changed later in the program
using another .SET directive.
o It offers more flexibility but can be less readable if overused.
Example:
loop_count .SET 10 ; Initialize loop counter

loop:
6|Page
; ... instructions using loop_count ...

loop_count .SET loop_count - 1 ; Decrement loop counter

; ... compare loop_count to zero for termination ...


Here:
* loop_count is initially set to 10.
* Inside the loop, it's reassigned the value of itself minus 1.
Key Differences:
Feature .EQU .SET
Modifiable No, acts like a constant Yes, value can be changed
Value definition later
Use Case When a fixed value is When a value might need
needed throughout adjustment during
the program program execution
Readability Generally considered Can be less readable if
more readable overused

7|Page

You might also like