{"id":79,"date":"2018-07-26T09:50:53","date_gmt":"2018-07-26T09:50:53","guid":{"rendered":"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=79"},"modified":"2018-08-10T11:18:01","modified_gmt":"2018-08-10T11:18:01","slug":"programming-parallel-ports","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/chapter\/programming-parallel-ports\/","title":{"rendered":"Programming parallel ports"},"content":{"raw":"<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In this lecture pin diagram of 8051 controller will be shown and discussed, an introduction to Ports of 8051 controller will be given and assembly programs for handling pins and ports of controller will be discussed.<\/p>\r\n&nbsp;\r\n\r\n<strong>1. Pin diagram of 8051 and ports<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">8051 family members come in different IC packages, such as DIP (dual in-line package), QFP (quad flat package), and LLC (leadless chip carrier), they all have 40 pins that are dedicated to various functions such as I\/O, RD, WR, address, data, and interrupts. some companies provide 20-pin versions of the 8051 with a reduced number of I\/O ports for less demanding applications. Majority of developers uses the 40-pin chip, we will concentrate on that. Figure 8-1 shows the pin diagram of 8051.<\/p>\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-82 aligncenter\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-31.png\" alt=\"\" width=\"490\" height=\"296\" \/>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">A set of 32 pins are set aside for the four ports P0,P1,P2 and P3 where each port takes 8 pins. Pin 40 provides supply voltage to the chip. The voltage source is +5V. Pin 20 is the ground. The rest of the pins are designated as XTAL1,XTAL2,RST,EA,PSEN and ALE. XTAL2\/XTALI are for oscillator input which provides the clock pulse to microcontroller. The pins from 32 to 39 form the port0( AD0\/AD7). P0.0 to P0.7 are multiplexed pins used for address and data The pins from 1 to 8 are for port 1 (P1.0 to P1.7); and the pins from 21 to 28 are for port 2. (P2.0 to P2.7) is used for sending\u00a0<span style=\"font-size: 1em;text-align: initial\">address to memory. The 9th pin RST is used for Restarting the 8051 microcontroller. The pins from 10 to 17 are for port3 which is a special port, and it is multi-functional. The 30th pin is ALE(Address latch enable). When the pin is set to 1, then address is transferred through the pins AD0 to AD7. When the pin is set to 0 then data is transferred through the pins AD0 to AD7. The 29th pin is PSEN which is the Program Strobe Enable used for reading the program from external memory.<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>1.1 Crystal Oscillator<\/strong>\r\n\r\n&nbsp;\r\n\r\nFigure 1.2 XTAL connection to an external clock source\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The 8051 has an on-chip oscillator but requires an external clock to run it. Most often a quartz crystal oscillator is connected to inputs XTAL (pin 19) and XTAL(pin 18). The quartz crystal oscillator connected to inputs XTAL1 and XTAL2 also needs two capacitors of 30 pF value. One side of each capacitor is connected to the ground as shown in Figure 1.2.<\/p>\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-85 aligncenter\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-33.png\" alt=\"\" width=\"398\" height=\"208\" \/>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">It must be noted that there are various speeds of the 8051 family. Speed refers to the maximum oscillator frequency which is connected to XTAL. For example, a 12-MHz chip must be connected to a crystal with 12 MHz frequency or less. Likewise, a 20 MHz microcontroller requires a crystal frequency of no more than 20 MHz. When the 8051 is connected to a crystal oscillator and is powered up, the frequency on the XTAL2 pin is connected using the oscilloscope.<\/p>\r\n&nbsp;\r\n\r\n<strong>1.2 RST<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Pin 9 is the Reset pin. It is an input and is active high. When the pin is applied to high, the microcontroller will reset and terminate.<\/p>\r\n&nbsp;\r\n\r\n<strong>1.3 EA<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The 8051 family members will come with on-chip ROM for storing the programs. In such cases, the EA pin is connected to VCC. For the family members like 8031 and 8032, there is no on-chip ROM, hence the code is stored in external ROM and is fetched by 8031\/8032. EA pin is connected to GND to indicate that the code is stored externally. EA\u00a0<span style=\"font-size: 1em;text-align: initial\">stands for '' External Access\" which is pin 31 in the DIP packages. It is an input pin and is connected to either Vcc or ground. 8031 uses this pin along with PSEN to access programs stored in ROM memory located outside the 8031. The next two pins are used mainly in 8031-based systems.<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>1.4 PSEN<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">This is an output pin. PSEN stands for ''Program store enable''. The external ROM holds the program code, this pin is connected to the OE pin of the ROM.<\/p>\r\n&nbsp;\r\n\r\n<strong>1.5 ALE<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">It is an output pin and is active high. When connecting an 8031 to external memory, port 0 provides both address and data. The ALE pin is used for demultiplexing the address and data by connecting to the G pin of the 74LS373 chip.<\/p>\r\n&nbsp;\r\n\r\n<strong>1.6 Ports 0,1,2 and 3<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">All the four ports in 8051 are bidirectional. Each consists of a latch an output driver, and an input buffer. P0,P2,and P3 will perform special function other than I\/O. As shown in the figure below, there are four ports namely P0,P1,P2 and P3, each uses 8 pins, making them 8-bit ports. All the ports upon reset are configured as input, since P0-P3 have FFH on them.<\/p>\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-84 aligncenter\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-32.png\" alt=\"\" width=\"405\" height=\"236\" \/>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The output drivers of Ports 0 and 2, and input buffers of Port 0, are used in accesses to external memory. In this application, Port 0 outputs the low byte of the external memory address, time-multiplexed with the byte being written or read. Port 2 outputs the high byte of the external memory address when the address is 16 bits wide.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">As shown in the figure 1.3, port 0 is also designated as AD0-AD7, allowing it to be used for both address and data. When connecting 8051 to an external memory, port 0 provides both address and data. The 8051 multiplexes address and data through port 0 to save pins. ALE indicates if P0 has address or data. When ALE=0, it provides data D0-D7, but when ALE=1 it has address A0-A7. Therefore ALE is used for demultiplexing the\u00a0<span style=\"font-size: 1em;text-align: initial\">address and data. When there is no external memory connection, the pins of P0 must be connected externally to a ten K-ohm pull-up resistor. This is due to the fact that PO is an open-drain, unlike P1,P2 and P3. Open drain is a term used for MOS chips in the same way that open collector is used for TTL chips. In contrast to Port 0, P1,P2 and P3 do not need any pull-up resistors since they have pull-up resistors internally. Upon reset, ports P1,P2 and P3 are configured as input ports.<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong><em>1.6.1 P1 and P2<\/em><\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In 8051 based systems with no external memory connection, both P1 and P2 are used as simple I\/O. However in 8031\/8051 based systems with external memory connection, port 2 must be used along with P0 to provide the 16-bit address for the external memory. Port 2 is designated as A8-A15, indicating its dual function. When 8051 is connected to external memory, P2 is used for the upper 8 bits of the 16-bit address and it cannot be used for I\/O.<\/p>\r\n&nbsp;\r\n\r\n<strong><em>1.6.2 Port 3<\/em><\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">It occupies a total of 8 pins, pins 10 through 17. It can be used as input or output. Ports P1,P2 and P3 do not need any pull-up resistors. Port 3 has the additional function of providing some extremely important signals such as interrupts.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">P3.0 and P3.1 are used for the RxD and TxD serial communications signals. Hence 8051 supports parallel as well as serial communications. Bits P3.2 and P3.3 are set aside for external interrupts. Bits P3.4 and P3.5 are used for Timers 0 and 1. P3.6 and P3.7 are used to provide the WR and RD signals of external memory connections, while the rest of the pins in port3 are normally used in the alternate function role.<\/p>\r\n&nbsp;\r\n<table class=\"aligncenter\" style=\"height: 140px;width: 60%\" border=\"1\">\r\n<tbody>\r\n<tr style=\"height: 14px\">\r\n<td style=\"height: 14px;width: 37.0625px\"><strong>Ports<\/strong><\/td>\r\n<td style=\"height: 14px;width: 275.063px\"><strong>Function<\/strong><\/td>\r\n<td style=\"height: 14px;width: 81.0625px\"><strong>Pin\u00a0number<\/strong><\/td>\r\n<\/tr>\r\n<tr style=\"height: 14px\">\r\n<td style=\"height: 14px;width: 37.0625px\">P3.0<\/td>\r\n<td style=\"height: 14px;width: 275.063px\">RxD(serial input port)<\/td>\r\n<td style=\"height: 14px;width: 81.0625px\">10<\/td>\r\n<\/tr>\r\n<tr style=\"height: 14px\">\r\n<td style=\"height: 14px;width: 37.0625px\">P3.1<\/td>\r\n<td style=\"height: 14px;width: 275.063px\">TxD(serial output port)<\/td>\r\n<td style=\"height: 14px;width: 81.0625px\">11<\/td>\r\n<\/tr>\r\n<tr style=\"height: 14px\">\r\n<td style=\"height: 14px;width: 37.0625px\">P3.2<\/td>\r\n<td style=\"height: 14px;width: 275.063px\">INT0 (external Interrput)<\/td>\r\n<td style=\"height: 14px;width: 81.0625px\">12<\/td>\r\n<\/tr>\r\n<tr style=\"height: 14px\">\r\n<td style=\"height: 14px;width: 37.0625px\">P3.3<\/td>\r\n<td style=\"height: 14px;width: 275.063px\">INT1(external Interrput)<\/td>\r\n<td style=\"height: 14px;width: 81.0625px\">13<\/td>\r\n<\/tr>\r\n<tr style=\"height: 14px\">\r\n<td style=\"height: 14px;width: 37.0625px\">P3.4<\/td>\r\n<td style=\"height: 14px;width: 275.063px\">T0(Timer\/ Counter 0 external Input)<\/td>\r\n<td style=\"height: 14px;width: 81.0625px\">14<\/td>\r\n<\/tr>\r\n<tr style=\"height: 14px\">\r\n<td style=\"height: 14px;width: 37.0625px\">P3.5<\/td>\r\n<td style=\"height: 14px;width: 275.063px\">T1(Timer\/ Counter 1 external Input)<\/td>\r\n<td style=\"height: 14px;width: 81.0625px\">15<\/td>\r\n<\/tr>\r\n<tr style=\"height: 14px\">\r\n<td style=\"height: 14px;width: 37.0625px\">P3.6<\/td>\r\n<td style=\"height: 14px;width: 275.063px\">WR ( External data memory write strobe)<\/td>\r\n<td style=\"height: 14px;width: 81.0625px\">16<\/td>\r\n<\/tr>\r\n<tr style=\"height: 14px\">\r\n<td style=\"height: 14px;width: 37.0625px\">P3.7<\/td>\r\n<td style=\"height: 14px;width: 275.063px\">RD( External data memory read strobe)<\/td>\r\n<td style=\"height: 14px;width: 81.0625px\">17<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/div>\r\n<p style=\"text-align: center\"><strong><span style=\"text-align: initial;font-size: 1em\">Table 1.1 Port 3 Alternate functions<\/span><\/strong><\/p>\r\n\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>2.Configuring ports<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">When \u20180\u2019 is written to the port, it is configured as output. To reconfigure the port as input, \u20181\u2019 must be written to port. Port0 is configured as input by writing \u20181\u2019 to port and then it can be used as input.<\/p>\r\n&nbsp;\r\n\r\nEx:\u00a0 MOV A,#0FFH ; A=FF hex\r\n\r\nMOV P0,A\u00a0 ; write \u20181\u2019 to port\r\n\r\nMOV A,P0\u00a0 ; A=P0\r\n\r\nMOV P2,A\u00a0\u00a0 ; P2=A\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Initially Port0 is configured as input port. First, using the immediate addressing mode the hexadecimal number FFH is moved to accumulator and all the port pins in P0 is written to 1. This statement is used to declare that the port P0 is used as the input port. Port P0 is connected to some other input device. The data received by the port P0 is sent to accumulator and then finally Port 2 is the output port in which the data stored in accumulator is delivered to port2.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Another function of Port 0 is AD0-AD7. It is used for both address and data. When connecting an 8051\/31 to an external memory, port 0 provides both address and data. Port 1 is used as input and output. Upon reset, port 1 is configured as an input port. Port 2 is also used as input or output. Upon reset, port 2 is configured as an input port. Port 2 along with P0 will provide the 16- bit address for the external memory. If 16 bit is needed for accessing the external memory then AD0-AD7 pins from Port 0 and A8-A15 pins from port 2 are combined in which port 2 contains the higher order byte and port 0 contains the lower order byte.<\/p>\r\n\r\n<\/div>\r\n<img class=\"size-full wp-image-86 aligncenter\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-34.png\" alt=\"\" width=\"466\" height=\"249\" \/>\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Instructions used in single bit operation are JB and JNB. These instructions monitor a bit and make a decision depending on whether it\u2019s 0 or 1. These two instructions can be used for any bits of I\/O ports 0, 1, 2, and 3. Table 1.2 lists the single bit operating instructions. Table 1.2 lists the single bit operations.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">2.1 Access 1 or 2 bits<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">In order to access only 1 or 2 bits of the port the following commands can be used.<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">CPL P0.4\u00a0;complement P0.4<\/span><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">SETB P1.4\u00a0;set only P1.4<\/span><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">CLR P2.2\u00a0; clear P2.2<\/span><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">SETB P1.0\u00a0; set bit 0 of port 1 as high<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">The first statement CPL complements the P0.4 bit. If P0.4 bit is 1, then it is converted to 0 and if it is 0, then converted to 1. In the above example SETB functions are used for setting the corresponding bits P1.0 and P1.4 to 1. CLR command will clear the particular bit.<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>2.2 Configuring port pin to generate square wave<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Following assembly code helps to generate a square wave at pin P1.3<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">LOOP: SETB P1.3\u00a0\u00a0\u00a0\u00a0\u00a0 ; p1.3=1<\/span><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">LCALL DELAY\u00a0\u00a0 ;delay subroutine<\/span><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">CLR P1.3\u00a0 \u00a0 ;p1.3=0<\/span><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">LCALL DELAY<\/span><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">SJMP LOOP<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n<img class=\"size-full wp-image-87 aligncenter\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-35.png\" alt=\"\" width=\"344\" height=\"184\" \/>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">For generating the square wave, the port is set to 1 for some period of time and then set to zero for the same time. Then a square wave can be generated. If the delay is changed, then the square wave becomes rectangular. Initially the port P1.3 is set to 1 using the SETB operation. LCALL is the long call which is the delay subroutine call, the pin P1.3 becomes 1 for certain period of time and then that pin is cleared using the CLR command. This pin maintains zero state for the same time and then using the control statement short jump, the loop continues and the square wave is generated.<\/p>\r\n&nbsp;\r\n\r\n<strong>3. Sample Programs<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>3.1 A switch is connected to pin P1.7. Write a program to check the status of Switch and perform the following:<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>(a)\u00a0<\/strong><strong>If SW=0, send letter \u2018N\u2019 to P2<\/strong>\r\n\r\n<strong>\u00a0<\/strong>\r\n\r\n<strong>(b)\u00a0<\/strong><strong>If SW=1, send letter \u2018S\u2019 to P2<\/strong>\r\n\r\n<\/div>\r\n<strong>\u00a0<img class=\"size-full wp-image-88 aligncenter\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-36.png\" alt=\"\" width=\"257\" height=\"165\" \/><\/strong>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\nSETB P1.7\u00a0 ;make P1.7 an input\r\n\r\nAGAIN:JB P1.7,OVER\u00a0 ;jump if P1.7=1\r\n\r\nMOV P2,#\u2019N\u2019\u00a0 ;SW=0, issue \u2018A\u2019 to P2\r\n\r\nSJMP AGAIN\u00a0 ;keep monitoring\r\n\r\nOVER: MOV P2,#\u2019S\u2019\u00a0 ;SW=1, issue \u2018S\u2019 to P2\r\n\r\nSJMP AGAIN\u00a0 ;keep monitoring\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Initially the pin P1.7 is set to 1 which indicates that this pin is considered as the input pin. Then the condition of JB becomes true hence it goes to the loop OVER, the byte 'S' is sent to the output port P2. Then using the SJMP command the AGAIN loop continues. If the switch is pressed it means the pin P1.7 becomes 1, then the condition fails. Hence the byte 'N' is sent to the port P2. Likewise the loop is executed continuously. If the switch is pressed the byte 'S' is sent to the output port P2, if it is not pressed then the byte 'N' is sent to the output port P2.<\/p>\r\n&nbsp;\r\n\r\n<strong>3.2 Write a program to perform the following:<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>(a)\u00a0\u00a0 <\/strong><strong>Keep monitoring switch (at) P0.1 until it becomes high<\/strong><strong>\u00a0<\/strong>\r\n\r\n<strong>(b)\u00a0\u00a0 <\/strong><strong>When P0.1 becomes high, Light LEDs connected at port 2<\/strong>\r\n\r\n<strong>(c)\u00a0\u00a0 <\/strong><strong>Send a low-to-high (L-to-H) pulse to P1.2 to sound buzzer<\/strong>\r\n\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-89 aligncenter\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-37.png\" alt=\"\" width=\"319\" height=\"204\" \/>\r\n\r\nSETB P0.1 ;make P0.1 as input (switch)\r\n\r\nMOV A,#FFH\u00a0\u00a0\u00a0 ;A=11111111\r\n\r\nAGAIN: JNB P0.1,AGAIN ; get out when P0.1=1\r\n\r\nMOV P2,A ;Light LEDS by sending 1s to P2\r\n\r\nCLR P1.2 ;make P1.2 low\r\n\r\nSETB P1.2 ;make 01.2 high - L-to-H to sound buzzer\r\n\r\nSJMP AGAIN\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Initially the bit P0.1 is set as input port. Then the hexadecimal value FFH is stored in Accumulator. The jump condition fails and the Accumulator value is sent to port P2. Then the port P1.2 is cleared and it is set again for giving the low to high pulse to the port P1.2, then the alarm will ring. If the switch is pressed the LED's connected to P2 will glow and the alarm will start ringing.<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">4. Summary<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"font-size: 1em\">In this lecture pin diagram of 8051 controller is discussed. Introduction to pins and the ports of 8051 controller has been given. Some assembly programs are also written for handling pins and ports of controller.<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">5. References<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">1.The 8051 Microcontroller and Embedded Systems Using Assembly and C Second Edition Muhammad Ali Mazidi, Janice Gillispie Mazidi and Rolin D. McKinlay.<\/span><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">2. http:\/\/what-when-how.com\/8051-microcontroller\/pin-description-of-the-8051\/<\/span><\/p>\r\n\r\n<\/div>\r\n&nbsp;\r\n\r\n<strong>Supporting &amp; Reference Materials<\/strong>\r\n<ol>\r\n \t<li>The 8051 Microcontroller and Embedded Systems Using Assembly and C Second Edition Muhammad Ali Mazidi, Janice Gillispie Mazidi and Rolin D. McKinlay.<\/li>\r\n \t<li>http:\/\/what-when-how.com\/8051-microcontroller\/pin-description-of-the-8051\/<\/li>\r\n<\/ol>","rendered":"<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In this lecture pin diagram of 8051 controller will be shown and discussed, an introduction to Ports of 8051 controller will be given and assembly programs for handling pins and ports of controller will be discussed.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1. Pin diagram of 8051 and ports<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">8051 family members come in different IC packages, such as DIP (dual in-line package), QFP (quad flat package), and LLC (leadless chip carrier), they all have 40 pins that are dedicated to various functions such as I\/O, RD, WR, address, data, and interrupts. some companies provide 20-pin versions of the 8051 with a reduced number of I\/O ports for less demanding applications. Majority of developers uses the 40-pin chip, we will concentrate on that. Figure 8-1 shows the pin diagram of 8051.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-82 aligncenter\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-31.png\" alt=\"\" width=\"490\" height=\"296\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-31.png 490w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-31-300x181.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-31-65x39.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-31-225x136.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-31-350x211.png 350w\" sizes=\"auto, (max-width: 490px) 100vw, 490px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">A set of 32 pins are set aside for the four ports P0,P1,P2 and P3 where each port takes 8 pins. Pin 40 provides supply voltage to the chip. The voltage source is +5V. Pin 20 is the ground. The rest of the pins are designated as XTAL1,XTAL2,RST,EA,PSEN and ALE. XTAL2\/XTALI are for oscillator input which provides the clock pulse to microcontroller. The pins from 32 to 39 form the port0( AD0\/AD7). P0.0 to P0.7 are multiplexed pins used for address and data The pins from 1 to 8 are for port 1 (P1.0 to P1.7); and the pins from 21 to 28 are for port 2. (P2.0 to P2.7) is used for sending\u00a0<span style=\"font-size: 1em;text-align: initial\">address to memory. The 9th pin RST is used for Restarting the 8051 microcontroller. The pins from 10 to 17 are for port3 which is a special port, and it is multi-functional. The 30th pin is ALE(Address latch enable). When the pin is set to 1, then address is transferred through the pins AD0 to AD7. When the pin is set to 0 then data is transferred through the pins AD0 to AD7. The 29th pin is PSEN which is the Program Strobe Enable used for reading the program from external memory.<\/span><\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>1.1 Crystal Oscillator<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Figure 1.2 XTAL connection to an external clock source<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The 8051 has an on-chip oscillator but requires an external clock to run it. Most often a quartz crystal oscillator is connected to inputs XTAL (pin 19) and XTAL(pin 18). The quartz crystal oscillator connected to inputs XTAL1 and XTAL2 also needs two capacitors of 30 pF value. One side of each capacitor is connected to the ground as shown in Figure 1.2.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-85 aligncenter\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-33.png\" alt=\"\" width=\"398\" height=\"208\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-33.png 398w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-33-300x157.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-33-65x34.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-33-225x118.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-33-350x183.png 350w\" sizes=\"auto, (max-width: 398px) 100vw, 398px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">It must be noted that there are various speeds of the 8051 family. Speed refers to the maximum oscillator frequency which is connected to XTAL. For example, a 12-MHz chip must be connected to a crystal with 12 MHz frequency or less. Likewise, a 20 MHz microcontroller requires a crystal frequency of no more than 20 MHz. When the 8051 is connected to a crystal oscillator and is powered up, the frequency on the XTAL2 pin is connected using the oscilloscope.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.2 RST<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Pin 9 is the Reset pin. It is an input and is active high. When the pin is applied to high, the microcontroller will reset and terminate.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.3 EA<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The 8051 family members will come with on-chip ROM for storing the programs. In such cases, the EA pin is connected to VCC. For the family members like 8031 and 8032, there is no on-chip ROM, hence the code is stored in external ROM and is fetched by 8031\/8032. EA pin is connected to GND to indicate that the code is stored externally. EA\u00a0<span style=\"font-size: 1em;text-align: initial\">stands for &#8221; External Access&#8221; which is pin 31 in the DIP packages. It is an input pin and is connected to either Vcc or ground. 8031 uses this pin along with PSEN to access programs stored in ROM memory located outside the 8031. The next two pins are used mainly in 8031-based systems.<\/span><\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>1.4 PSEN<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">This is an output pin. PSEN stands for &#8221;Program store enable&#8221;. The external ROM holds the program code, this pin is connected to the OE pin of the ROM.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.5 ALE<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">It is an output pin and is active high. When connecting an 8031 to external memory, port 0 provides both address and data. The ALE pin is used for demultiplexing the address and data by connecting to the G pin of the 74LS373 chip.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.6 Ports 0,1,2 and 3<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">All the four ports in 8051 are bidirectional. Each consists of a latch an output driver, and an input buffer. P0,P2,and P3 will perform special function other than I\/O. As shown in the figure below, there are four ports namely P0,P1,P2 and P3, each uses 8 pins, making them 8-bit ports. All the ports upon reset are configured as input, since P0-P3 have FFH on them.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-84 aligncenter\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-32.png\" alt=\"\" width=\"405\" height=\"236\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-32.png 405w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-32-300x175.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-32-65x38.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-32-225x131.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-32-350x204.png 350w\" sizes=\"auto, (max-width: 405px) 100vw, 405px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The output drivers of Ports 0 and 2, and input buffers of Port 0, are used in accesses to external memory. In this application, Port 0 outputs the low byte of the external memory address, time-multiplexed with the byte being written or read. Port 2 outputs the high byte of the external memory address when the address is 16 bits wide.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">As shown in the figure 1.3, port 0 is also designated as AD0-AD7, allowing it to be used for both address and data. When connecting 8051 to an external memory, port 0 provides both address and data. The 8051 multiplexes address and data through port 0 to save pins. ALE indicates if P0 has address or data. When ALE=0, it provides data D0-D7, but when ALE=1 it has address A0-A7. Therefore ALE is used for demultiplexing the\u00a0<span style=\"font-size: 1em;text-align: initial\">address and data. When there is no external memory connection, the pins of P0 must be connected externally to a ten K-ohm pull-up resistor. This is due to the fact that PO is an open-drain, unlike P1,P2 and P3. Open drain is a term used for MOS chips in the same way that open collector is used for TTL chips. In contrast to Port 0, P1,P2 and P3 do not need any pull-up resistors since they have pull-up resistors internally. Upon reset, ports P1,P2 and P3 are configured as input ports.<\/span><\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p><strong><em>1.6.1 P1 and P2<\/em><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In 8051 based systems with no external memory connection, both P1 and P2 are used as simple I\/O. However in 8031\/8051 based systems with external memory connection, port 2 must be used along with P0 to provide the 16-bit address for the external memory. Port 2 is designated as A8-A15, indicating its dual function. When 8051 is connected to external memory, P2 is used for the upper 8 bits of the 16-bit address and it cannot be used for I\/O.<\/p>\n<p>&nbsp;<\/p>\n<p><strong><em>1.6.2 Port 3<\/em><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">It occupies a total of 8 pins, pins 10 through 17. It can be used as input or output. Ports P1,P2 and P3 do not need any pull-up resistors. Port 3 has the additional function of providing some extremely important signals such as interrupts.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">P3.0 and P3.1 are used for the RxD and TxD serial communications signals. Hence 8051 supports parallel as well as serial communications. Bits P3.2 and P3.3 are set aside for external interrupts. Bits P3.4 and P3.5 are used for Timers 0 and 1. P3.6 and P3.7 are used to provide the WR and RD signals of external memory connections, while the rest of the pins in port3 are normally used in the alternate function role.<\/p>\n<p>&nbsp;<\/p>\n<table class=\"aligncenter\" style=\"height: 140px;width: 60%\">\n<tbody>\n<tr style=\"height: 14px\">\n<td style=\"height: 14px;width: 37.0625px\"><strong>Ports<\/strong><\/td>\n<td style=\"height: 14px;width: 275.063px\"><strong>Function<\/strong><\/td>\n<td style=\"height: 14px;width: 81.0625px\"><strong>Pin\u00a0number<\/strong><\/td>\n<\/tr>\n<tr style=\"height: 14px\">\n<td style=\"height: 14px;width: 37.0625px\">P3.0<\/td>\n<td style=\"height: 14px;width: 275.063px\">RxD(serial input port)<\/td>\n<td style=\"height: 14px;width: 81.0625px\">10<\/td>\n<\/tr>\n<tr style=\"height: 14px\">\n<td style=\"height: 14px;width: 37.0625px\">P3.1<\/td>\n<td style=\"height: 14px;width: 275.063px\">TxD(serial output port)<\/td>\n<td style=\"height: 14px;width: 81.0625px\">11<\/td>\n<\/tr>\n<tr style=\"height: 14px\">\n<td style=\"height: 14px;width: 37.0625px\">P3.2<\/td>\n<td style=\"height: 14px;width: 275.063px\">INT0 (external Interrput)<\/td>\n<td style=\"height: 14px;width: 81.0625px\">12<\/td>\n<\/tr>\n<tr style=\"height: 14px\">\n<td style=\"height: 14px;width: 37.0625px\">P3.3<\/td>\n<td style=\"height: 14px;width: 275.063px\">INT1(external Interrput)<\/td>\n<td style=\"height: 14px;width: 81.0625px\">13<\/td>\n<\/tr>\n<tr style=\"height: 14px\">\n<td style=\"height: 14px;width: 37.0625px\">P3.4<\/td>\n<td style=\"height: 14px;width: 275.063px\">T0(Timer\/ Counter 0 external Input)<\/td>\n<td style=\"height: 14px;width: 81.0625px\">14<\/td>\n<\/tr>\n<tr style=\"height: 14px\">\n<td style=\"height: 14px;width: 37.0625px\">P3.5<\/td>\n<td style=\"height: 14px;width: 275.063px\">T1(Timer\/ Counter 1 external Input)<\/td>\n<td style=\"height: 14px;width: 81.0625px\">15<\/td>\n<\/tr>\n<tr style=\"height: 14px\">\n<td style=\"height: 14px;width: 37.0625px\">P3.6<\/td>\n<td style=\"height: 14px;width: 275.063px\">WR ( External data memory write strobe)<\/td>\n<td style=\"height: 14px;width: 81.0625px\">16<\/td>\n<\/tr>\n<tr style=\"height: 14px\">\n<td style=\"height: 14px;width: 37.0625px\">P3.7<\/td>\n<td style=\"height: 14px;width: 275.063px\">RD( External data memory read strobe)<\/td>\n<td style=\"height: 14px;width: 81.0625px\">17<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p style=\"text-align: center\"><strong><span style=\"text-align: initial;font-size: 1em\">Table 1.1 Port 3 Alternate functions<\/span><\/strong><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>2.Configuring ports<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">When \u20180\u2019 is written to the port, it is configured as output. To reconfigure the port as input, \u20181\u2019 must be written to port. Port0 is configured as input by writing \u20181\u2019 to port and then it can be used as input.<\/p>\n<p>&nbsp;<\/p>\n<p>Ex:\u00a0 MOV A,#0FFH ; A=FF hex<\/p>\n<p>MOV P0,A\u00a0 ; write \u20181\u2019 to port<\/p>\n<p>MOV A,P0\u00a0 ; A=P0<\/p>\n<p>MOV P2,A\u00a0\u00a0 ; P2=A<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Initially Port0 is configured as input port. First, using the immediate addressing mode the hexadecimal number FFH is moved to accumulator and all the port pins in P0 is written to 1. This statement is used to declare that the port P0 is used as the input port. Port P0 is connected to some other input device. The data received by the port P0 is sent to accumulator and then finally Port 2 is the output port in which the data stored in accumulator is delivered to port2.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Another function of Port 0 is AD0-AD7. It is used for both address and data. When connecting an 8051\/31 to an external memory, port 0 provides both address and data. Port 1 is used as input and output. Upon reset, port 1 is configured as an input port. Port 2 is also used as input or output. Upon reset, port 2 is configured as an input port. Port 2 along with P0 will provide the 16- bit address for the external memory. If 16 bit is needed for accessing the external memory then AD0-AD7 pins from Port 0 and A8-A15 pins from port 2 are combined in which port 2 contains the higher order byte and port 0 contains the lower order byte.<\/p>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-86 aligncenter\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-34.png\" alt=\"\" width=\"466\" height=\"249\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-34.png 466w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-34-300x160.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-34-65x35.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-34-225x120.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-34-350x187.png 350w\" sizes=\"auto, (max-width: 466px) 100vw, 466px\" \/><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Instructions used in single bit operation are JB and JNB. These instructions monitor a bit and make a decision depending on whether it\u2019s 0 or 1. These two instructions can be used for any bits of I\/O ports 0, 1, 2, and 3. Table 1.2 lists the single bit operating instructions. Table 1.2 lists the single bit operations.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">2.1 Access 1 or 2 bits<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">In order to access only 1 or 2 bits of the port the following commands can be used.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">CPL P0.4\u00a0;complement P0.4<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">SETB P1.4\u00a0;set only P1.4<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">CLR P2.2\u00a0; clear P2.2<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">SETB P1.0\u00a0; set bit 0 of port 1 as high<\/span><\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">The first statement CPL complements the P0.4 bit. If P0.4 bit is 1, then it is converted to 0 and if it is 0, then converted to 1. In the above example SETB functions are used for setting the corresponding bits P1.0 and P1.4 to 1. CLR command will clear the particular bit.<\/span><\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>2.2 Configuring port pin to generate square wave<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Following assembly code helps to generate a square wave at pin P1.3<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">LOOP: SETB P1.3\u00a0\u00a0\u00a0\u00a0\u00a0 ; p1.3=1<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">LCALL DELAY\u00a0\u00a0 ;delay subroutine<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">CLR P1.3\u00a0 \u00a0 ;p1.3=0<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">LCALL DELAY<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">SJMP LOOP<\/span><\/p>\n<\/div>\n<div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-87 aligncenter\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-35.png\" alt=\"\" width=\"344\" height=\"184\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-35.png 344w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-35-300x160.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-35-65x35.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-35-225x120.png 225w\" sizes=\"auto, (max-width: 344px) 100vw, 344px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">For generating the square wave, the port is set to 1 for some period of time and then set to zero for the same time. Then a square wave can be generated. If the delay is changed, then the square wave becomes rectangular. Initially the port P1.3 is set to 1 using the SETB operation. LCALL is the long call which is the delay subroutine call, the pin P1.3 becomes 1 for certain period of time and then that pin is cleared using the CLR command. This pin maintains zero state for the same time and then using the control statement short jump, the loop continues and the square wave is generated.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>3. Sample Programs<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>3.1 A switch is connected to pin P1.7. Write a program to check the status of Switch and perform the following:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>(a)\u00a0<\/strong><strong>If SW=0, send letter \u2018N\u2019 to P2<\/strong><\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><strong>(b)\u00a0<\/strong><strong>If SW=1, send letter \u2018S\u2019 to P2<\/strong><\/p>\n<\/div>\n<p><strong>\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-88 aligncenter\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-36.png\" alt=\"\" width=\"257\" height=\"165\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-36.png 257w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-36-65x42.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-36-225x144.png 225w\" sizes=\"auto, (max-width: 257px) 100vw, 257px\" \/><\/strong><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>SETB P1.7\u00a0 ;make P1.7 an input<\/p>\n<p>AGAIN:JB P1.7,OVER\u00a0 ;jump if P1.7=1<\/p>\n<p>MOV P2,#\u2019N\u2019\u00a0 ;SW=0, issue \u2018A\u2019 to P2<\/p>\n<p>SJMP AGAIN\u00a0 ;keep monitoring<\/p>\n<p>OVER: MOV P2,#\u2019S\u2019\u00a0 ;SW=1, issue \u2018S\u2019 to P2<\/p>\n<p>SJMP AGAIN\u00a0 ;keep monitoring<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Initially the pin P1.7 is set to 1 which indicates that this pin is considered as the input pin. Then the condition of JB becomes true hence it goes to the loop OVER, the byte &#8216;S&#8217; is sent to the output port P2. Then using the SJMP command the AGAIN loop continues. If the switch is pressed it means the pin P1.7 becomes 1, then the condition fails. Hence the byte &#8216;N&#8217; is sent to the port P2. Likewise the loop is executed continuously. If the switch is pressed the byte &#8216;S&#8217; is sent to the output port P2, if it is not pressed then the byte &#8216;N&#8217; is sent to the output port P2.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>3.2 Write a program to perform the following:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>(a)\u00a0\u00a0 <\/strong><strong>Keep monitoring switch (at) P0.1 until it becomes high<\/strong><strong>\u00a0<\/strong><\/p>\n<p><strong>(b)\u00a0\u00a0 <\/strong><strong>When P0.1 becomes high, Light LEDs connected at port 2<\/strong><\/p>\n<p><strong>(c)\u00a0\u00a0 <\/strong><strong>Send a low-to-high (L-to-H) pulse to P1.2 to sound buzzer<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-89 aligncenter\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-37.png\" alt=\"\" width=\"319\" height=\"204\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-37.png 319w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-37-300x192.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-37-65x42.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-37-225x144.png 225w\" sizes=\"auto, (max-width: 319px) 100vw, 319px\" \/><\/p>\n<p>SETB P0.1 ;make P0.1 as input (switch)<\/p>\n<p>MOV A,#FFH\u00a0\u00a0\u00a0 ;A=11111111<\/p>\n<p>AGAIN: JNB P0.1,AGAIN ; get out when P0.1=1<\/p>\n<p>MOV P2,A ;Light LEDS by sending 1s to P2<\/p>\n<p>CLR P1.2 ;make P1.2 low<\/p>\n<p>SETB P1.2 ;make 01.2 high &#8211; L-to-H to sound buzzer<\/p>\n<p>SJMP AGAIN<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Initially the bit P0.1 is set as input port. Then the hexadecimal value FFH is stored in Accumulator. The jump condition fails and the Accumulator value is sent to port P2. Then the port P1.2 is cleared and it is set again for giving the low to high pulse to the port P1.2, then the alarm will ring. If the switch is pressed the LED&#8217;s connected to P2 will glow and the alarm will start ringing.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">4. Summary<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: 1em\">In this lecture pin diagram of 8051 controller is discussed. Introduction to pins and the ports of 8051 controller has been given. Some assembly programs are also written for handling pins and ports of controller.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">5. References<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">1.The 8051 Microcontroller and Embedded Systems Using Assembly and C Second Edition Muhammad Ali Mazidi, Janice Gillispie Mazidi and Rolin D. McKinlay.<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">2. http:\/\/what-when-how.com\/8051-microcontroller\/pin-description-of-the-8051\/<\/span><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong>Supporting &amp; Reference Materials<\/strong><\/p>\n<ol>\n<li>The 8051 Microcontroller and Embedded Systems Using Assembly and C Second Edition Muhammad Ali Mazidi, Janice Gillispie Mazidi and Rolin D. McKinlay.<\/li>\n<li>http:\/\/what-when-how.com\/8051-microcontroller\/pin-description-of-the-8051\/<\/li>\n<\/ol>\n","protected":false},"author":2,"menu_order":8,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":[],"pb_section_license":""},"chapter-type":[],"contributor":[],"license":[],"class_list":["post-79","chapter","type-chapter","status-publish","hentry"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/chapters\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/wp\/v2\/users\/2"}],"version-history":[{"count":5,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/chapters\/79\/revisions"}],"predecessor-version":[{"id":441,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/chapters\/79\/revisions\/441"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/chapters\/79\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/wp\/v2\/media?parent=79"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/chapter-type?post=79"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/wp\/v2\/contributor?post=79"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/wp\/v2\/license?post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}