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.
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
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- DSP's various lords
- Unboxing K210 and ESP32S2
- What is the name of this insulation sheet?
- cpld realizes phase-locked loop frequency synthesis
- Power conversion type analysis
- Synplify Tool User Guide.pdf
- STM32 A certain function is put into RAM and runs without any phenomenon
- [Help] Pingtouge scenario-based Bluetooth Mesh node write address 0x failed! Write registers fail...
- C6678 DSP program debugging problem
- [First batch of finalists] 2022 Digi-Key Innovation Design Competition