Module - 3: 8051 Stack, I/O Port Interfacing and Programming
The document discusses the 8051 stack, I/O port interfacing and programming. It covers topics like the 8051 stack, stack instructions, subroutine instructions and examples. It also discusses interfacing a simple switch and LED to I/O ports to turn the LED on and off depending on the switch status. The document explains the stack pointer register, PUSH and POP instructions and provides examples. It also explains JUMP and CALL instructions for conditional and unconditional jumps to change the program flow. Subroutine CALL instructions like ACALL and LCALL are discussed along with the RET and RETI instructions.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100%(1)100% found this document useful (1 vote)
258 views51 pages
Module - 3: 8051 Stack, I/O Port Interfacing and Programming
The document discusses the 8051 stack, I/O port interfacing and programming. It covers topics like the 8051 stack, stack instructions, subroutine instructions and examples. It also discusses interfacing a simple switch and LED to I/O ports to turn the LED on and off depending on the switch status. The document explains the stack pointer register, PUSH and POP instructions and provides examples. It also explains JUMP and CALL instructions for conditional and unconditional jumps to change the program flow. Subroutine CALL instructions like ACALL and LCALL are discussed along with the RET and RETI instructions.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 51
Module -3
8051 Stack, I/O Port
Interfacing and Programming Topics to be covered • 8051 Stack • Stack instructions • Subroutine instructions. • Assembly language program examples on subroutine and involving loops. • Interfacing simple switch and LED to I/O ports to switch on/off LED with respect to switch status. 8051 Stack • The stack is a part of RAM used to store information temporarily. • The SP (stack pointer) register used to access the stack. • The SP is 8 bit wide by default it hold address 07h. • The storing of a CPU register in the stack is called a PUSH • Loading the contents of the stack back into a CPU register is called a POP • CALL instruction saves the address of the next instruction on the Stack memory. PUSH & POP instructions PUSH • SP will be incremented by 1 that it is going to point to 08h location • Content of registers will be dumped on stack memory • Ex- PUSH 0E0h--(“A” content will be dumped on stack) POP • Content of stack memory will be retrived on register • SP will be decremented by 1 that it is going to point to 07h location • Ex- POP 0E0h--(“A” content will be content of stack memory) Example for PUSH MOV R6, #25H MOV R1, #12H MOV R4, #0F3H PUSH 6 PUSH 1 PUSH 4 Example for POP JUMP & CALL instructions • JUMP & CALL changes the flow of program execution by changing PC.
JUMP instructions are of 2 types
1. Conditional Jump- Flow of execution changed with respect conditions 2. Unconditional Jump - Flow of execution changed without any conditions Conditional Jumps- (-128 to 127 byte range) 1.JB bit,addr- Jump if bit is high to specified address----- (3B,3C) No flags affected 2.JNB bit,addr- Jump if bit is not high to specified address-----(3B,3C) No flags affected 3.JBC bit,addr- Jump if bit is high to specified address & clear bit-----(3B,2C) 4.JC addr- Jump if carry is high to specified address ----- (2B,2C) 5.JNC addr- Jump if No carry to specified address ----- (2B,2C) 5.JZ addr- Jump if Accumulator content is zeo to specified address -----(2B,2C)—No flags affected 6.JNZ addr- Jump if Accumulator content is not zeo to specified address -----(2B,2C)—No flags affected 7.DJNZ byte, addr- Decrement byte if not zero Jump to specified address -----(2B,2C)—No flags affected 7.DJNZ direct, addr- Decrement the contents of direct address if not zero Jump to specified address -----(2B,2C)—No flags affected Compare & Jump Instruction 2.Unconditional Jump Jumps to specified address without any condition Different Unconditional jump Instructions 1. SJMP 8bit address 2. LJMP 16bit address 3. JMP @A+DPTR 1.SJMP 8bit address(Short Jump) • It is 2 byte instruction • First byte is the opcode • Second byte is the relative target address • 00 to FFH (forward +127 and backward-128 bytes from the current PC) SJMP next 2.LJMP 16bit address(Long Jump) • It is 3 byte instruction • First byte is the opcode • Next 2 bytes are the relative target address • 0000to FFFFH (within the range of 64K Bytes) 3.JMP @A+DPTR
By adding content of A and DPTR the relative
target address is obtained Example CALL Instructions Call instruction is used to call subroutine
• Subroutines are used to perform tasks that need to
be performed frequently • Subroutines saves memory space . 1.ACALL-Absolute Call • Unconditionally calls the subroutine located at the indicated address(11bit address 2K Range) Syntax- ACALL target address 2.LCALL-Long Call • Unconditionally calls the subroutine located at the indicated address(16bit address 64K Range) Syntax- LCALL target address RET –Return from subroutine • Syntax –RET RETI –Return from Interrupt • Syntax –RETI • It is used in the Interrupt service routine Example Examples