MM Assignmemt 3
MM Assignmemt 3
MM Assignmemt 3
(ANSWERS)
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.
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:
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:
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;
return 0;
}
4|Page
a port (PORTA, PORTB, etc.) as inputs or outputs, essentially determining
how the controller interacts with external devices.
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|Page
don't translate into machine code that the processor executes but instead
provide information or perform actions to aid assembly.
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 ...
7|Page