0% found this document useful (0 votes)
1 views3 pages

Experiment 1

The document outlines an experiment to familiarize users with the I/O ports of the Atmega 2560 microcontroller by interfacing a Bar graph LED. The task involves writing a program to turn on eight LEDs connected to Port J sequentially with a delay, keeping them on for a specified duration, and then turning them off before repeating the cycle. The procedure includes initializing the port, writing the main function, and debugging the code on a robot to ensure it functions as intended.

Uploaded by

amul.kumar28111
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)
1 views3 pages

Experiment 1

The document outlines an experiment to familiarize users with the I/O ports of the Atmega 2560 microcontroller by interfacing a Bar graph LED. The task involves writing a program to turn on eight LEDs connected to Port J sequentially with a delay, keeping them on for a specified duration, and then turning them off before repeating the cycle. The procedure includes initializing the port, writing the main function, and debugging the code on a robot to ensure it functions as intended.

Uploaded by

amul.kumar28111
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/ 3

Experiment 1 |Task 2|: Getting Familiar with I/O port operation – Bar graph LED

The aim of this experiment is to get you familiar with I/O Ports of Atmega 2560
microcontroller, when a pin is used as an output. In this experiment, you will interface an output
device (Bar graph LED) to the microcontroller. Bar graph LED comprises of 10 LEDs included
in a single module and is connected to Port J of Atmega 2560 microcontroller.
Your task is to selectively turn ON each LED one by one from a set of eight LEDs connected
to Port J.
Initially all the eight LEDs will be off. Then each LED has to be serially turned ON after a
delay of 500 milliseconds. Once turned ON, the LED will remain ON. After all the eight LEDs
have been serially turned ON, they remain ON for 500 milliseconds and then, turn OFF all the
LEDs for 500 milliseconds. After this, the pattern repeats itself.
Procedure:
Step 1: Write program code to complete the following functions. Refer to the function
description written below each one.
1. port_init()
• Initialize Port J as output port using DDRJ register.
• At the start, keep all the LEDs OFF. Use PORTJ register to turn OFF all 8 LEDs.
2. main()
Call functions defined before and write a code to do the following:
1. Initially all the eight LEDs remain OFF.
2. Turn ON each LED after a delay of 500 millisecond one by one starting from LSB
pin of Port J.
3. After all the eight LEDs have been serially turned ON, they remain ON for 500
milliseconds and then, turn OFF all the LEDs for 500 milliseconds. After this, the
pattern repeats itself.

Step 2: Check and debug your code on the robot. Save the project. Ensure that code performs
as expected.
/*
* Filename: Experiment-1 Task 2
* Description: This experiment is a part of Task 2. It is aimed at getting you familiar with I/O
interfacing by writing a code to sense pressing of a push button switch.
* * Functions: main(),port_init()
*/

// Note : You may write more functions depending on requirement.

#define F_CPU 14745600


#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

void LED_bargraph_config (void)


{
DDRJ = 0xFF; //PORT J is configured as output
PORTJ = 0x00; //Output is set to 0
}

void buzzer_on (void)


{
unsigned char port_restore = 0;
port_restore = PINC;
port_restore = port_restore | 0x08;
PORTC = port_restore;
}

void buzzer_off (void)


{
unsigned char port_restore = 0;
port_restore = PINC;
port_restore = port_restore & 0xF7;
PORTC = port_restore;
}

void init_devices (void)


{
cli(); //Clears the global interrupts
port_init();
sei(); //Enables the global interrupts
}

void port_init(void)
{
DDRC = DDRC | 0x08; //Make Port C pin 3 as output
PORTC = PORTC & 0xF7; //Keep buzzer off in initial state
DDRE = DDRE & 0x7F; //Make Port E pin 7 as input pin.
PORTE = PORTE | 0x80; // set appropriate value to activate pull up for Port E pin
7
LED_bargraph_config();
}

You might also like