Access to external program memory uses the signal (Program store enable) as the read strobe. Access to external data memory uses (alternate function of P3.7 and P3.6).
For external program memory, always 16 bit address is used. For example -
MOVC A, @ A+DPTR
MOVC A, @ A+PC
Access to external data memory can be either 8-bit address or 16-bit address -
8-bit address- MOVX A, @Rp where Rp is either R0 or R1
MOVX @Rp, A
16 bit address- MOVX A,@DPTR
MOV X @DPTR, A
The external memory access in 8051 can be shown by a schematic diagram as given in fig 7.1.
Fig 7.1 Schematic diagram of external memory access
If an 8-bit external address is used for data memory (i.e. MOVX @Rp) then the content of Port-2 SFR remains at Port-2 pins throughout the external memory cycle. This facilitates memory paging as the upper 8 bit address remains fixed.
During any access to external memory, the CPU writes FFH to Port-0 latch (SFR). If the user writes to Port-0 during an external memory fetch, the incoming byte is corrupted.
External program memory is accessed under the following condition.
Whenever is low, or
Whenever PC contains a number higher than 0FFFH (for 8051) or 1FFF (for 8052).
Some typical use of code/program memory access:
External program memory can be not only used to store the code, but also for lookup table of various functions required for a particular application. Mathematical functions such as Sine, Square root, Exponential, etc. can be stored in the program memory (Internal or eternal) and these functions can be accessed using MOVC instruction.
Fig 7.2 Program memory showing the storage of lookup table