Microcontroller: 8051 Stack, I/O Port Interfacing and Programming
Microcontroller: 8051 Stack, I/O Port Interfacing and Programming
Microcontroller: 8051 Stack, I/O Port Interfacing and Programming
18EC46
Module 3:
8051 STACK, I/O PORT INTERFACING
AND PROGRAMMING
Dinesh M.A.
[email protected]
•
/dinesh.ajay
/prof.dineshma
VISION OF THE DEPARTMENT
Module 3:
8051 STACK, I/O PORT INTERFACING
AND PROGRAMMING
Dinesh M.A.
[email protected]
•
/dinesh.ajay
/prof.dineshma
Course Outcomes
CO’s DESCRIPTION OF THE OUTCOMES
• Loading the contents of the stack back into a CPU register is called a POP
• With every pop, the top byte of the stack is copied to the register specified by the
instruction and the stack pointer is decremented once
MOV SP, #5FH ;make RAM location 60H, first stack location
MOV R2, #25H
MOV R1, #12H
MOV R4, #0F3H
PUSH 2
PUSH 1
PUSH 4
Solution:
RETI
• Pops two bytes from the stack into the program counter(PC) and reset the
interrupt enable Flip-Flops
Note that
• The only difference between the RET and RETI instructions is the enabling of the interrupt
logic when RETI is used.
• RET is used at the ends of subroutines called by an opcode. RETI is used by subroutines
called by an interrupt.
Microcontroller 18EC46- DINESH M.A. 5/13/2020 23
I/O Port Interfacing and Programming
• The four 8-bit I/O ports P0, P1, P2 and P3 each uses 8 pins
• All the ports upon RESET are configured as input, ready to be used
as input ports
• When the first 0 is written to a port, it becomes an output
• To reconfigure it as an input, a 1 must be sent to the port
• To use any of these ports as an input port, it must be programmed
ORG 0
MOV A,#55H ; Load A with 55h
BACK: MOV P1,A ; Send 55h to port1
ACALL DELAY ; Call the subroutine DELAY
CPL A ; Complements A, so that A becomes AAh
SJMP BACK ; Keep doing this indefinitely
A switch is connected to pin P1.0 and an LED to pin P2.7. Write a program to get the status of
switch and send it the LED.
Solution: