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, the P2 port address bus and the 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 difference in other aspects. 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 address 0x0001 to 0x55 is
(*(unsigned char*)0x0001)=0x55; //(Here we assume the data width is 8 bits)
If the function selected by the I/O port is the external data address bus and the hardware is connected properly, 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 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, control bus. The process of transferring data is to address first, then transfer data. That is, send an address information first (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 this data. The whole process is controlled by the control bus. Therefore, each time the data is read, it is operated on the register corresponding to the address, and there will be no confusion. 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:Design of electronic calendar system based on single chip control technology
Next article:Analysis of the problem of controlling the on and off of diodes with keyboard based on STC microcontroller
- Popular Resources
- Popular amplifiers
- Learn ARM development(14)
- Learn ARM development(15)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Circuit short circuit protection burns out DC-DC, output 12V changes drastically to around 28V, green is the flip protection signal
- EEWORLD University ---- Matlab Machine Learning
- How embedded hardware and software systems work
- Help: How to reduce the power consumption of the solenoid valve coil
- How to write arm-poky mixed Makefile
- Inductor and capacitor selection for flyback circuit
- Single-ended input and double-ended output circuit
- When calculating the circuit branch current and component voltage, how to determine whether the selected loop group is an independent loop using the loop current method?
- Evaluation summary: Domestic FPGA Gaoyun GW1N series development board
- What is IoT technology?