 Hello, Myself Pravindra Chauhan, Assistant Professor, Department of Electronics Engineering, Vulture and District of Technology, Solapur. So in this session, we will discuss how to write the program to access the data from the external read-write memory. So at the end of this session, student will be able to write the assembly program with the data stored at external data memory. So in this session, we will discuss the interfacing of data memory with microcontroller 8051. Then how to write the instructions to read and write the external data memory. Then how to write the 8051 assembly program to transfer a block of data from the external data memory. So this is the data memory interface to the 8051 microcontroller. Now the size of the memory shown is here the 8k byte. So to access the 8k memory the 13 address bits are required that is from A0 to A12. So the port 0 is providing the lower address bits as well as the data bits. So it is having the alternate function of AD0 to AD7. Then the port 2 is providing the higher 8 bits of the 16 bit address that is from A8 to A15. So out of this the from P2.0 to P2.5 that is A8 to A12 are directly connected to the higher address pins of the memory and lower 8 address bits to the A0 to A7 pins and then the data pins that is the port 0 is connected to the data pins of the external memory. Now this port 0 is providing both address as well as the data. So this address and data are separated out here by making the use of this latch signal. And then whatever the remaining 3 address bits A13, A14 and A15 are used to select or to enable this particular memory chip for the desired address range. Now decoding logic will be changed according to your address range. And the read bar from the 8051 goes to the read pin of the memory. Similarly write signal from the 804 will go to the write pin of the data memory. Now when the data transfer between the external memory and the 8051 is taking place. This data transfer happens only between accumulator and the external memory. So write the instruction to read a byte from external data RAM from address 100H and to store at an external address at 200H. Since one byte is stored at 100H you store now or you transfer that byte at address 200. Now this is the memory to memory data transfer. Now this is not possible memory to memory data transfer is not possible. So first you have to read the data from external memory into the accumulator and then from accumulator you have to transfer again to the external memory. Now to access the external memory, external data memory in 8051 only one pointer is provided which is called as DPTR data pointer register. So here first load the DPTR register with your source address that is the 100H. Then read your source byte which is stored at 100 into the accumulator. Then you load the DPTR register with your destination address that is the 200 and then at 200 you transfer your source byte where it is now it is in the accumulator. So in this fashion we can read the data from external memory here the first two instructions and the next two instructions are used to write the data from accumulator to the external memory address pointed by DPTR register. Now we will write the one program 8051 assembly program. So write the 8051 assembly program to transfer an array stored at 40H in on chip data memory to 4000H in off chip data memory and assume the 10 bytes in an array means the 10 bytes are stored from internal memory at address 40H onwards. So you have to transfer these 10 bytes into the external memory from address 4000H. So how do how will you implement this? So data transfer happens only between accumulator and the external memory. So first you read the byte from the source array into accumulator. So you take the first element of your source array into the accumulator then you write that element into the destination address which is in the external memory and repeat the same steps for all the elements in the source array. So for that the program we can write like this. Now initially I had used the one directive which is called the equate and these are the identifier I am using source array equate with the value 40 means this is our the source address this is the destination address 4000 and these are number of elements are equal to 10 and ORG tells the simulator you start writing this program from address 000. So first R0 register is loaded with the source address that is the 40. So R0 we are using as a pointer to the memory pointer to the source array DPTR is used to point your destination array which is in the external data memory and then R2 we are using as a counter to count how many bytes are transferred. So first read the first byte from your source array into the accumulator. So move A at the rate R0 in R0 currently the 40 is there. So whatever the byte stored at address R0 will come into the accumulator. Then you transfer that first element in the external memory whose address is in DPTR. So currently in DPTR the 4000 is there. So your first byte from address 40 will transfer into the external data memory at address 4000. So increment your the source pointer increment the destination pointer to proceed further. So increment your R2 register to monitor how many bytes are transferred. If it is not equal to 0 again do the same thing. So this loop will execute how many times 10 times. So 10 times what you are doing you are reading your source byte you are transferring into the destination address and you are incrementing both the pointer source pointer and destination pointer. Now write the 8051 assembly program to transfer an array stored at 4000 H to 5000 H in off chip data memory. Means now your source array and the destination array is in the external memory. And assume there are 10 bytes in an array. So one thing you are already knowing that the direct memory to memory data transfer is not possible. So read the source byte into the accumulator. Then write the byte from accumulator into destination array. But here the two memory pointers are required to point the source and the destination addresses. And we are having only one pointer register that is the DPTR. Now here there is need to swap the source and destination addresses. While reading the data DPTR should have the source address in it. And while writing the byte destination address must be in the data pointer register. So the swapping of source and destination address is to be required. Now this swapping can be done in number of bits. So references used for this the 8051 and embedded C programming by Majidi and the microcontrollers by Ajay Deshmukh.