51 microcontroller special function register operation process

Publisher:dfdiqcLatest update time:2023-08-09 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  We must be patient with the unique program syntax of the 51 microcontroller and the basic operating process of the Keil software.

  We mainly use C language to program microcontrollers, and some microcontrollers have a few very special and unique programming sentences. The 51 microcontroller has them. I will introduce two of them first.


  The first sentence is: sfr P0 = 0x80;

  The keyword sfr is unique to the 51 microcontroller. Its function is to define a special function register of the microcontroller. There are many small modules inside the 51 microcontroller. Each module lives in a room with a unique room number. At the same time, each module has 8 control switches. P0 is a functional module that lives in the room 0x80. We set the 8 switches of this module inside P0 to make the 8 IO ports of P0 of the microcontroller output high level or low level. There are many registers inside the 51 microcontroller. If we want to use them, we must make an sfr statement in advance. However, Keil software has pre-written all these statements and saved them in a special file. If we want to use them, we only need to add a line of #include at the beginning of the file. This will be explained in detail later.


  The second sentence is: sbit LED = P0^0;

  This sbit is the definition of one of the eight switches in the SFR just mentioned. After passing the second sentence above, in the future, as long as we write LED in the program, it will represent the P0.0 port (the "^" symbol is above the numeric key 6). Note that this P must be capitalized, which means that we P0.0 was given a more vivid name called LED.


  After understanding these two sentences, let's take a brief look at the special function registers of the microcontroller. Please note that each type of microcontroller will be equipped with a data sheet (Datasheet) written by the manufacturer, so let’s take a look at the STC89C52 data sheet. From pages 21 to 24, they are all introductions and addresses of special function registers. Mapping list. Before we use this register, we must analyze the address of this register. Are there too many colorful things that you can’t remember? This is irrelevant and you don’t need to remember it. Just understand it. I will explain most of them to you step by step later. When you need to use some of them, you can come and check them yourself. A manual is enough. Doing skills is not just for exams. You can read the manual at any time to find the materials you need.


  As shown in Figure 2-7, it is an interception of the table at the bottom of page 22 of the manual.

  51 microcontroller special function register operation process

  Figure 2-7 IO port special function register

  Let's take a look at this table. Among them, the P4 port STC89C52 expands the standard 51. Let's ignore it first and only look at the previous four P0, P1, P2, and P3. Each P port itself has 8 control ports. We can refer to our development board schematic diagram or Figure 2-1 to see that our microcontroller has a total of 32 IO ports (IO, Input and Output, respectively, input and output).


  Among them, the address of the P0 port address is 0x80. There are a total of 8 IO port control bits from 7 to 0, followed by a Reset Value. This is very important. It is a parameter that we must look at when looking at the register. There are 8 controls. The bit reset values ​​are all 1.


  This is to tell us that every time the microcontroller is powered on and reset, the value of all pins is 1 by default, which is high level. We must also fully consider this issue when designing the circuit.


  So for the two sentences above, when we write sfr, we must write them according to this address (Add) in the manual. When we write sbit, we can directly take out one of the bits in a byte. When we program, there are also ready-made header files with register addresses written in them. We can just include the header file directly, and there is no need to write them one by one.


Reference address:51 microcontroller special function register operation process

Previous article:How does Keil C51 support double data pointers and what are the special requirements?
Next article:Failure analysis of 51 microcontroller programming chip failure to work

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号