51 single-chip programming skills finishing

Single chip microcomputer STM32L151CCU6
1206RGB (single)
Programmable Package SG-8018CA(SG7050C) 0.67M~170M
0201 package SLP0603 ESD electrostatic diode 5V one-way ESD

1. Do not define too many variables. The lower 128 bits are the storage area for the user-defined variables (by default), and the variable can be placed at the upper 128 bits, but it is easy to make mistakes, and it is best not to put it. You can view the storage of memory variables through *.M51. It is best not to exceed 110 bytes, otherwise the program will not run or error.

2. If a variable is used in multiple places, it can be defined as a global variable. For example, the loop variables i, j, to minimize the parameter transfer.

3. Static variables are best placed in the program storage area, defined by code.

4. Variables should be defined as unsigned numbers. Variables such as flag bits that occupy only one bit should be defined as bits.

5. The subroutine should be declared in advance after the main() main program.

6. Variables, subprogram definitions but not used, the system gives a warning.

7. Although local variables and global variables have different names, the runtime may be changed by global variables.

8. After the program is compiled, it is possible to generate very large files. For example, the original 5k, compiled into 10k, this is caused by the random allocation of program space during C assembly. You can first block a part of the program to compile, then remove it and then compile it, restore it, or copy part of it to another file to compile.

9. If a pulse signal is used to generate a timer, to remove the pulse signal, the timer should be turned off first, and then the level is set to high level or low level as required.

10. The "watchdog" function can be implemented using software. For example, if a program runs for one cycle and takes 50ms, the timer can be positioned for 100ms. When it exceeds 100ms, the program will be reset, and the timer will be reloaded or the timer parameters will be reset at the bottom of the program loop.

11. In order to improve the accuracy of the evaluation, you can measure multiple times, then sort, remove the maximum and minimum values, average, or directly average.

12. Multiple timers can be used with one timer. In general, two timers are not enough for a larger program. If several timing times are 10ms, 200us, or 50ms, the timing value can be positioned at 200us, and two variables can be set. When multiple timings are needed, find their minimum common divisor timing.

13. When we write the program to the MCU, it writes *.hex, don't be confused by its size. For 8k MCU, programs less than 20k can be written.

Special Cable

Special Cable,Cable Special,Special Electrical Cables,Special Cables Industries

Shenzhen Bendakang Cables Holding Co., Ltd , https://www.bdkcables.com

Posted on