Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
107 views11 pages

Lab#11 Interrupt Handeling in At89C51: Objective

This document discusses using interrupts and timers in an 8051 microcontroller to generate a square wave and read/write ports. It includes 4 tasks: 1) generate a 100ms square wave on P2.1 using Timer0 while continuously reading P0 and writing to P1, 2) generate a 500us square wave on P2.1 using Timer1 while reading a 4-bit P0 and writing to P1, 3) turn on an LED connected to P1.3 when a switch connected to INT1 goes low and keep it on for a fraction of a second, 4) turn an LED on and off at the same rate as pulses on INT1 using its falling edge to trigger the LED. The learning

Uploaded by

Akira Mannahel
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)
107 views11 pages

Lab#11 Interrupt Handeling in At89C51: Objective

This document discusses using interrupts and timers in an 8051 microcontroller to generate a square wave and read/write ports. It includes 4 tasks: 1) generate a 100ms square wave on P2.1 using Timer0 while continuously reading P0 and writing to P1, 2) generate a 500us square wave on P2.1 using Timer1 while reading a 4-bit P0 and writing to P1, 3) turn on an LED connected to P1.3 when a switch connected to INT1 goes low and keep it on for a fraction of a second, 4) turn an LED on and off at the same rate as pulses on INT1 using its falling edge to trigger the LED. The learning

Uploaded by

Akira Mannahel
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/ 11

Lab#11

INTERRUPT HANDELING IN AT89C51


OBJECTIVE
1. Getting introduced to interrupt handling
2. Generating a square wave using timers and interrupts

DISCUSSION
The equipment we will use to simulate the lab is software based listed as follow

1. Keil u-vision
2. Proteus

Interrupts:

As the name implies, an interrupt is some event which interrupts normal program execution.

Setting up Interrupts

By default at powerup, all interrupts are disabled. This means that even if, for example, the TF0
bit is set, the 8051 will not execute the interrupt. The program must specifically tell the 8051 that
it wishes to enable interrupts and specifically which interrupts it wishes to enable.
Polling Sequence

The 8051 automatically evaluates whether an interrupt should occur after every instruction.
When checking for interrupt conditions, it checks them in the following order:

1. External 0 Interrupt
2. Timer 0 Interrupt
3. External 1 Interrupt
4. Timer 1 Interrupt
5. Serial Interrupt

External Hardware Interrupt Triggering (INT0&INT1)

Low-Level Triggered
Falling-Edge Triggered
TASKS
Task#01
Write an assembly program that continuously gets 8-bit data from P0 and send it to P1
while simultaneously creating a square wave of 100ms time-period on pin P2.1, Use Timer0
mode1 and Xtal=11.0592Mhz.

Program Code

org 00h

ljmp main

org 00bh

mov tl0,#00h

mov th0,#4ch

cpl p2.1

reti

org 0030h

main:

clr p2.1 ; set as output

mov p0,#0ffh ; set as input

mov IE,#82h ;External intrupt enable

mov tmod,#01h ;Timer mode 16-bit

mov tl0,#00h

mov th0,#4ch

setb tr0

repeat:

mov a,p0 ;reading from port 0

mov p1,a ;sending to port1

sjmp repeat
Proteus Circuit

Proteus Output
Task#02
Write an assembly program that continuously gets 4-bit data from P0 and send it to P
while simultaneously creating a square wave of 500µs time-period on pin P2.1, Use Timer1
mode2 (8-bit Auto-reload) and Xtal=11.0592Mhz.

Program Code
org 00h

ljmp main

org 0001bh

mov tl1,#1ah

mov th1,#00h

cpl p2.1

retI

org 0030h ;address of IE0

main:

mov p0,0ffh ;set as input

clr p2.1 ;set as output

mov IE,#88h ;enable IE

mov tmod,#20h ;Timmer mode 4-bit

mov tl1,#1ah

mov th1,#00h

setb tr1

repeat:

mov a,p0 ;readind frpm p0

mov p1,a ;sending to p1

sjmp repeat

ret

end
Proteus Circuit

Proteus Output
Task#03
Write an assembly program for a scenario in which, your controller’s pin3.3 (INT1) is
connected to a switch (Normally high). And LED is connected to P1.3(Normally off).
Whenever switch goes low, it should turn on LED, and When it is turned on it should stay
on for a fraction of a second. As long as the switch is pressed low, the LED should stay on.

Program Code
org 00h

ljmp main ;jump to main

org 0013h ;external IE0 interupt address

setb p1.3 ;on

mov r0,#220

label1:

djnz r0,label1

clr p1.3 ;off

reti

org 0030h ;external IE1 interupt address

main:

mov IE,#84h ;interrupt

repeat:

sjmp repeat

end
Proteus Circuit

Task#04
Assume that pin 3.3 (INT1) is connected to a pulse generator, write a program in which the
falling edge of the pulse will send a high to P1.3, which is connected to an LED. In other
words, the LED is turned on and off at the same rate as the pulses are applied to the INT1
pin.

Program Code

org 00h

ljmp main

org 0013h ;external interrupt IE0 address

setb p1.3 ;on


mov r0,220

delay: ;delay

djnz r1,delay

clr p1.3

mov r0,220

delay1: ;delay

djnz r0,delay1

reti

org 0030h ;external interrupt IE1 address

main:

setb TCON.3 ;setting for E1 as edge trigger

mov IE,#84h

rep: ;repeat again

sjmp rep

end
Learning Outcomes
In this lab we learned how to code interrupts in 8051 micro controller.By performing this lab
following learning outcomes were achieved

1. GOT introduced to interrupt handling


2. Learned the switching control of an LED through interrupts

You might also like