Work for 7 months, the microcontroller programming also began to slowly familiar with, always know that single-chip microcomputer is the timer, state machine, interrupt these things combine efficiency is quite high, but since the development of GPF this chip, I found another kind of microcontroller development skills, master please bypass.
We all know that in the program, the delay will affect the real-time performance of single-chip microcomputer, resulting in a significant reduction in efficiency, but in the development of the GPF chip, the system delay and initialization by the supplier to do a piece, so the call program, must do a certain loop to make the program can run normally up, Actually, I don't know why they did it.
In the work, change a source code is not casually can change, at that time did so a program, source code I will not public, write a case explanation:
void Test () {int i = 0; int tick; int batterystatus = 0;int Voltage; int count = 0; int voltage_value; char ch; scanf ("%d" , &batterystatus); while (1) {delay_20ms (); switch (batterystatus) {Case 1: if (count = =) { printf ("0x%x\n", 0xe1); count = 0; }; break; Case 2: if (count = =) {printf ("0x%x\n", 0x90),//generic ' 1 ' signal count = 0; }; Break;d Efault:break;} count++; #if 0 ch = getch (); Suppose I set up a key in here if (ch = = ' Q ') {printf ("%x", 0x48); break;} #endif}}
In the while loop, the first step in is to delay 20 ms, and then count counter Gaga, when added to 50 times that is a second, and then zeroed. At this point, if you press the button, will not be disturbed, the program normal operation, the efficiency is still very high. If this time delay_20ms change to delay_1000ms, the program scan button each will wait for 1s clock, affect efficiency. Count values can self-estimate, do not need to be too accurate, such a program in the delay does not need to be too precise to achieve the same function as the timer.
The development technique of single-chip microcomputer programming