input output instructions 8051 assembly language

8,662

input output instructions 8051 assembly language
input output instructions 8051 assembly language

This tutorial continues the discussion on 8051 Assembly Programming by teaching input and output instructions for 8051 microcontrollers using assembly language. The microcontroller comprises a total of forty pins, most of which serve multiple functions. The primary function is input/output operations, while secondary functions may include counters or serial communication. The microcontroller features four ports (P0, P1, P2, and P3), each with 8 pins. The entire port can be addressed during programming. The 8051 refers to a family of microcontrollers with a common architecture, differing only in additional features, pin distribution, and packaging. Pin 40 is Vcc, receiving 5V, while pin 20 is GND, receiving 0V from the power source. Pins 18 and 19 are designated for connecting a crystal, which determines the machine cycle frequency, ranging from 3 to 24 MHz. Pin 9, the reset pin (RST), resets the program, similar to restarting a computer, setting the program counter back to zero and losing all register values. The EA/VPP pin (pin 31) is for external access; it is set to one (or Vcc) if the microcontroller has on-chip ROM, and to zero if it does not. This pin must not be left unconnected. The basic setup for microcontroller operation is outlined, including potential modifications to pins ALE/PROG, EA/VPP, and PSEN. A module is described with a 40-pin base mounted on a PCB to prevent damage during soldering. The AT89S52 microcontroller, a member of the 8051 family, is highlighted, with the exception of the AT89S51, which requires a pull-up resistor at port zero for input/output. The tutorial transitions to programming the 8051 in assembly language for input/output operations, noting that all ports can serve as input or output. The tutorial includes illustrations for accessing different pins and ports. For input reception, the input pins or ports must be initialized to logic HIGH (1). Instead of assigning logic high to each pin individually, a value of FF hex (binary 11111111) can be loaded to the input port. In specific scenarios, only a single bit may need to be observed for actions, such as triggering a buzzer for a temperature alarm when the signal goes high. The tutorial prepares users for practical implementation, requiring a typical parallel programmer or an ISP (In-System Programmer), which is generally more affordable and does not necessitate removing the microcontroller from the circuit for programming. Programmers are estimated to cost between Rs 1500-2500, with a recommendation to purchase a USB burner/programmer due to the obsolescence of parallel ports.

The 8051 microcontroller architecture is designed to facilitate a variety of applications through its versatile pin configuration. Each of the four ports (P0, P1, P2, P3) can be utilized for both input and output, allowing for efficient data handling in embedded systems. The ability to address entire ports simplifies programming, enabling the manipulation of multiple pins simultaneously.

In practical scenarios, the initialization of pins is crucial for proper operation. For instance, when configuring a port for input, setting all pins to logic HIGH can be efficiently achieved by loading a single hexadecimal value (FF) into the port register. This method not only saves programming time but also ensures that all pins are uniformly set, reducing the likelihood of errors during input operations.

The reset functionality is particularly important in embedded applications, as it allows for the reinitialization of the microcontroller without the need for physical intervention. This feature is essential for applications requiring reliability and stability, such as industrial automation or consumer electronics.

The choice of crystal frequency directly influences the performance of the microcontroller, with a range of 3 to 24 MHz allowing for flexibility in application design. Higher frequencies can lead to faster processing times, which is beneficial for time-sensitive tasks.

When interfacing with external components, such as sensors or actuators, careful attention must be paid to the electrical characteristics of the pins being used. For instance, the inclusion of pull-up resistors, as noted for the AT89S51, is a common practice to ensure stable input readings, particularly when dealing with open-collector outputs.

Overall, this comprehensive understanding of the 8051 microcontroller's architecture, pin configurations, and programming techniques lays a solid foundation for developing sophisticated embedded systems. The tutorial serves as a stepping stone for users to explore and implement their unique projects, leveraging the capabilities of the 8051 family of microcontrollers.This tutorial is in continuation with previous tutorials on 8051 Assembly Programming. Now we will learn how to give input and output instructions to 8051 microcontroller(s) using assembly programming language. The microcontroller has total forty pins in all. Most of the pins of 8051 microcontroller have more than one function. The first function is the input /output operation and the second function can be some special function like they can be used as counters or for serial communication. In microcontroller there are four ports (collection of pins) P0, P1, P2 &P3. These ports have 8 pins each as shown. As we will see later on we will be able to address the whole port during programming. Whenever we are talking about 8051 we are talking of the family of microcontrollers having the architecture of 8051.

They are all same except for some additional features, pins distribution and packaging. VCC and GND: - The pin 40 is Vcc i. e. it is given 5V and pin 20 is GND i. e. it is given 0V (supplied from power source) for powering up the microcontroller. CONNECTING THE CRYSTAL (XTAL1- XTAL2): The pin numbers 18 - 19 are used to connect the crystal. The frequency of this crystal determines the machine cycle. With 8051 family we can use a crystal having frequency from 3 to 24 MHz. RESET PIN CONNECTION (RST): The reset pin i. e. pin number 9 is used to reset the program just like we restart a computer, the program starts executing from the very beginning. When reset is used the program counter is set back to zero and the values in all other registers are lost.

EA/VPP: The EA pin no. 31 is known as external access. The 8051 microcontrollers have on chip ROM so the EA/VPP is set to one (or Vcc). In case there is no on- chip ROM, like in case of 8031 we set this pin equal to zero. This pin cannot be left unconnected. This is the basic setup of microcontroller that you need to have in order to perform an 8051 activity. The pins ALE/ PROG, EA/ VPP and PSEN may have some modifications. We will discuss this wherever it is necessary. This is a module that has been prepared by us. You can see that a 40 pin base has been mounted on the PCB (printed circuit board) instead of directly soldering the microcontroller to PCB which maybe damaged while soldering.

Here a microcontroller AT89S52 has been shown which is a member of 8051 family. The above circuit is valid for all the members of 8051 family except the AT89S51. In AT89S51, we also have to add pull up resistor at port zero for Input/ Output. (Check the data sheet of AT89S51 microcontroller for the same) So far we have discussed the basic setup required for initializing the microcontroller and now comes the interesting part i. e. how to program 8051 using assembly language i. e. carry out input/output operations. All the ports of 8051 can be used for Input or Output. Let`s get started. Some illustrations are listed below showing how to access the different pins and ports. Remember for receiving input the input pins or port must be initialized to logic HIGH i. e. 1 and in the subsequent example complete port has been used for receiving input. So rather than assigning logic high to each pin, FF hex value i. e. binary 11111111 is loaded to the input port. Sometimes we may only need to observe a single bit and perform an action based upon it like: receiving an input of temperature alarm and if the signal goes high (i.

e. temperature is above a certain limit) the buzzer goes off. Now you are ready for the real thing. We will start with a simple activity to give you a feel and also you can use this tutorial to implement your own ideas. For this you will need a typical parallel programmer or an ISP (In system programmer). The ISP is generally cheaper and you don`t need to remove the µController from the circuit to burn it.

The burners/programmers will cost you around Rs 1500-2500. Do try to buy a USB burner/programmer as parallel ports are n 🔗 External reference