Lab Report MES_05
Lab Report MES_05
Faculty of Engineering
Lab Report
Experiment 05
Experiment Title: Familiarization of assembly language program and Interrupts in
a microcontroller.
Date of Perform: 02 June 2024 Date of Submission: 09 June 2024
Course Title: Microprocessor and Embedded Systems Lab
Course Code: EE4103 Section: E
Semester: Fall 2024-25 Degree Program: BSc in CSE/EEE
Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan
Declaration and Statement of Authorship:
1. I/we hold a copy of this Assignment/Case Study, which can be produced if the original is lost/damaged.
2. This Assignment/Case Study is my/our original work; no part has been copied from any other student’s work or any other source except where
due acknowledgment is made.
3. No part of this Assignment/Case Study has been written for me/us by any other person except where such collaboration has been authorized.
by the concerned teacher and is acknowledged in the assignment.
4. I/we have not previously submitted or am submitting this work for any other course/unit.
5. This work may be reproduced, communicated, compared, and archived to detect plagiarism.
6. I/we permit a copy of my/our marked work to be retained by the Faculty Member for review by any internal/external examiners.
7. I/we understand that Plagiarism is the presentation of the work, idea, or creation of another person as though it is your own. It is a form of cheating and is a
very serious academic offense that may lead to expulsion from the University. Plagiarized material can be drawn from, and presented in, written, graphic, and
visual forms, including electronic data, and oral presentations. Plagiarism occurs when the origin of the source is not appropriately cited.
8. I/we also understand that enabling plagiarism is the act of assisting or allowing another person to plagiarize or copy my/our work.
* Student(s) must complete all details except the faculty use part.
** Please submit all assignments to your course teacher or the office of the concerned teacher.
Group # 04
Total Marks
Table of Contents
Objectives 3
Equipment List 3
Circuit Diagram 4
Experimental Output Results (Color Photographs) 7
Simulation Output Results (Color Photographs) 8
Answers to the Questions in the Lab Manual 9
Discussion 12
References 13
Objectives:
The objectives of this experiment are to To explore and implement the principles of assembly
language programming on an Arduino microcontroller, including circuit design and the use of digital
I/O ports, with a focus on controlling an LED through external interrupts.
Equipment List:
1) Arduino IDE (2.0.1 or any recent version)
2) Arduino Microcontroller board
3) PC having an Intel processor
4) LED lights (Red, Green, Yellow, 1 pc each)
5) One 100 resistor
6) Three push switches
7) Jumper wires
Circuit Diagram:
Figure 1: Experimental setup of an LED control system using an Arduino Microcontroller Board.
Part 01
The .ino file:
//-------------------------
// C Code for Blinking LED
//-------------------------
extern “C”
{
void start();
void led(byte);
}
//----------------------------------------------------
void setup()
{
start();
}
//----------------------------------------------------
void loop()
{
led(1);
led(0);
}
The .S file:
;---------------
; Assembly Code
;---------------
#define __SFR_OFFSET 0x00
#include “avr/io.h”
;------------------------
.global start
.global led
;------------------------
start:
SBI DDRB, 5; set PB5 (D13) as o/p
RET; return to setup() function
;---------------------------------------------------------------------------
led:
CPI R24, 0x00; value in R24 passed by caller compared with 0
BREQ ledOFF; jump (branch) if equal to subroutine ledOFF
SBI PORTB, 5; set D13 to HIGH, i.e., the LED will turn ON
RCALL myDelay; Calling a delay function to determine the ON duration of LED
RET; return to loop() function
;---------------------------------------------------------------------------
ledOFF:
CBI PORTB, 5; set D13 to LOW, i.e., the LED will turn OFF
RCALL myDelay; Calling a delay function to determine the OFF duration of LED
RET; return to loop() function
Part 02:
The btnLED.ino file:
//-----------------------------------
// C Code: RGB LED ON/OFF via Buttons
//-----------------------------------
extern "C"
{
void start();
void btnLED();
}
//-----------------------
void setup()
{
start();
}
//-----------------------
void loop()
{
btnLED();
}
The btnLED.S file:
;------------------------------------------
; Assembly Code: RGB LED ON/OFF via Buttons
;------------------------------------------
#define __SFR_OFFSET 0x00
#include "avr/io.h"
;------------------------
.global start
.global btnLED
;================================================================
start:
SBI DDRB, 4; set PB4 (pin D12 as o/p - red LED)
SBI DDRB, 3; set PB3 (pin D11 as o/p - green LED)
SBI DDRB, 2; set PB2 (pin D10 as o/p - blue LED)
CBI DDRD, 2; clear PD2 (pin D02 as i/p - red button)
CBI DDRD, 3; clear PD3 (pin D03 as i/p - green button)
CBI DDRD, 4; clear PD4 (pin D04 as i/p - blue button)
RET
btnLED:
L2: SBIS PIND, 4 ; Skips below statement if the push button of D04 is not pressed
RJMP L1
SBI PORTB, 2 ; Turn ON LED, PB2(D10), if SW of D04 is not pressed
CBI PORTB, 3 ; Turn OFF LED, PB3(D11), if SW of D04 is not pressed
SBIC PIND, 4 ; Skips below statement if the push button of D04 is pressed
RJMP L2
L1: CBI PORTB, 2 ; Turn OFF LED, PB2(D10), if SW of D04 is pressed
SBI PORTB, 3 ; Turn OFF LED, PB3(D11), if SW of D04 is pressed
RET
Part 03
The pbintLED.ino file:
const byte ledPin = 13;
const byte interruptPin = 2;
volatile byte state = LOW;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
}
void loop() {
digitalWrite(ledPin, state);
}
void blink() {
state = !state;
}
Part 03
The blinkLED.ino file:
bool LED_State = ‘True’;
void setup() {
pinMode(13, OUTPUT);
cli(); // stop interrupts till we make the settings
TCCR1A = 0; // Reset the entire A and B registers of Timer1 to make sure that
TCCR1B = 0; // we start with everything disabled.
TCCR1B = 0b00000100; // Set CS12 bit of TCCR1B to 1 to get a prescalar value of 256.
TIMSK1 = 0b00000010; // Set OCIE1A bit to 1 to enable compare match mode of A reg.
OCR1A = 31250; // We set the required timer count value in the compare register, A
sei(); // Enable back the interrupts
}
void loop() {
// put your main code here, to run repeatedly.
}
// With the settings above, this ISR will trigger each 500 ms.
ISR(TIMER1_COMPA_vect) {
TCNT1 = 0; // First, set the timer back to 0 so that it resets for the next interrupt
LED_State = !LED_State; // Invert the LED State
digitalWrite(13, LED_State); // Write this new state to the LED connected to pin D5
}
Simulation Output Results:
Figure 06: Output results of Part 02 (WITHOUT PRESSING THE SWITCH GREEN IS ON)
Figure 07: Output results of Part 03 (WHILE PRESSING THE SWITCH LED IS OFF)
Figure 07: Output results of Part 03 (WITHOUT PRESSING THE SWITCH LED IS ON)
Figure 08: Output results of Part 04 (WHILE PRESSING THE SWITCH LED IS OFF
Figure 08: Output results of Part 04 (WITHOUT PRESSING THE SWITCH LED IS ON)
Discussion:
Through this experiment, we gained practical knowledge of assembly language programming for
Arduino microcontrollers. We successfully developed code to control an LED and built circuits to test
its functionality. By integrating external interrupts, we deepened our understanding of Arduino's digital
I/O ports and their capabilities. This hands-on experience improved our skills in microcontroller
programming, circuit design, and debugging. Additionally, it enhanced our understanding of how
external interruptions can be used to create responsive systems, which is valuable for designing efficient
embedded systems. This experiment provided a solid foundation for advanced projects involving
assembly language and real-time control mechanisms.
References:
1) . Arduino Official Documentation: https://www.arduino.cc/reference/en/.com.
2) Assembly Language Programming for Arduino: https://learn.adafruit.com/.
3) https://www.arduino.cc/en/uploads/Main/arduino-uno-schematic.pdf
4) ATMega328 manual.