 Myself, Sudhakar Barbade, Assistant Professor, Electronics and Telecommunication Engineering Walsh and Historic Technology, Solapur. In continuation with the previous lecture, today 8051 I.O. Programming Part 2, we will discuss. In this first learning outcome, at the end of this session, students will be able to describe key features of 8051 I.O. ports and its programming, contents. Here we will see port 2 and port 3 features and its programming. First, we will see what is the dual role of port 2. Port 2 can be used along with P0, P0 in the previous lecture we saw that it can be used as an address and data, address of lower 8 bits and data that is D0 to D8. So port 2 can be used along with P0 to provide 16-bit address for the external memory. That means port 2 provides the higher byte of address of 16-bit address. When 8051 is connected to external memory, P2 is used for the upper 8 bits that is A8 to A15 of the 16-bit address and while using this as an address, it cannot be used for I.O. programming. Now we will see programming of port 2. First we will see how it can be configured as an input port. In the following code port 2 is configured first as an input port by writing 1's to it and then data is received from the port and sent to P1. So as said earlier on reset all ports are configured as an output port but when we are using it as an input port they must be configured first. So these first two instructions move A, hash, 0, FFH and move P2, A these two instructions are used for configuring port 2 as an input port and what is done here is port 2 is read since we are configured as an input port port 2 is read into accumulator and accumulator contents are sent back to P1 continuously with this loop. So this way what happens is whatever contents of P2 is transferred to P1 with this example. Now there is a question, what is the hex code for configuring port 2 as input port? You pause the video and answer the question. You might have thought over the question port 2 is configured as an input port and the question is what will be the hex code? Since we have to write all 1's that is all 8 bits should be 1 so as to configure as input port all 8 1's means it is FFH. Now come to this programming port 2 as output port. Since there is no need of configuring a port as output port we will not do anything here configuration only what we are doing is this code will send out to port 2 the altering values 55H and AAH that is all the bits of port 2 toggle continuously. So here first 55H is moved into the accumulator and the same is out to port with some delay it is again complemented and this is in a loop after complementing we get AAH and this AAH and 55H will be send continuously through some delay. Now we will see port 3 dual role port 3 has additional function of providing some extremely important signals as shown. So these are the port 3 pins P302 P37 8 pins are there and this is what the function associated with each pin of a port 3 port 3 0th pin is having a function of RXD that means reading serial data and the here pin number is given pin number 10 is a port 3 pin 0 which can be used as an read serial data P3.1 can be used as transmitting serial data port 3.2 can be used as an interrupt 0 this is a active low signal port 3.3 is used as a again interrupt pin that is INT1 again this is a active low signal port 3.4 is used with the timer 0 TU0 means timer 0 P3.5 with timer 1 and P3.6 and P3.7 these are used as read and read and write commands to either IO devices or memory. So WR stands for writing again this is a active low signal RAD bar is for reading as we saw port 3 how it can be configured as a input port since we know already port 3 when we are using it as input port it must be configured first as an input port by writing 1s to it and then data is received from the port and sent to P1 that means whatever data received on port 3 will be sent to port 1 with this code. So first two instructions again are for configuring port 3 as a input port by writing hash 0ffh so with this port 3 is configured as an input port then port 3 is read by using this move a comma P3 instruction this is sent to port 1 again and this is in a loop so continuously whatever is there on port 3 will be sent to port 1. Here we will see how this port 3 can be configured as an output port since there is no need of specifically configuring it as an output port we will skip those two instructions which are used for configuration the following code will continuously send out to port 3 the alternating values 55h and aah so first 55h is moved into the accumulator the same contents is moved to port 3 or sent to port 3 after some delay the port accumulator is complemented and again it jumps back here the complemented value aah will be sent now to port 3 so this is in a loop so what happens is here is port 3 whatever is in port 3 is complemented every time with initial value of 55h and the other value is aah next feature of all the ports of 8051 is read modify and write in a single instruction so how this is done and what is the use of it we will see the ports in the 8051 can be accessed by the read modify write technique this feature saves many lines of code by combining in a single instruction all three actions that is reading the port modifying it and writing to the port so the following code describes it here what is done is port P1 is loaded with the immediate value 55h move P1, hash 55h this instruction loads 55h into P1 and here in the second this instruction is very important this instruction does three tasks that is reading the port modifying the value and writing back to the port so this XLR stands for XOR the contents of P1 P1 consist of 55h with immediate value 0FFH so what happens here is what P1 content that is 55h is XORed with FFH that means first port 1 is read here and that is XORed with FFH and whatever the result of XOR operation is written back into P1 port after some delay this process is repeated again so this gives the benefit of decreasing the code length another feature of ports of 8051 is it can be addressed with a single bit that is single bit addressability of the port there are times that we need to access only one or two bits of the port instead of the entire 8 bits a powerful feature of 8051 IO ports is their capability to access individual bits of the port without altering the rest of the bits in that port means here the individual port pins we can use as a input or output for example the following code toggles the bit P1.2 continuously only port one is used but entire port one is not used only port one pin two is used and that is toggled continuously so here so whatever the value of this P12 is complemented after some delay again this loop jumps back to this again it complements whatever the value and this process is repeated references the 8051 microcontroller architecture programming and applications by Kenneth Ayla and another is the 8051 microcontroller and embedded systems by Muhammad Ali Masdi so these two books I have used to prepare these slides thank you very much