MCU external program memory data memory operation command

Publisher:不见南师久Latest update time:2012-09-04 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Note: The operation commands of the microcontroller's off-chip program memory and data memory are different from the commonly referred to memory, and are different from the AT24C02 of the I2C bus and the SPI protocol. They refer to the use of a dedicated interface circuit, using the "three-bus" method of the P0 port, P2 port address bus and control line to access. When programming, the difference from accessing the internal program memory and data memory is: 1. For the external program memory, it is the same as the internal one, and the program does not need to be changed. 2. For the off-chip data memory, the assembly needs to use MOVX DPTR or something, which I don't understand. The relevant parts of the C language, such as: variable keywords: pdata xdata is the off-chip data memory type. The register address of the transmitted off-chip data must also be transmitted according to the actual transmission, and there is no other difference. There is no special register to be operated deliberately. .

Before designing the off-chip program memory, the level of the EA pin must be determined first.

EA=0, the microcontroller only accesses the external program memory. For the 8031 ​​microcontroller, this pin must be grounded. EA=1, the microcontroller accesses the internal program memory. For the 8XX51 microcontroller with internal program memory, this pin should be connected to a high level, but if the address value exceeds the 4KB range, the microcontroller will automatically access the external program memory.

After setting the EA, the microcontroller automatically executes in the order set by the program.

In programming, there is no need for special statements to specify that the external program memory is called. For example, if EA is set to a high level, the program will automatically transfer to the external program memory after executing the program memory instructions on the chip, without the need for special commands. This is what is called the program memory is uniformly addressed inside and outside the chip, while the data memory is treated separately with Mov and Movx.

But the main thing you need to know is the process of the program reading the off-chip instruction code: first addressing, then fetching. The microcontroller will first send a selection address (PC value) to P2 and p0 according to the value of PC, and then read the code from the off-chip program memory. Because the value of PC is generally continuous, this requires the off-chip program memory space to be distributed continuously, which is different from the data memory. If it is not distributed continuously, a special line number must be used to change the value of PC so that it can correspond to the distribution of the off-chip program memory.

In short, remember the three-bus transmission method, first address, then transmit data, controlled by the control bus

Memories generally have WR, RD, CS lines as well as address ports and data ports. Some data and address ports are multiplexed, while others are separate. Looking at the datasheets of these memories will help you understand how to access their internal data. For example, to read the data in the external RAM address 0x0001 (assuming there is such an address), then set WR high, CS low, and output 0x0001 on the address line. Then the CPU data line can wait for the required data. In this case, the CPU's I/O is just an ordinary I/O port. However, general microcontrollers and ARMs can select I/O as the access port for external memory. At this time, as long as you connect the corresponding lines according to the instructions in the datasheet, the CPU can automatically cooperate in timing according to your instructions, making access to external devices just like accessing internal RAM. The advantage of this is that it saves CPU time.

The C language instruction to set the address 0x0001 to 0x55 is
(*(unsigned char*)0x0001)=0x55; // (here the data width is assumed to be 8 bits)
If the function selected by the I/O port is the external data address bus and the hardware is connected, then this instruction is to read and write the corresponding address of the external memory.

It is worth mentioning that the access speeds of various types of storage devices are different. Therefore, if the program is executed in an external device, the execution time will be quite different. For example, the execution speed of a for loop placed in external RAM and external flash may differ by 3 times.

First, the microcontroller uses a three-bus structure to transfer data. Address bus, data bus, and control bus. The process of transferring data is to address first and then transfer data. That is, first send an address information (the microcontroller writes the address information to the bus), and the register (program memory or data memory) writes the data to be read by the microprocessor to the bus according to this address, and the microprocessor reads the data. The whole process is controlled by the control bus. Therefore, each read data is operated on the register corresponding to the address, and no confusion will occur. When writing data, it is the same, first address, then write data, and the data is written to the register corresponding to the address just addressed.

Second, the program memory and data memory have different selection signals. They are selected at different times in one instruction cycle, so there will be no confusion.

Third, the selection pins are different. For example, the external data memory uses the 6th and 7th pins of P3 as the selection signal, and the program memory uses PSEN as the selection signal. They are connected to the selection pins of their respective devices, so there will be no confusion.

Fourth, the instructions are different. Take assembly instructions for example. MOV is used to transfer data from program memory, and MOVX is used to transfer data from data memory (to the outside of the chip).

In short, remember the three-bus transmission method: first address, then transfer data, and it is controlled by the control bus. This mode will make it easy for you to understand this.

The p2 and p0 of the microcontroller transmit the high eight bits and low eight bits of the address respectively. At the same time, p0 also transmits data. During the high level of the timing signal ALE, the address information is locked. /PSEN is used to select the program memory. During the low level of /PSEN, the program code is transferred to the program memory. /WR and /RD are used to select the data memory, that is, the data is transferred to the data register during the low level of /WR and /RD. However, /PSEN, /WR and /RD become low levels at different times, and there is no overlapping part. In other words, when /WR and /RD become low levels, /PSEN has already returned to high levels. Of course, the data information transmitted from the P0 port will only be transmitted to the data memory, because the program memory is no longer in the selected state! From the surface, they are all transmitted from the p0 port, but there will be no confusion because the time of selecting the device is different. Of course, I am talking about the situation of the off-chip program memory and data memory. In fact, it is the same for the chip. It is still the control method of the three buses, so that they are selected at different times without conflict.

Take a look at a circuit diagram of a single-chip microcomputer. You will find that p0 is connected to 74LS373, 8155 or 8255 or keyboard or digital-to-analog converter, etc. The 8155 or 8255 or keyboard or digital-to-analog converter is treated as a data memory by the single-chip microcomputer. 74LS373 is mostly connected to the program memory. Then, isn't the signal sent by p0 received by both? Note that ALE is connected to the G interface of 74LS373, which is used to latch the address, and PSEN is sometimes used and sometimes not. WR and RD are connected to the selection interface of the data memory. Because the signals of WR and RD do not overlap with ALE in time, the signal of p0 will not be received by the program memory and the data memory at the same time. This is an example, and the specific situation needs to be analyzed specifically.

Keywords:MCU Reference address:MCU external program memory data memory operation command

Previous article:51 MCU infrared receiving decoding program
Next article:Matrix keyboard of single chip microcomputer

Recommended ReadingLatest update time:2024-11-17 00:37

Design of a controllable imaging system based on 51 single chip microcomputer
0 Introduction The optical imaging system is an important tool for converting optical information into electronic information that is easier for people to process. It is particularly important for intelligent monitoring, medical diagnosis and consumer electronics. With the complexity of the imaging system functions,
[Microcontroller]
Design of a controllable imaging system based on 51 single chip microcomputer
Philips 51LPC series microcontroller is used to control AC motors
    Abstract: The 51LPC series of microcontrollers developed by Philips use the double-speed 80C51 core, which has low cost, low power consumption, low electromagnetic interference (EMI), high anti-interference and built-in power Brownout detection, analog functions, UART, I2C and A new generation of microcontroller
[Industrial Control]
Design of On-site Power-free Electronic Password Lock Based on 51 Single-Chip Microcomputer
O Introduction At present, there are many electronic locks based on IC card design on the market, which are widely used in hotels, apartments, warehouses, schools and other places. These occasions can provide good DC or AC power, and the control part of the electronic lock can easily obtain stable power for a lo
[Microcontroller]
Design of On-site Power-free Electronic Password Lock Based on 51 Single-Chip Microcomputer
51 microcontroller learning: LED flashing experiment
Experiment name: LED flashing experiment Wiring instructions: Experimental phenomenon: The D1 indicator light of the "LED module" flashes after downloading the program Notes: *********************** *************************************************** ****************/ #include "reg52.h" typedef unsigned int u16; //Red
[Microcontroller]
MCU clock cycle machine cycle
Clock cycle The clock cycle is also called the oscillation cycle. It is defined as the inverse of the clock pulse and is the most basic and smallest unit of time in a computer. Machine cycle In a computer, for ease of management, the execution of an instruction is usually divided into several stages, and each stage c
[Microcontroller]
ARM7 microcontroller (learning) - (VII), pulse width modulation PWM - 02
Well, this experiment is also relatively simple~~ Use the buttons to adjust the PWM output (the cycle remains unchanged here, only the duty cycle is changed)~~ 7. Pulse Width Modulation (PWM) VII. (02) Adjustable PWM output (The following program has general operation steps. I did not experiment with the double-edge c
[Microcontroller]
ARM7 microcontroller (learning) - (VII), pulse width modulation PWM - 02
Design of Digital Multimeter Based on Single Chip Microcomputer
1DS1629 structure characteristics and working principleDS1629 is a chip designed for digital temperature measurement, and also has the function of real-time clock/calendar. The wide power supply range and extremely low power consumption of DS1629 are very suitable for battery-powered applications. Its clock func
[Microcontroller]
Design of Digital Multimeter Based on Single Chip Microcomputer
MCU program memory ROM
  The English abbreviation of single-chip program memory is ROM. The data stored in ROM is generally written in advance before being installed in the whole machine. It can only be read out during the operation of the whole machine, and it cannot be quickly and conveniently rewritten like random access memory. The data
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号