0% found this document useful (0 votes)
19 views5 pages

Atmega 32 Timer LED Control Lab

1) The document describes an MPI lab assignment to learn about timers on the Atmega 32 processor. The objectives are to learn Proteus, the Atmega 32, Atmel Studio, and timers. 2) The task is to make an LED connected to port B pin 4 toggle using Timer 4 with a 1 second delay. The solution uses Timer 0 to count to 100 increments and toggle the LED every 20,000 iterations. 3) The second task is to make the same LED toggle with an 8 microsecond delay using Timer 0 configured for a clock rate of 8MHz. The solution uses Timer 0 to count to 100 and toggle the LED every 625 iterations.

Uploaded by

Burhan Ahmed
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)
19 views5 pages

Atmega 32 Timer LED Control Lab

1) The document describes an MPI lab assignment to learn about timers on the Atmega 32 processor. The objectives are to learn Proteus, the Atmega 32, Atmel Studio, and timers. 2) The task is to make an LED connected to port B pin 4 toggle using Timer 4 with a 1 second delay. The solution uses Timer 0 to count to 100 increments and toggle the LED every 20,000 iterations. 3) The second task is to make the same LED toggle with an 8 microsecond delay using Timer 0 configured for a clock rate of 8MHz. The solution uses Timer 0 to count to 100 and toggle the LED every 625 iterations.

Uploaded by

Burhan Ahmed
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

MPI LAB

LAB 4
Handling Timers on Atmega 32

Name : Burhan Ahmed Satti


Enrollment No. : 01-134172-065
Class : BSCS 4-A
Subject : MPI Lab
Lab Assistant : Muhammad Atif

Objectives
•Learning basics of Proteus
•Introduction to Atmega 32 processor
•Learning basics of Atmel studio
•Learning Timers of atmega 32 processor

Tools Used
•Proteus 8.0
•Atmel Studio 7.0
BSCS 4-A Burhan Ahmed Satti 01-134172-065

Task No. 4.1


Using Timer 4, make the LED connected at 4th bit of port B toggle.
Solution
/**
* \file
*
* \brief Empty user application template
*
*/

/**
* \mainpage User Application template doxygen documentation
*
* \par Empty user application template
*
* Bare minimum empty user application template
*
* \par Content
*
* -# Include the ASF header files (through asf.h)
* -# "Insert system clock initialization code here" comment
* -# Minimal main function that starts with a call to board_init()
* -# "Insert application code here" comment
*
*/

/*
* Include header files for all drivers that have been imported from
* Atmel Software Framework (ASF).
*/
/*
* Support and FAQ: visit <a href="[Link] Support</a>
*/
#include <asf.h>

int main (void)


{
/* Insert system clock initialization code here (sysclk_init()). */

board_init();

DDRB = 1<<4;
PORTB = 0x00;
TCCR0 = 1<<CS00;
int IterationCounter =0;

while (1)
{
if(TCNT0 > 100)
{
IterationCounter++;
if(IterationCounter >20000)
{
IterationCounter = 0;
PORTB ^= 0xFF;
}
}
}

/* Insert application code here, after the board has been initialized. */

HCI Lab Page 2 of 5


BSCS 4-A Burhan Ahmed Satti 01-134172-065

Result

Conclusion
The LED toggles every second.

HCI Lab Page 3 of 5


BSCS 4-A Burhan Ahmed Satti 01-134172-065

Task No. 4.2


Make the same LED toggle using 8 micro seconds delay.
Solution
/**
* \file
*
* \brief Empty user application template
*
*/

/**
* \mainpage User Application template doxygen documentation
*
* \par Empty user application template
*
* Bare minimum empty user application template
*
* \par Content
*
* -# Include the ASF header files (through asf.h)
* -# "Insert system clock initialization code here" comment
* -# Minimal main function that starts with a call to board_init()
* -# "Insert application code here" comment
*
*/

/*
* Include header files for all drivers that have been imported from
* Atmel Software Framework (ASF).
*/
/*
* Support and FAQ: visit <a href="[Link] Support</a>
*/
#include <asf.h>

int main (void)


{
/* Insert system clock initialization code here (sysclk_init()). */

board_init();

DDRB = 1<<4;
PORTB = 0x00;
TCCR0 = 1<<CS01;
int IterationCounter =0;

while (1)
{
if(TCNT0 > 100)
{
IterationCounter++;
if(IterationCounter > 625)
{
IterationCounter = 0;
PORTB ^= 0x10;
TCNT0 = 0;
}
}
}

/* Insert application code here, after the board has been initialized. */
}

HCI Lab Page 4 of 5


BSCS 4-A Burhan Ahmed Satti 01-134172-065

Result

Conclusion
LED is toggling successfully.

HCI Lab Page 5 of 5

You might also like