MCU memory and registers

Publisher:码农创想家Latest update time:2011-09-23 Keywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The memory of the microcontroller is divided into two types: program memory ROM and data memory RAM. These two types of memory are strictly distinguished in use and cannot be mixed. The program memory stores program instructions, constants, tables, etc.; while the data memory stores buffer data.

The memory structure of MCS-51 microcontroller has three parts: one is program memory, the second is internal data memory, and the third is external data memory. The memory of MCS-51 microcontroller can be divided into five categories: program memory, internal data memory, special function registers, bit address space, and external data memory.

Program Memory


Programs are a series of commands that control the actions of a computer. The microcontroller only recognizes machine instructions consisting of "0" and "1" codes. For example, the command MOV A, #20H written in mnemonics is replaced by the machine-recognized code 74H, 20H: (written in binary, it is 01110100B and 00100000B). Before the microcontroller processes a problem, the compiled program, table, and constant must be compiled into machine code and stored in the microcontroller's memory, which is called program memory. The program memory can be placed inside or outside the chip, or it can be set inside and outside the chip at the same time. Since the PC program counter is 16 bits, the program memory can use a 16-bit binary address. Therefore, the maximum address of the internal and external memory can be from 0000H to FFFFH. 8051 has 4k bytes of ROM inside, which occupies the lowest 4k bytes from 0000H to 0FFFH. At this time, the address number of the program memory expanded outside the chip should start from 1000H. If 8051 is used as 8031, and you do not want to use the 4k ROM inside the chip, and use all the external memory, the address number can still start from 0000H. However, at this time, the {31}th pin (ie, EA pin) of 8051 should be kept at a low level. When EA is high, the user uses the internal ROM in the range of 0000H to 0FFFH. When it is greater than 0FFFH, the microcontroller CPU automatically accesses the external program memory.


Data storage


The data memory of the microcontroller is composed of read-write memory RAM. Its maximum capacity can be expanded to 64k, which is used to store real-time input data. There are 256 units of internal data memory in 8051, of which 00H~7FH is the internal random access memory RAM, and 80H~FFH is the special register area. In actual use, the internal memory should be fully utilized first. From the perspective of use, it is very important to understand the structure and address allocation of the internal data memory. Because they will be used frequently in the future when learning instruction systems and program design. The address of the internal data memory of 8051 is from 00H to FFH, with a total address space of 256 bytes. The space is divided into two parts, of which the address of the internal data RAM is 00H~7FH (that is, 0~127). The address used as a special function register is 80H~FFH. In these 256 bytes, there is also a so-called "bit address" area, which can be addressed not only by byte, but also by "bit". For those data that need to be operated on by bit, they can be stored in this area. There are four groups of working registers arranged from 00H to 1FH, each group occupies 8 RAM bytes, recorded as R0~R7. Which group of registers to use is selected by RS1 and RS0 in the above-mentioned flag register. Different binary numbers can be placed in these two bits to select different register groups.


Special Function Registers


The address range of the special function register (SFR) is 80H~FFH. In MCS-51, except for the program counter PC and four working register areas, the remaining 21 special function registers are all in this SFR block. Five of them are double-byte registers, which occupy a total of 26 bytes. The symbols and addresses of each special function register are shown in Appendix 2. Those with * are bit addressable. The special function register reflects the status of 8051, and is actually the status word and control word register of 8051. The CPU PSW is a typical example. These special function registers are generally divided into two categories, one is related to the pins of the chip, and the other is used for controlling the functions on the chip. The special function registers related to the chip pins are P0~P3, which are actually 4 eight-bit latches (one for each I/O port). Each latch is attached with a corresponding output driver and input buffer to form a parallel port. MCS-51 has four such parallel ports, P0~P3, which can provide 32 I/O lines, each of which is bidirectional and most of them have a second function. Among the other registers used for chip control, the functions of accumulator A, flag register PSW, data pointer DPTR, etc. have been mentioned before, and the functions of other registers will be further introduced in the relevant parts later.

Address Space

To ensure that multiple applications can be in memory at the same time and do not interfere with each other, two problems need to be solved: protection and relocation. Let's look at a primitive solution to the former, which was used on the IBM 360: mark memory blocks with a protection key, and compare the key of the executing process with the protection key of each memory word it accesses. However, this method itself does not solve the latter problem, although this problem can be solved by relocating the program when it is loaded, but this is a slow and complicated solution.

A better approach is to create a new memory abstraction: the address space. Just as the concept of a process creates an abstract CPU to run programs, the address space creates an abstract memory for programs. An address space is a set of addresses that a process can use to address memory. Each process has its own address space, and this address space is independent of the address space of other processes (except in some special cases where processes need to share their address space).

The concept of address space is very general and appears in many contexts. For example, in the United States and many other countries, a local telephone number is usually a 7-bit number. Therefore, the address space for telephone numbers is from 0 000 000 to 9 999 999, although some numbers are not used, such as those starting with 000. As the number of cell phones, modems, and fax machines increased, this space became less and less available, resulting in the need to use more digits. The address space of the Pentium's I/O ports is from 0 to 16 383. IPv4 addresses are 32-bit numbers, so their address space is from 0 to 232-1 (there are also some reserved numbers).

Address spaces do not have to be numeric. A set of ".com" Internet domain names is also an address space. This address space is made up of all strings of 2 to 63 characters followed by ".com". The characters that make up these strings can be letters, numbers, and hyphens. By now you should have understood the concept of address space. It is very simple.

External Memory

Floppy disks, hard disks, CDs, and USB flash drives are all external storage devices. From the working principle of von Neumann's stored program and the composition of computers, computers are divided into arithmetic units, controllers, storage devices, and input/output devices. The storage device here refers to the memory, and the hard disk belongs to the input/output device. The program code and data required for CPU calculations come from the memory, and the things in the memory come from the hard disk. Therefore, the hard disk does not deal directly with the CPU. The hard disk is an external storage device relative to the memory. The storage device is used to store data. The memory has cache and memory, which is the internal storage of the computer. The external storage device is an external storage device similar to the USB flash drive. The internal storage device is fast and expensive, and has a small capacity. The data in the memory will be lost after a power outage. The unit price of the external storage device is low, the capacity is large, the speed is slow, and the data will not be lost after a power outage.

Keywords:MCU Reference address:MCU memory and registers

Previous article:Addressing mode of microcontroller
Next article:Commonly used chips for single chip microcomputers

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

Compensation method based on high-precision temperature measurement of single-chip microcomputer
For a long time, people have mostly used conventional measurement methods to measure temperature. When the detection accuracy is required to be high, the conditioning circuit is complex and the number of A/D bits is high, which makes the design system cost high and difficult to popularize. With the development of el
[Microcontroller]
MCU controlled 0-30V adjustable power supply
CPU circuit diagram Display circuit Control board circuit diagram Program  #include iotiny24.h // Include model header file   //#include iot24v.h #include iomacro.h // Include "bit" operation header file #include ctype.h #include math.h #include stdio.h #include stdlib.h #include string
[Microcontroller]
MCU controlled 0-30V adjustable power supply
51 single chip microcomputer reads out the two-digit BCD dial program
Question: I made a small design using AT89C2051, where P1 is connected to a two-digit BCD dip switch, P3.2 is connected to a switch, and P3.3 is connected to a relay. The specific connection method of the two-digit BCD dip switch is that the common end is connected to P1.1 and P1.2, and 8421 is connected to P1.3~P1.6
[Microcontroller]
The role of single chip microcomputer in vehicle alcohol detection system
introduction Nowadays, the harm of drunk driving is obvious to society, and the national government has also promulgated relevant punishment regulations to prohibit these behaviors, such as revoking the driver's license for six months, deducting points, imposing fines, etc. At present, almost all countries
[Microcontroller]
The role of single chip microcomputer in vehicle alcohol detection system
Notes on using TMR1 of pic16f877 microcontroller
1. Structure 1. TMR1 can be used as a general timer and counter, and can also use the built-in low-frequency time base oscillator to realize the real-time clock RTC function; through the use of TMR1 and CCP modules, TMR1 can also realize input capture and output comparison functions. TMR1 is a 16-bit readable and
[Microcontroller]
This is how our teacher teaches microcontrollers
Seeing that many netizens are asking how to improve their abilities, I would like to talk about my own learning process. I majored in Communication Engineering in the Computer Department, and my main development direction was in computer network software, which can be seen from my graduation project topic “Hotel Room
[Microcontroller]
Demonstration of C language program based on AVR microcontroller I/O
 //Program flow: all on->all off->PD advances every other step->all on->all off->PD advances every other two steps->all on->all off->PB all on->pb0 set->pb0 cleared->PB0 inverted->all off->(loop)        // Target : M8    // Crystal: 11.059Mhz        #include     #include         //Start all on    void port_ini
[Microcontroller]
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号