You are on page 1of 40

W5.

E5 8051 Keil – Hardware - Interrupt and LED

W5.E5 8051 Keil and Hardware –


Interrupt and LED

Course: BMHA204P – Microprocessors and Microcontrollers LAB


-Dr Richards Joe Stanislaus
Assistant Professor - SENSE
Email: richards.stanislaus@vit.ac.in
W5.E5 8051 Keil – Hardware - Interrupt and LED

Important NOTE
•TAKE NOTES IN RECORD (Can strike
also, no marks will be reduced)
•Enter your registration number and
Full Name next to
1) all the plots and
2) all the programs.
W5.E5 8051 Keil – Hardware - Interrupt and LED

LAB record instructions:


For the lab experiment,
• Write the Aim.
• Complete the Software/Hardware components used.
• Write the mnemonics / commands used and one line description
• Draw the Diagramatic representation of circuit connection / port
interfacing
• Write the special pins and components used and brief description
• Connect the inputs and outputs. write the same in the lab copy(inputs
and outputs section).
• Write the output as observed and displayed.
• Write a concluding statement for each program / sub-experiment.
• Submit the document’s hard copy on time by next week.
W5.E5 8051 Keil – Hardware - Interrupt and LED

Hardware interfacing
LEDs with Timers and
Interrupt of 8051
W5.E5 8051 Keil – Hardware - Interrupt and LED

Lab Task – 5.1


Write an 8051 assembly language program to toggle bit of P1.7
for every 1 second. Simultaneously, toggle bit of P1.6 such that
P1.6 and P1.7 are complement to each other. Connect two LEDs
at the pins P1.6 and P1.7 and verify the same. Assume the
crystal frequency as 11.0592 MHz.
W5.E5 8051 Keil – Hardware - Interrupt and LED
W5.E5 8051 Keil – Hardware - Interrupt and LED

P1.7

P1.6
G
G

P1.6
P1.7
W5.E5 8051 Keil – Hardware - Interrupt and LED

Lab Task - 5.1


Making TH and TL both zero means that the timer will count from
0000 to FFFF, and then roll over to raise the TF flag. As a result, it
goes through a total Of 65536 states. Therefore, we have delay =
(65536 - 0) × 1.085 us = 71.1065ms.
71.1065ms * X =1000ms

where X represents the number of times the whole range from 0000
to FFFF needs to be repeated to generated an overall delay of 1
second (1000 ms).

X = 1000/71.1065 = 14
W5.E5 8051 Keil – Hardware - Interrupt and LED

Lab Task 5.1: PROGRAM


ORG 0000H AGAIN: JNB TF1, AGAIN
MOV TMOD, #10H CLR TR1
MOV C,P1.7 CLR TF1
CPL C DJNZ R0, BACK
MOV P1.6,C SJMP REPEAT
REPEAT: MOV R0,#14
CPL P1.7
CPL P1.6
BACK: MOV TL1, #00H
MOV TH1, #00H
SETB TR1
W5.E5 8051 Keil – Hardware - Interrupt and LED
W5.E5 8051 Keil – Hardware - Interrupt and LED

Lab Task 5.1: Hardware Components


required
• 8051 microcontroller Kit
• Serial communication cable
• Flat Ribbon Connector Cable (FRC)
• Two LEDs
• Bread board
• Three wires (single strand)
W5.E5 8051 Keil – Hardware - Interrupt and LED

Connections for Port 1.6, 1.7 and Ground to


LEDs
Connect the Flat Ribbon Cable and
Pin
W5.E5 8051 Keil – Hardware - Interrupt and LED

Procedure to Connect Hardware


1. Ensure the serial cable(usart) is connected to USB of your
computer.
W5.E5 8051 Keil – Hardware - Interrupt and LED

Procedure to Connect Hardware


2. In start menu, type device manager
and expand the Ports(COM & LPT) option
3. Identify the USB Serial Port number
(Here it is COM10, it may vary in your
system)
4. If your computer displays COM15 or above,
disconnect the serial cable and reconnect
in another usb port. Then right click at
Ports section in device manager and
select Scan for Hardware changes.
Identify the COM port number.
Note: Port number is used while configuring Keil
W5.E5 8051 Keil – Hardware - Interrupt and LED

Procedure to Connect Hardware


5. Ensure the switch is in execute mode in the Kit.
W5.E5 8051 Keil – Hardware - Interrupt and LED

Procedure to Configure Software


6. Open Keil software, Create new project, Include the STARTUP.A51
file for interfacing the hardware.
7. Right click at Source group and add new item
and
save the .asm file.
8. Type the program
and save it.
W5.E5 8051 Keil – Hardware - Interrupt and LED

Procedure to Configure Software


9. Select Options for target next to Target 1.

10. In the Options window,


select Target tab
10.1 Set frequency as
11.0592 (MHz)
10.2 Check box the
Use Onchip ROM
10.3 Select Debug Tab
W5.E5 8051 Keil – Hardware - Interrupt and LED

Procedure to Configure Software


10.4 Select Output tab
Enter name of executable
Select Create HEX file checkbox
W5.E5 8051 Keil – Hardware - Interrupt and LED

Procedure to Configure Software


11. In Debug TAB
Select Use (Hardware)
Select Keil Monitor-51 Driver
Check box :
Load application at Startup
Select Settings
W5.E5 8051 Keil – Hardware - Interrupt and LED

Procedure to Configure Software


12. In the settings,
Port: select COM port
from step 4.
Baud rate: 9600 (preferred)
Click OK and
OK in Options for Target
window.
W5.E5 8051 Keil – Hardware - Interrupt and LED

Procedure to Configure Software


13. Save, Translate and Build in Keil software.
14. Click RESET button in hardware kit.
15. In Keil, go to Debug -> Start Debug session
16. In Debug mode, Debug -> Run
This uploads and runs the program from the KIT. Based on the
connections, the corresponding components will provide the output.

17. After verifying outputs -> Click RESET in KIT -> Stop Debug in
Keil -> Stop Debugging.
18. Remove file from source group and add new .asm file for next
program.
W5.E5 8051 Keil – Hardware - Interrupt and LED

Procedure to Configure Software


• Write your observations based on your experiment.
W5.E5 8051 Keil – Hardware - Interrupt and LED

Task 5.2: Keil software only.


• Write a timer interrupt program that continuously get 8-bit data from
P0 and sends it to P1 while simultaneously creating a square wave
of 200 μs period on pin P2.1. Use timer 0 to create the square wave.
Assume thatXTAL = 11.0592 MHz.
Complete this task in Keil Software only.
W5.E5 8051 Keil – Hardware - Interrupt and LED

Task 5.2 : Program


//Go to main main: MOV TMOD,#02H
ORG 0000h MOV P0,#0FFH
LJMP main MOV TH0,#155
MOV IE,#82H
// ISR for Timer 0 SETB TR0
ORG 000Bh Back: MOV A,P0
CPL P2.1 MOV P1,A
RETI SJMP Back
END
W5.E5 8051 Keil – Hardware - Interrupt and LED

Task 5.2 : Outputs


• Take screenshots as in Previous experiments (W8.E9)
W5.E5 8051 Keil – Hardware - Interrupt and LED

External Hardware Interrupt


The 8051 has two external hardware interrupts
• Pin 12 (P3.2) and pin 13 (P3.3) of the 8051, designated as INT0 and
INT1, are used as external hardware interrupts
• The interrupt vector table locations 0003H and 0013H are set aside
for INT0 and INT1
• There are two activation levels for the external hardware interrupts
• Level trigged
• Edge trigged
W5.E5 8051 Keil – Hardware - Interrupt and LED

External Hardware Interrupt


W5.E5 8051 Keil – Hardware - Interrupt and LED

Low-level signal
• In the level-triggered mode, INT0 and INT1 pins are normally high.
• If a low-level signal is applied to them, it triggers the interrupt.
• This is called a level-triggered or level activated interrupt and is the
default mode upon reset of the 8051.
• Pins P3.2 and P3.3 are used for normal I/O unless the INT0 and
INT1 bits in the IE register are enabled.
W5.E5 8051 Keil – Hardware - Interrupt and LED

Activation of External Interrupts


• To make INT0 and INT1 edge triggered interrupts, we must program
the bits of the TCON register.
• The TCON register holds, among other bits, the IT0 and IT1 flag
bits that determine level- or edge-triggered mode of the hardware
interrupt.
• IT0 and IT1 are bits D0 and D2 of the TCON register.
• They are also referred to as TCON.0 and TCON.2 since the TCON
register is bit addressable.
W5.E5 8051 Keil – Hardware - Interrupt and LED

TCON Register
W5.E5 8051 Keil – Hardware - Interrupt and LED

Task 5.3 : Hardware


Assume that the INT1 pin is connected to a switch that is normally
high. Whenever it goes low, it should turn on an LED. The LED is
connected to P1.3 and is normally off. As long as the switch is
pressed low, the LED should stay on. Simultaneously perform a
toggle operation in P1.5 with the delay of 500ms.

Note: INT1 pin is P3.3 and is a push button in left corner, along the
RESET push button in 8051 kit.
W5.E5 8051 Keil – Hardware - Interrupt and LED
W5.E5 8051 Keil – Hardware - Interrupt and LED
W5.E5 8051 Keil – Hardware - Interrupt and LED

P1.3 P1.5
P1.5 P1.3 G
W5.E5 8051 Keil – Hardware - Interrupt and LED
W5.E5 8051 Keil – Hardware - Interrupt and LED

Task 5.3: Program


ORG 0000H ORG 30H
LJMP main main: MOV IE,#10000100B
Here: SETB P1.5
//ISR for INT1 ACALL DELAY
ORG 0013H CLR P1.5
SETB P1.3 ACALL DELAY
MOV R3,#255 SJMP Here
Back: DJNZ R3, Back
CLR P1.3
RETI
W5.E5 8051 Keil – Hardware - Interrupt and LED

Task 5.3: Program (contd)


//Delay of 500ms DJNZ R2,HERE3
DELAY: MOV R2,#04H ;DECREMENT R2
;LOAD R2 WITH 07 HEX RET ;RETURN
HERE3: MOV R1,#0FFH END
;LOAD R1 WITH 0FF HEX

HERE2: MOV R0,#0FFH


;LOAD R2 WITH 0FF HEX

HERE1: DJNZ R0,HERE1


DECREMENT R0

DJNZ R1,HERE2
;DECREMENT R1
W5.E5 8051 Keil – Hardware - Interrupt and LED

Task 5.3: Hardware Connection


• Port 1.3 is 12th in FRC: Connect to a LED
• Port 1.5 is 10th in FRC: Connect to another LED
• Ground is 26th in FRC: Connect to ground
.
W5.E5 8051 Keil – Hardware - Interrupt and LED

Task 5.3: Points to observe while


verifying Output:
• Follow the procedure in task 10.1 for hardware interfacing.
1. On clicking RUN in debug mode, LED at P1.5 will toggle between ON
and OFF continuously at 500ms rate.
2. When INT1 (P3.3) push button is pressed(LOW) and held in LOW
position, the interrupt is enabled and is observed in P1.3 LED (which is on).
When Interrupt is LOW (interrupt enabled), the toggle LED at P1.5 will not
work.
3. When INT1 (P3.3) push button is released (HIGH), the interrupt is HIGH
(no interrupt) and is observed in P1.3 LED (which is now OFF).
When Interrupt is HIGH (no interrupt), the toggle LED at P1.5 will
continue to work.
W5.E5 8051 Keil – Hardware - Interrupt and LED

LAB record instructions:


For the lab experiment,
• Write the Aim.
• Complete the Software/Hardware components used.
• Write the mnemonics / commands used and one line description
• Draw the Diagramatic representation of circuit connection / port
interfacing
• Write the special pins and components used and brief description
• Connect the inputs and outputs. write the same in the lab copy(inputs
and outputs section).
• Write the output as observed and displayed. GET OUTPUT VERIFIED
• Write a concluding statement for each program / sub-experiment.
• Submit the document’s hard copy on time by next week.

You might also like