Experiment 1
Experiment 1
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()
*/
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();
}