Notes on 32-Bit Single-Chip Microcomputer C language programming

Source: Internet
Author: User

1. After the system is reset or powered on, the microcontroller will execute a small segment of initialization automatically inserted by the maplab c32 connector before executing the main () function.ProgramThat is, the so-called starup (startup)CodeOr crt0 () code. The startup code is responsible for basic internal operations, including all important initialization of the stack.

 

2. Call a library function at will, such as printf (), which may increase the Execution Code by thousands of bytes. Therefore, use the library function with caution.

 

3. crt0 code is responsible for copying the array content defined in flash from flash to ram before the main program runs. Another important function of crt0 is to initialize each global variable declared by the program to 0, this makes the program safer and easier to predict, but it is costly. If a large array is to be stored in Ram, the crt0 code will take some time to clear them and then execute the main program even if you do not require them to be initialized. However, embedded applications do not allow this latency. In these applications, several milliseconds can damage an expensive power transistor, or quickly and safely restore your application system from the Emergency Reset state. In these special cases, you must define the special function _ on_reset ():

 

Void _ on_reset (void)

{

 

// Your code

 

}

 

This function replaces a blank space called before crt0 code initialization. This program should be as short as possible.

 

4. The variable modified by const is saved in Flash (Program), while the common variable is saved in Ram. After the code is executed, it can be initialized and available.

 

5. the baud rate range allowed by the RS232 interface is positive and negative 2%.

 

6. Press the key to shake the code (take the javase16 Development Board as the model, four buttons _ rd6, _ rd7, _ ra7, _ rd13)

 

Detect input signal

Int reak (void)

{

 

Int C = 0;

 

If (! _ Rd6)

C | = 8;

 

If (! _ Rd7)

C | = 4;

 

If (! _ Ra7)

C | = 2;

 

If (! _ Rd13)

C | = 1;

 

Return C;

}

 

Press down to shake:

 

Int getk (void)

{

Int I = 0, r = 0, j = 0;

Int C;

 

 

Do {

Dleayms (10 );

If (C = readkey ())

{

If (C> r)

R = C;

I ++;

}

Else

I = 0;

 

}

While (I <10 );

 

}

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.