0% found this document useful (0 votes)
10 views

MTE 3104 LAB 01

This lab report details an experiment on sequential LED blinking using the Atmega32 microcontroller and Proteus simulation, aimed at understanding AVR programming and circuit simulation. The experiment involves coding in Atmel Studio to create a unique LED pattern by manipulating port outputs and utilizing modular arithmetic. The results demonstrate effective control of LEDs, providing a practical application for embedded systems education.

Uploaded by

M.I. Aman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

MTE 3104 LAB 01

This lab report details an experiment on sequential LED blinking using the Atmega32 microcontroller and Proteus simulation, aimed at understanding AVR programming and circuit simulation. The experiment involves coding in Atmel Studio to create a unique LED pattern by manipulating port outputs and utilizing modular arithmetic. The results demonstrate effective control of LEDs, providing a practical application for embedded systems education.

Uploaded by

M.I. Aman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Heaven’s light is our guide

RAJSHAHI UNIVERSITY OF ENGINEERING &


TECHNOLOGY Department of Mechatronics Engineering

Lab Report
Course No.: MTE 3104
Course Title: Microcontroller and Interfacing Sessional

Experiment No.: 01
Experiment Name: Sequential LED Blinking using Atmega32 with Proteus Simulation

Submitted By: Submitted To:


Md. Mawdud-E-Alam Md Zunaid Hossen
Roll No.: 2108047 Lecturer,
Department of Mechatronics Engineering Department of Mechatronics Engineering,
Rajshahi University of Engineering &
Technology

Md. Sakib Hassan Chowdhury


Lecturer,
Department of Mechatronics Engineering
Rajshahi University of Engineering &
Technology, Rajshahi-6204.

Date of Experiment: February 25, 2025


Date of Submission: April 15, 2025
Experiment No: 01
Experiment Name: Sequential LED Blinking using Atmega32 with Proteus Simulation
Objectives:
1. To understand the basics of AVR microcontroller programming.
2. To implement LED blinking using Atmega32 microcontroller.
3. To simulate the circuit using Proteus software.

Theory:

AVR microcontrollers, originally developed by Atmel and now under Microchip Technology,
are a family of 8-bit microcontrollers recognized for their RISC (Reduced Instruction Set
Computer) architecture. This architecture delivers high performance while maintaining low
power consumption, making AVR microcontrollers a popular choice in embedded systems. They
are appreciated for their flexibility and user-friendliness and come equipped with a wide range of
built-in peripherals such as timers, UART, SPI, and ADC. Programming these microcontrollers
is typically done using C or assembly language, and the code is uploaded to the flash memory of
the device. The ATmega32, part of the AVR microcontroller family, is an 8-bit microcontroller
developed by Atmel (now Microchip Technology). It features a powerful RISC-based CPU with
32 general-purpose registers and an efficient instruction set, enabling fast and effective
instruction execution. In terms of memory, the ATmega32 offers 32KB of in-system
programmable flash memory for code storage, 2KB of SRAM for runtime data, and 1KB of
EEPROM for non-volatile data storage—providing sufficient resources for a broad range of

applications.

Figure 1: ATMEGA32 Microcontroller with Pin Diagram

Designed with energy efficiency in mind, the ATmega32 supports several power-saving modes
and has advanced clock management, making it ideal for battery-operated devices. It operates
within a wide voltage range of 1.8V to 5.5V, offering flexibility for different power supply
setups. Additionally, it is available in multiple package types like PDIP, TQFP, and MLF,
accommodating various design and integration needs.

Required Software:
 Atmel Studio 7
 Proteus 8
Code (Atmel Studio 7):
#include <avr/io.h>
#include <util/delay.h>
#define F_CPU 8000000

int main(void)
{
int i = 0;
DDRC = 0xFF;
DDRD = 0xFF;

while (1)
{
for (int count = 0; count < 8; count++)
{

PORTC = (1 << i);


PORTD = (1 << i);
i = (i + 3) % 8;
_delay_ms(1000);
}
}
}

Code Explanation:
This code lights up one LED at a time skipping each 2 following LEDs on both PORTC and
PORTD of an AVR microcontroller in a repeating. It turns on LEDs in the sequence by skipping
2 LEDs in between, meaning every 3 rd LED with a 1-second delay between each. The pattern
continuously loops, creating a jumping LED effect across the ports.
 The code begins by including necessary AVR libraries for I/O operations and delay
functionality.
 It defines the CPU frequency as 8 MHz, which is required for accurate timing with
_delay_ms().
 Inside the main function, an integer variable i is initialized to 0 to track the LED position.
 Both PORTC and PORTD are configured as output ports by writing 0xFF to their DDR
registers.
 An infinite while loop ensures that the LED pattern runs continuously without stopping.
 Within the loop, a for loop runs 8 times to cover all 8 possible LED positions.
 In each iteration, a single bit is set high on PORTC and PORTD using (1 << i), lighting
one LED.
 i = (i + 3) % 8; This line updates the value of i by adding 3 to its current value, then
taking the modulo 8 of the result. The % 8 ensures the value of i stays within the range 0
to 7, which matches the 8 bits of the port. Once i reaches or exceeds 8, the modulo
operation wraps it back to the beginning of the 0–7 range.
Example:
If i = 0:
→ i = (0 + 3) % 8 = 3
Then:
→ i = (3 + 3) % 8 = 6
→ i = (6 + 3) % 8 = 1
→ i = (1 + 3) % 8 = 4
→ and so on: 0 → 3 → 6 → 1 → 4 → 7 → 2 → 5 → 0
This creates a cyclic "skip-3" pattern across the 8 LEDs. This stepping method creates
a unique LED pattern that appears to jump across positions non-linearly.
 A 1-second delay is added after each step using _delay_ms(1000) for visual clarity.
Circuit Diagram:

D1

LED-BIBY

D2

LED-BIBY
D3

LED-BIBY
D4

LED-BIBY
D5

LED-BIBY
U1 D6
9 22
RESET PC0/SCL
23
PC1/SDA
13 24 LED-BIBY
XTAL1 PC2/TCK
12 25
XTAL2 PC3/TMS
26 D7
PC4/TDO
40 27
PA0/ADC0 PC5/TDI
39 28
PA1/ADC1 PC6/TOSC1
38 29 LED-BIBY
PA2/ADC2 PC7/TOSC2
37
36
PA3/ADC3
14 D8
PA4/ADC4 PD0/RXD
35 15
PA5/ADC5 PD1/TXD
34 16
PA6/ADC6 PD2/INT0
33 17 LED-BIBY
PA7/ADC7 PD3/INT1
18
1
PD4/OC1B
19 D9
PB0/T0/XCK PD5/OC1A
2 20
PB1/T1 PD6/ICP1
3 21
PB2/AIN0/INT2 PD7/OC2
4 LED-BIBY
PB3/AIN1/OC0
5
6
PB4/SS D10
PB5/MOSI
7 32
PB6/MISO AREF
8 30
PB7/SCK AVCC
LED-BIBY
ATMEGA32 D11

LED-BIBY
D12

LED-BIBY
D13

LED-BIBY
D14

LED-BIBY
D15

LED-BIBY
D16

LED-BIBY
Figure 2: Circuit Diagram for the blinking LEDs
Result:
D1

LED-BIBY

D2

LED-BIBY
D3

LED-BIBY
D4

LED-BIBY
D5

LED-BIBY
U1 D6
9 22
RESET PC0/SCL
23
PC1/SDA
13 24 LED-BIBY
XTAL1 PC2/TCK
12 25
XTAL2 PC3/TMS
26 D7
PC4/TDO
40 27
PA0/ADC0 PC5/TDI
39 28
PA1/ADC1 PC6/TOSC1
38 29 LED-BIBY
PA2/ADC2 PC7/TOSC2
37
36
PA3/ADC3
14 D8
PA4/ADC4 PD0/RXD
35 15
PA5/ADC5 PD1/TXD
34 16
PA6/ADC6 PD2/INT0
33 17 LED-BIBY
PA7/ADC7 PD3/INT1
18
1
PD4/OC1B
19 D9
PB0/T0/XCK PD5/OC1A
2 20
PB1/T1 PD6/ICP1
3 21
PB2/AIN0/INT2 PD7/OC2
4 LED-BIBY
PB3/AIN1/OC0
5
6
PB4/SS D10
PB5/MOSI
7 32
PB6/MISO AREF
8 30
PB7/SCK AVCC
LED-BIBY
ATMEGA32 D11

LED-BIBY
D12

LED-BIBY
D13

LED-BIBY
D14

LED-BIBY
D15

LED-BIBY
D16

LED-BIBY

Figure 2: LED Blinking Sequentially

This code creates a dynamic LED display on PORTC and PORTD of an AVR microcontroller,
where one LED lights up at a time in a specific, non-linear sequence. Starting from the first LED
(position 0), the active LED shifts by 3 positions in each step using the formula (i + 3) % 8,
resulting in the sequence: 0 → 3 → 6 → 1 → 4 → 7 → 2 → 5. This sequence then repeats
continuously. Each LED remains on for 1 second, providing a clear and noticeable delay that
enhances the visual effect. The result is a rotating, jumping LED pattern that can be used for
testing, visual signaling, or decorative effects in embedded systems.

Discussion:

The code demonstrates how to generate a custom LED pattern using bitwise operations and
modular arithmetic in AVR microcontrollers. By incrementing the LED position by 3 and using
modulo 8, it creates a non-sequential, cyclic pattern across 8 LEDs on PORTC and PORTD. This
approach is useful for understanding port manipulation, bit-shifting, and timing control. The
result is an eye-catching LED effect suitable for educational projects, debugging, or creative
embedded applications.

Conclusion:

In conclusion, this program effectively showcases the use of bitwise operations, modular
arithmetic, and port control to create a unique LED pattern on an AVR microcontroller. By
combining hardware manipulation with precise timing, it highlights key concepts in embedded
programming and demonstrates how simple logic can produce complex and visually engaging
output, making it a valuable learning example for beginners and enthusiasts alike.

References:
 ATmega32 Datasheet – Atmel/Microchip
 Proteus 8 User Manual – Labcenter Electronics
 AVR Libc Documentation: https://www.nongnu.org/avr-libc/
 Atmel Studio 7 Documentation – Microchip
 Embedded Systems by Raj Kamal (for microcontroller basics)

You might also like