0% found this document useful (0 votes)
5 views13 pages

Mup Exp9

The document outlines Experiment 9 of a Microprocessor Lab, focusing on implementing interrupts and DIP switches control using Atmel AVR assembly language. It details the objectives, including generating hardware interrupts with a push button and creating an ISR to control an LED, as well as a second problem involving 4-bit addition using INT0. The document also includes code snippets, flowcharts, and explanations of key concepts related to interrupts and register transfers.

Uploaded by

ee23b062
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)
5 views13 pages

Mup Exp9

The document outlines Experiment 9 of a Microprocessor Lab, focusing on implementing interrupts and DIP switches control using Atmel AVR assembly language. It details the objectives, including generating hardware interrupts with a push button and creating an ISR to control an LED, as well as a second problem involving 4-bit addition using INT0. The document also includes code snippets, flowcharts, and explanations of key concepts related to interrupts and register transfers.

Uploaded by

ee23b062
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/ 13

MICROPROCESSOR LAB

EXPERIMENT 9

By EE22B084 (Aditi Vinchurkar) and EE22B085 (Ashwin Reddy)


Aim:

Using Atmel AVR assembly language programming, implement interrupts and DIP
switches control in Atmel Atmega microprocessor. Aims of this experiment are:

• Generate an external (logical) hardware interrupt using an emulation of a push button


switch.

• Write an ISR (Interrupt Service Routine) to switch ON an LED for a few seconds (10
secs) and then switch OFF. (The lighting of the LED could be veri ed by monitoring the
signal to switch it ON).

• If there is time, you could try this also: Use the 16 bit timer (via interrupt) to make an
LED blink with a duration of 1 second.

• Also, one needs to implement all of the above, in AVR assembly.

Drive link containing working video:

https://drive.google.com/ le/d/1DfnF7oReULrrIQ40uEdRdcmlM0AgP4RH/view?
usp=sharing
fi
fi
Problem 1: Implementing the Interrupt using INT1

You are given the le "EE2016F23Exp9int1.asm" which is an assembly program which

implements interrupt using INT1. Fill in the blanks in the assembly code.

Approach

We set the ISR for INT1 at the label int1_ISR by using the following command (Here, the ISR for
INT1 is set in the memory address 0x04):

.ORG 0x0004 ;

RJMP int1_ISR;

At the program origin, the program jumps to the label reset. Once we jump, the following steps
are executed:

• The memory address of RAMEND is stored to the Stack Pointer.

• PB1 is made as an output and all of PortD is made as input and take the input from PIND3,
enabling internal pull-up resistor.

• This is done by con guring the data direction DDR registers (By con guring DDRB and
DDRD)

• We then set ISC11 in the MCUCR to 1, to make the falling edge of an interrupt pin generate
an interrupt.

• We then enable the interrupt for INT1 in GICR, by using the ORI operation.

• All the interrupts are enabled using the SEI.

The program then waits at the label "inde niteloop", waiting for an interrupt, as seen in
the following code snippet:

inde niteloop:

RJMP inde niteloop


In the "int1_ISR" Routine, we make our LED blink 10 times . The duty cycle is followed
corresponding to the code.
fi
fi
fi
fi
fi
fi
Flowchart:
Code:
Questions From Code

Question: LDI R16, HIGH(RAMEND); Guess, why it is done ???


Answer: This is done in order to store the top 8 bits of the address of the end of data memory.

Question: ORI R16, 1<< ISC11; Why it is Ored?


Answer: It is Ored to not change the rest of the bits of R16, except the bit at the same position
as that of ICS11 in the MCUCR which is set to 1

Question: SEI; What does it do?


Answer: It sets the global interrupt enable in SREG Register as 1.

Question: inde niteloop: rjmp inde niteloop; Stay here. Expecting interrupt?
Answer:Yes, out program stays here, as it waits for an interrupt.

Question: What is the Duty Cycle and period of the LED Blinking?
Answer:The duty cycle is 50% while the LED blinking period is 390158 cycles, which is
equivalent to .39sec.
fi
fi
Explanations and ideas:

• Interrupts:
• Interrupts are a method used to serve a device using a microcontroller.
• Here, the device sends an interrupt signal to the microcontroller, upon which the
microcontroller pauses all other processes and serves the device.
• Interrupts are better than Polling, in which the microcontroller keeps monitoring the
output of a device in the fact that it doesn’t waste time monitoring all devices, and
makes the rest of the program wait only when a request is made.

• Interrupt Service Routine(ISR):


• The ISR is the Routine that is called when an interrupt is raised.
This routine is called only if Global Interrupt Enable is set using the SEI Command
• When an interrupt request occurs for INT1, the program goes to the memory address
0x04, the interrupt vector for the same

• Interrupt Vector:
• The Microcontroller checks in a memory address called Interrupt Vector, to nd the
memory address at which the ISR is stored.
• The Interrupt Vectors for INT0, INT1 and INT2 are memory addresses 0x02,0x04 and
0x06
• Whenever an Interrupt occurs, the program goes to these memory addresses and
searches for the memory address for the ISR.

Register transfers:

• Registers R16 and R17 are the only registers we have used in the program.

• The rst time we use R16 is to initialise the stack pointer. We rst load R16 with
0x00 and write this to SPH and then load 0x70 R16 and write to SPL.

• The second time we load R16 with 0x02, this is done to set PB1 as an output pin.

• The third time we use the register R16 is when we use it to make Port-D as
input.Here, R16 is loaded with 0x00 and this is written to DDRD. Then, R16 is
loaded with 0x08, and written to the DDRD to activate pull-up resistor in PD3.

• The fourth time, we load R16 with contents of MCUCR and then OR it with 0x08
and then write it back to MCUCR

• R16 is then loaded with GICR contents, OR’ed with 0x80 and written back to GICR

• R16 loaded with 0x0A and then copied to R0 to be used as counter for blinking

• R16 is loaded with 0xFF and written to POTD to switch on LED

• R16,R17 loaded with 0xFF and used as counters in delay loops.


fi
fi
fi
Problem-2: Implementing interrupt using INT0

Problem statement:
Perform 4-bit addition of two unsigned nibbles from an 8-bit dip input switch (set by TAs)
and display the result obtained in LEDs.

This code as well uses the same logic as the previous one, but the only di erence is that
this operates on INT0 and not INT1.
• The ISR for INT1 is set at the label int0_ISR by using the following command (ISR
for INT0 is set in the memory address 0x02):
.ORG 0x0002 ;
• RJMP int1_ISR;

• At the program origin, we make the program jump to the label reset. Here, the
following steps are carried out:
• Store the memory address of RAMEND to Stack Pointer.

• Make PB1 as output and make all of PortD as input and take the input from
PIND2, enabling internal pull-up resistor.

• Set ISC11 in MCUCR to 1, that is, make a falling edge of interrupt pin
generate an interrupt.

• Enable Interrupt for INT0 in GICR.

• Enable all interrupts using SEI.

• Our program waits at the label "inde niteloop", waiting for an interrupt as seen below:

inde niteloop: RJMP inde niteloop

• In the "int0_ISR" Routine, the LED is made to blink 10 times


fi
fi
fi
ff
Flowchart:
Inferences:
The register transfers are similar to problem 1, the owchart and approach has been
provided above.

Individual contribution:

• The work was evenly distributed between both members of the team (Aditi Vinchurkar
(EE22B084) and Ashwin Reddy (EE22B085) ,
• Both of us collaborated and performed the experiment, worked on the code, and
prepared the report together.

fl

You might also like