As we all know, compared to other programming languages, C language has absolute advantages in writing embedded programming. However, it always has disadvantages: it has poor timing and it is not easy to write precise delays. However, when writing embedded system drivers, it often requires more accurate software delays, which exposes the "disadvantages" of the C language, and generally can only be achieved through embedded assembly. For example, if a delay of 10us is required at a working frequency of 1 MHz, it is necessary to embed 10 phrases of “empty operationâ€, which is obviously embarrassing in terms of writing. This paper proposes a time-delay scheme that simplifies writing, uses the macro with parameters to create tiny time slices, and can achieve completely accurate software delays, which greatly facilitates the writing of driver and software analog communication protocols.
Note: All of the following are discussions under the ICC AVR platform and are valid for all AVR series microcontrollers. As for other platforms, it can be modified and transferred according to this plan.
The implementation of this solution is actually very simple:
First define N macros and call 1 ~ N assembly "null operation" instructions respectively, such as:
#define NOP_1 asm(“nopâ€) // Delay one clock cycle
#define NOP_2 NOP_1; asm(“nopâ€) // delay two clock cycles
#define NOP_3 NOP_2; asm(“nopâ€) // delay three clock cycles
#define NOP_4 NOP_3; asm(“nopâ€) // Delay four clock cycles
......
#define NOP_40 NOP_40; asm(“nopâ€) // Delay 40 clock cycles
Then use the "##" operator to implement the delay with parameter macros:
#define NOP(N) NOP_##N // delay N clock cycles
The role of the operator is to link the content of the two parts into one content. That is, NOP(3) becomes NOP_3 after expansion, NOP(4) becomes NOP_4 after expansion, and so on. Therefore, after the above macros are defined, precise software delay can be achieved by calling the NOP(N) statement. E.g:
NOP(4); // delayed by 4 clock cycles
The above statement expansion process is as follows:
NOP_3 ; asm("nop");
NOP_2; asm("nop"); asm("nop");
NOP_1; asm("nop"); asm("nop"); asm("nop");
Asm("nop"); asm("nop"); asm("nop"); asm("nop");
Just delay 4 clock cycles
However, the above macro is not perfect enough, if you try to use the following statement, the program will be loopholes.
If (expression)
NOP(3);
Else
NOP(4);
This is because after the NOP(N) macro is expanded, it is not a statement, but it becomes N statements. It must be enclosed in braces to ensure that the program runs correctly. That should be changed to:
If (expression)
{
NOP(3);
}
Else
{
NOP(4);
}
If the definition of the NOP(N) macro is changed to:
#define NOP(N) do{ NOP_##N ; }while(0)
After the NOP(N) macro is expanded, only one statement is formed and the above problem will not occur.
However, note that the "##" operator can only link the two sides together as they are. Therefore, the parameter of NOP(N) must be a specific constant, ie it can only be a number, and the macro NOP_N corresponding to this number must already be defined.
E.g:
After the "NOP(3+4);" statement is expanded, it will become "NOP_3+4;" ​​and a syntax error will occur;
Another example:
After the "NOP(a);" statement is expanded, it will become "NOP_a;" and "NOP_a;" is undefined.
Only such statements are the correct ones:
NOP(20); // Delay 20 clock cycles
The above program is organized into a header file, which can be called anytime later. The following is a well-organized header file:
Note: This file is not suitable for long delays. A long delay will invoke a large number of "null operations" instructions, taking up a lot of program instruction space. This issue will be resolved in the V2.0 release.
Intel I5 Laptop is the one of the important high cpu processors, another ones are i3, i7, i9. We can do 2th, 4th, 5th, 6th, 8th, 10th, 11th or 12th. How to choose a best suitable one? If you do heavier jobs, like interior design, music or video editing, even engineering drawing, etc, 15.6 inch Intel I5 11th Generation Laptop or Intel I5 10th Generation Laptop is a better choice for you. If you focus on portability, Laptop 14 Inch I5 11th generation is a good option. Of course, Intel i7 11th Generation Laptop or 1650 graphics card laptop also available.
Someone may worry the custom one quality, that`s cause that lack of custom Student Laptop knowledge, so just keep reading so that know deep in this field. Frankly speaking, the technical skill is totally mature, no matter hardware or software or craft. You can see nearly no difference when check the oem laptop and brand one in person. To support clients and be confident with our product, provide sample for every clients.
Any other special requirements, you can just contact us freely or email us and share the exact details about what you need, thus right and valuable information sended in 1 working day.
Intel I5 Laptop,Intel I5 11th Generation Laptop,Intel I5 10th Generation Laptop,Laptop 14 Inch I5,Intel I5 Laptop Price
Henan Shuyi Electronics Co., Ltd. , https://www.shuyicustomtablet.com