 Today we will discuss 8051 IO programming, learning outcome at the end of this session students will be able to describe key features of 8051 IO ports and its programming contents. In part 1 we will discuss what are the different 8051 ports and in this lecture we will see 0 and port 1 its features and programming. If you look at the diagram 8051 has got 4 ports which are named as P0, P1, P2 and P3 and each port is of 8 pins or we can say 8 bits. Each port has dual use except P1. All the ports are used for multiple purposes except P1 and all ports are bit addressable in addition to 8 bits as a whole. That means we can use any port pin as a single entity otherwise we can use that port as a whole that is 8 bits. So these are the features of 8051 ports. All the ports upon reset are configured as output means all the port pins are ready to use as a output port when we reset the system. But to use any of these ports as an input port it must be programmed. That means we should configure first it as an input port and then we can use it for our purpose. All the ports except port 0 has internal pull up registers means port 0 does not have internal pull up registers why it does not have we will see in the next slide. But remaining all the ports have internal pull up registers so there is no need to connect external pull up registers for port 1, port 2 and port 3. But at an external pull up register of 10k is required to be connected to each pin of port 0. If you want to use port 0 for IO it must be connected supply voltage through 10 kohm register. Each port pin of port 0 must be connected through a 10k register to VCC. This is due to the fact that P0 is an open drain P0 is an open drain circuit and the use of it we will see in the next slide. See here if you want to use port 0 we can look at this port pins are there P0.0 to P0.7. This is all the 8 bits of port 0 which are used as either port 0 or it can be used for other purpose also that we will see in the next slide. But when we are using it as a port 0 each port pin must be connected through a 10k register to VCC. So this is what exception to only port 0 for the remaining ports there is no need to connect this external pull up register they can be used directly. But here why this is not done internally as of other ports because open drain output is used to interface different families of devices that have different operating logic voltage levels or to control external circuitry that requires a higher voltage. That means if you want multi logic devices in a circuit we can use this port 0 to connect to another device of different logic level. So this is possible only with port 0 with port 1, 2 and 3 we cannot connect the devices of other logic levels. Now as we discussed earlier port 0 has dual role except that means port 1 does not have any other role it only acts as a IOPort but remaining ports has dual role. So what is the dual role of port 0 we will discuss here. So this is what we can say a memory this is a latch and this is our processor. So port 0 pins are connected to memory directly as well as it goes to the latch and AL is used to latch these port 0 contents. So how this is done we can see here the 8051 multiplexes address and data through port 0 to save pins. So this port 0 pins carries address as well as data that is 80 to 87 but when this will be data and when this will be address that is decided by the pin ALI. So ALI indicates if P0 has address or data with the help of latch this latch. So when this is 0 the data is transferred between this memory and processor and when this AL is 1 it has address which is latched here and this address that is 80 to 87 is provided to the memory. So this port 0 carries data as well as address. Now we will see the programming of port 0 how it can be used there are only two possibilities one is we can use it as an input port or we can use it as an output port. So first we will see how it can be used as an input port. So in the following code what is done is port 0 is configured first as an input port by writing 1's to it and then data is received from port and sent to port 1. So first this port must be configured as an input port by writing 1's that means 8 1's to it and then we can use that port. So here by using this move instruction move A comma hash 0 FFH means we are configuring this port as an input port but this is moved first into the accumulator and then this accumulator content is moved to the port 0 that means port 0 now is returned with all 1's or we can say in hexadecimal FFH. So now with this these two instructions what has happened is port 0 is configured as an input port. Now since it is configured as an input port it must be read so port 0 is read by using this instruction move A comma P0 means port contents are transferred to the accumulator then accumulator contents are transferred to P1 as we said earlier we are sending port 0 contents to port 1 contents and this is in a loop. So whatever data is available on port 0 is sent to port 1 with this example. Now what is the dual role of port 1? You pause the video and answer the question you might have thought over the previous question and the answer is port 1 does not have any dual role it is only used as an IU port. Here we will see port 0 as an output port as again discussed earlier upon reset all ports are configured as output there is no need to specifically configure it as output port. This code the following code will continuously send out to port 0 the alternating values FFH and AEH. So look at this this 55H is loaded into accumulator again accumulator content that is 55H is moved to P0 after some delay this is complimented accumulator is complimented and after complimenting 55H we get AAH that is again send this is a loop so that AAH we will now send to the P0. So this way 55H and AAH will be sent with some delay to port 0 continuously. Now programming port 1 as input port we have seen with port 0 similarly here we should first configure it as an input port by writing 1's to it and then this can be used as an input port. Here what is done is data is received from the port and saved in R7 you can look at whatever these two instructions are for configuring port 1 as an input port and whatever port is that means content of port 1 is read into the accumulator and accumulator contents are sent to R7 that means here port contents are sent to R7 continuously. Lastly we will see programming of port 1 as an output port as we discussed there is no need to specifically configure it as an output port and this code will send to port 1 continuously that 55H and its compliment AAH with some delay these are references for my presentation the 8051 microcontroller architecture programming and applications by Kenneth Ayla and another is 8051 microcontroller and embedded systems by Muhammad Ali Mazdi.