SlideShare a Scribd company logo
MICROCONTROLLER
Unit II -ASSEMBLY PROGRAMMING AND INSTRUCTION OF
8051
Lecture – 12
UNIT – II ASSEMBLY PROGRAMMING AND
INSTRUCTION OF 8051
 Introduction to 8051 assembly programming, Assembling and running an 8051 program,
Data types and Assembler directives, 8051 Addressing Modes, Arithmetic, logic
instructions and programs, Jump, loop and call instructions, I/O port programming.
I/O Port
Programming
Port 0
Port 0 occupies a total of 8 pins (pins 32–39).
It can be used for input or output. To use the pins of port 0 as both input and
output ports, each pin must be connected externally to a 10Kohm pull-up resistor.
This is due to the fact that P0 is an open drain, unlike P1, P2, and P3.
With resistors connected to port 0, in order to make it an input, the port must be
programmed by writing 1 to all the bits.
In the following code, port 0 is configured first as an input port by writing 1s to it,
and then data is received from that port and sent to P1.
;Get a byte from P0 and send it to P1
MOV A,#0FFH ;A = FF hex
MOV P0,A ;make P0 an input port by writing
all 1s to it
BACK: MOV A,P0 ;get data from P0
MOV P1,A ;send it to port 1
SJMP BACK ;keep doing it
Dual role of port 0
As shown in Figure 1, port 0 is also designated as AD0–AD7, allowing it to be
used for both address and data. When connecting an 8051/31 to an external
memory, port 0 provides both address and data. The 8051 multiplexes address
and data through port 0 to save pins.
Port 1
Port 1 occupies a total of 8 pins (pins 1 through 8).
It can be used as input or output.
In contrast to port 0, this port does not need any pull-up resistors since it already
has pull-up resistors internally.
Upon reset, port 1 is configured as an input port.
The following code will continuously send out to port 1 the alternating values 55H
and AAH.
;Toggle all bits of P1 continuously
MOV A,#55H
BACK: MOV P1,A
ACALL DELAY
CPL A ;complement(Invert) reg. A
SJMP BACK
Port 2
Port 2 occupies a total of 8 pins (pins 21 through 28).
It can be used as input or output.
Just like P1, port 2 does not need any pull-up resistors since it already has pull-up
resistors internally.
Upon reset, port 2 is configured as an input port.
The following code will continuously send out to port 2 the alternating values 55H
and AAH. That is, all the bits of P2 toggle continuously.
MOV A,#55H
BACK: MOV P2,A
ACALL DELAY
CPL A ;complement reg. A
SJMP BACK
;Toggle all bits of P0
BACK: MOV A,#55H
MOV P0,A
ACALL DELAY
MOV A,#0AAH
MOV P0,A
ACALL DELAY
SJMP BACK
By sending 55H and AAH to a given port continuously, we toggle all the bits of
that port.
Dual role of port 2
In many systems based on the 8051, P2 is used as simple I/O.
However, in 8031-based systems, port 2 must be used along with P0 to provide
the 16-bit address for external memory.
Port 2 is also designated as A8–A15, indicating its dual function.
Port 3 –
Alternate
functions

More Related Content

PDF
Embedded systems io programming
PPT
I o ports and timers of 8051
PDF
SE PAI Unit 5_IO programming in 8051
PDF
Port Organization of 8051 .pdf
PPTX
8051 Microcontroller -1.pptx
PPTX
Microprocessor and microcontroller MODULE-4.pptx
PPTX
I/O port programming in 8051
Embedded systems io programming
I o ports and timers of 8051
SE PAI Unit 5_IO programming in 8051
Port Organization of 8051 .pdf
8051 Microcontroller -1.pptx
Microprocessor and microcontroller MODULE-4.pptx
I/O port programming in 8051

Similar to MICROCONTROLLER .pptx (20)

PPTX
8051-Special Purpose Registers and Memory Interface.pptx
PPT
Power Point Presentation on Microcontrollers
PPT
The Intel MCS-51 is a single-chip microcontroller series developed by Intel
PPT
8051 Microcontroller architecture and operation
PPT
MICROCONTROLLER 8051 ARCHITECTURE BASIC.ppt
PPT
Microcontroller 8051
PPT
8051 MMD Chapter 1.ppt
DOCX
Microprocessor Interfacing and 8155 Features
PDF
Embedded system (Chapter 3) io_port_programming
PPTX
8155 GPPI
PPT
Lecture_8255_MODIfggggggggggggFIED_BY_ME_24-11-2020.ppt
PDF
unit-3-8255.pdf
PPTX
08 ATmega328P Arduino GPIO input outpt.pptx
PPTX
8255_Ppi new
DOC
Unit iii microcontrollers final1
PPT
1203 Ppi 8155
PPTX
Embedded System Microcontroller 8051
PPT
Io (2)
PPTX
Hardware View of Intel 8051
8051-Special Purpose Registers and Memory Interface.pptx
Power Point Presentation on Microcontrollers
The Intel MCS-51 is a single-chip microcontroller series developed by Intel
8051 Microcontroller architecture and operation
MICROCONTROLLER 8051 ARCHITECTURE BASIC.ppt
Microcontroller 8051
8051 MMD Chapter 1.ppt
Microprocessor Interfacing and 8155 Features
Embedded system (Chapter 3) io_port_programming
8155 GPPI
Lecture_8255_MODIfggggggggggggFIED_BY_ME_24-11-2020.ppt
unit-3-8255.pdf
08 ATmega328P Arduino GPIO input outpt.pptx
8255_Ppi new
Unit iii microcontrollers final1
1203 Ppi 8155
Embedded System Microcontroller 8051
Io (2)
Hardware View of Intel 8051
Ad

Recently uploaded (20)

PDF
1_English_Language_Set_2.pdf probationary
PDF
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Introduction to Building Materials
PDF
Indian roads congress 037 - 2012 Flexible pavement
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
RMMM.pdf make it easy to upload and study
PDF
Classroom Observation Tools for Teachers
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Hazard Identification & Risk Assessment .pdf
PPTX
Lesson notes of climatology university.
PDF
advance database management system book.pdf
1_English_Language_Set_2.pdf probationary
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
A systematic review of self-coping strategies used by university students to ...
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Supply Chain Operations Speaking Notes -ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Weekly quiz Compilation Jan -July 25.pdf
Introduction to Building Materials
Indian roads congress 037 - 2012 Flexible pavement
Orientation - ARALprogram of Deped to the Parents.pptx
RMMM.pdf make it easy to upload and study
Classroom Observation Tools for Teachers
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Hazard Identification & Risk Assessment .pdf
Lesson notes of climatology university.
advance database management system book.pdf
Ad

MICROCONTROLLER .pptx

  • 1. MICROCONTROLLER Unit II -ASSEMBLY PROGRAMMING AND INSTRUCTION OF 8051 Lecture – 12
  • 2. UNIT – II ASSEMBLY PROGRAMMING AND INSTRUCTION OF 8051  Introduction to 8051 assembly programming, Assembling and running an 8051 program, Data types and Assembler directives, 8051 Addressing Modes, Arithmetic, logic instructions and programs, Jump, loop and call instructions, I/O port programming.
  • 4. Port 0 Port 0 occupies a total of 8 pins (pins 32–39). It can be used for input or output. To use the pins of port 0 as both input and output ports, each pin must be connected externally to a 10Kohm pull-up resistor. This is due to the fact that P0 is an open drain, unlike P1, P2, and P3.
  • 5. With resistors connected to port 0, in order to make it an input, the port must be programmed by writing 1 to all the bits. In the following code, port 0 is configured first as an input port by writing 1s to it, and then data is received from that port and sent to P1. ;Get a byte from P0 and send it to P1 MOV A,#0FFH ;A = FF hex MOV P0,A ;make P0 an input port by writing all 1s to it BACK: MOV A,P0 ;get data from P0 MOV P1,A ;send it to port 1 SJMP BACK ;keep doing it Dual role of port 0 As shown in Figure 1, port 0 is also designated as AD0–AD7, allowing it to be used for both address and data. When connecting an 8051/31 to an external memory, port 0 provides both address and data. The 8051 multiplexes address and data through port 0 to save pins.
  • 6. Port 1 Port 1 occupies a total of 8 pins (pins 1 through 8). It can be used as input or output. In contrast to port 0, this port does not need any pull-up resistors since it already has pull-up resistors internally. Upon reset, port 1 is configured as an input port. The following code will continuously send out to port 1 the alternating values 55H and AAH. ;Toggle all bits of P1 continuously MOV A,#55H BACK: MOV P1,A ACALL DELAY CPL A ;complement(Invert) reg. A SJMP BACK
  • 7. Port 2 Port 2 occupies a total of 8 pins (pins 21 through 28). It can be used as input or output. Just like P1, port 2 does not need any pull-up resistors since it already has pull-up resistors internally. Upon reset, port 2 is configured as an input port. The following code will continuously send out to port 2 the alternating values 55H and AAH. That is, all the bits of P2 toggle continuously. MOV A,#55H BACK: MOV P2,A ACALL DELAY CPL A ;complement reg. A SJMP BACK
  • 8. ;Toggle all bits of P0 BACK: MOV A,#55H MOV P0,A ACALL DELAY MOV A,#0AAH MOV P0,A ACALL DELAY SJMP BACK By sending 55H and AAH to a given port continuously, we toggle all the bits of that port. Dual role of port 2 In many systems based on the 8051, P2 is used as simple I/O. However, in 8031-based systems, port 2 must be used along with P0 to provide the 16-bit address for external memory. Port 2 is also designated as A8–A15, indicating its dual function.