CS684: Embedded System Course
Lab 1: Bar-graph LEDs and Interrupt Switch Interfacing
LEARNING RESOURCES
This lab requires understanding of I/O interfacing with AVR microcontroller and basic knowledge about Masking. Refer the Resources file.
AIM
In this lab, you will interface the Bar-graph LEDs and the Interrupt Switch to ATmega2560. The aim of this lab is to get you familiar with the configuring and interfacing of Input and Output devices.
Your task is to toggle the status of 2 Bar-graph LEDs depending on whether the Interrupt Switch is pressed or released.
The program is provided as Eclipse project. But, the program contains few incomplete functions which you would have to complete as per the instructions present in the comments.
CONNECTIONS
-
Interrupt Switch : PD2
-
Bar-graph LED:
- LED 2 --> PB1
- LED 6 --> PB5
- LED 8 --> PB0
PROCEDURE
Step-1: Download lab1_sw_led zip folder. Right-click on the hyperlinks and select Save Link As... option to download. Extract the zip file. Start Eclipse, click on File > Open Projects From File System > Directory and browse for lab1_sw_led folder to open the project.
Step-2: In src/eBot_Sandbox.cpp, complete the toggle_leds_on_sw_press function to achieve the following:
- Check whether the Interrupt Switch is pressed or not.
- If the Interrupt Switch is pressed, only the 2nd LED will turn OFF and the 8th LED will turn ON.
- If the Interrupt Switch is not pressed, the 2nd LED will remain ON and only 8th LED will turn OFF.
Note: While completing, you have to use following functions defined in eBot_MCU_Predef.h header file:
- bool interrupt_switch_pressed (void);
- void turn_on_bar_graph_led (unsigned char);
- void turn_off_bar_graph_led (unsigned char);
Step-3: You will notice some pre-written function stubs in src/eBot_MCU_Predef.c included for your assistance related to Bar-graph LEDs and Interrupt Switch. Complete the pre-written functions with the help of comments provided.
Step-4: In the Package Explorer (left pane), right click on lab1_sw_led folder and select Show in Local Terminal --> Terminal(bottom pane). Type the following command in the terminal:
avr_hex_file_generator -cpp src/lab1_sw_led_main -dcpp src/eBot_Sandbox -dc src/eBot_MCU_Predef -m atmega328p
If there are no errors present in your program, the project will get compiled correctly and you will get the message as shown below, Also, build folder will be generated in project directory that will contain lab1_sw_led_main.hex file along with other build files.

Step-5: Load the hex file on the SimulIDE circuit (AVR_simulator.simu) once your program gets build successfully. Save the project. Ensure that code performs as expected. NOTE: Getting Build succeeded output doesn't mean that your program will give the expected output as it can contain logical errrors.
MACROS to use
- In the skeleton code eBot_MCU_Predef.c we have included a header file named, eBot_MCU_Predef.h which consists of the declaration of the following constants (for atmega328p controller):
//For Interrupt Switch:
#define interrupt_sw_ddr_reg DDRD
#define interrupt_sw_port_reg PORTD
#define interrupt_sw_pin 2 // PD2
//For Bar-graph LED:
#define bar_graph_led_ddr_reg DDRB
#define bar_graph_led_port_reg PORTB
#define bar_graph_led_2_pin 1 // PB1
#define bar_graph_led_8_pin 0 // PB0
#define bar_graph_led_6_pin 5 // PB5
- You have to use these constants declared in eBot_MCU_Predef.h and the Masking Operators to complete the lab.
Simulation: EXPECTED OUTPUT
Software required: SimulIDE AppImage (refer Installation_Instructions provided to you)