The development technique of single-chip microcomputer programming

Source: Internet
Author: User

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

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.