Software reset of 51 MCU

Publisher:shiwanyongbingLatest update time:2016-05-20 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
    Please look at the program at the bottom first.
      This is a program for Keil software, called "pure software" reset. The so-called "pure software" means that it does not directly operate hardware and registers.
      In fact, if you don't understand hardware and assembly, you can't have this C program. Anyway, let's take a look at its true face:
      We know that 51 microcontrollers 
      can put data in the program memory, that is, there is no essential difference between programs and data, they are all specific data. If we store a program in the form of array data in the program memory, can it be executed? The answer is yes.
       -Now
      back to the topic, let's take a look at the array data 0xe4, 0xc0, 0xe0, 0xc0, 0xe0, 0x22. From the assembly window of Keil, we can see that it is actually four assembly statements:
        CLR A; compiled as 0XE4
        PUSH ACC; compiled as 0XC0 0XE0
        PUSH ACC; compiled as 0XC0 0XE0
        RET; function return is compiled as 0X22. It can be seen that this is actually the assembly reset instruction of the 51 microcontroller.
      In fact, it's just that the C reset code is written in an ugly way. rst is a byte pointer pointing to the program memory. We convert it to a pointer to a function that returns void. The format of a function pointer that returns void is: void 
      (*)(). This expression is more complicated because of the operator priority relationship. Enclose it in parentheses and it becomes (void 
      (*)())rst. In this way, rst becomes a function pointer. Let's take a look at the general format of function pointer (*p)(). Replace p with (void 
      (*)())rst and enclose it in parentheses to become (*((void (*)())rst))(). This reveals the whole veil of this reset.
      The following is the test and verification program:
#include
main()
{
        unsigned char code rst[6]={0xe4,0xc0,0xe0,0xc0,0xe0,0x22}; //Define an array of code type, it must be of code type
        while(1) //Loop test
        {
                TMOD=5; //The test can be any language name
                TI=1;
                P1=0;
                P1=1;
                P2=2;
                P3=3;
                (*((void (*)())rst))(); //Reset
                SCON=0x50;
        }
}
Reference address:Software reset of 51 MCU

Previous article:51 MCU PID algorithm implementation program C language
Next article:Crystal oscillator circuit in single chip microcomputer

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号