Microcontroller Programming Development Tips

Wu Jianying Microcontroller Development Board Address

Taobao Store:Wu Jianying’s Shop

Address:https://item.taobao.com/item.htm?_u=ukgdp5a7629&id=524088004171

Microcontroller Programming Development Tips

After working for 7 months, I have gradually become familiar with programming microcontrollers. Previously, I always knew that microcontrollers combined timers, state machines, and interrupts, which was quite efficient. However, after taking over the development of the GPF chip, I discovered another kind of microcontroller development technique. Experts, please bypass this.

We all know that delays in programs can affect the real-time performance of microcontrollers, leading to a significant decrease in efficiency. However, in the development of the GPF chip, the system delay and initialization were combined by the supplier, so calling the program requires a certain loop to ensure that the program runs normally. I actually don’t know why they did it this way.

In work, modifying a source code is not something that can be done casually. At that time, I created a program, and I won’t disclose the source code, but I will write a case to explain:

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 == 50)

{

printf(“0x%x\n”,0xE1);

count = 0 ;

};break ;

case 2:

if(count == 50)

{

printf(“0x%x\n”,0x90); // Send general ‘1’ signal

count = 0 ;

};break ;

default:

break ;

}

count++ ;

#if 0

ch = getch(); // Assume I set a key here

if(ch == ‘q’)

{

printf(“%x”,0x48);

break ;

}

#endif

}

}

In the while loop, first there is a delay of 20 ms, then the count counter increments. When it reaches 50, which is one second, it resets. At this point, if a key is pressed, it will not be disturbed, and the program runs normally, maintaining high efficiency. If at this time delay_20ms is changed to delay_1000ms, the program will have to wait 1 second for each key scan, affecting efficiency. The count value can be estimated by oneself and does not need to be too precise. Such a program can achieve functions similar to that of a timer without requiring too precise a delay.

If you like this articleplease give a thumbs up

Microcontroller Programming Development Tips

Microcontroller Programming Development Tips

Technology Comes from Accumulation, Success Comes from Perseverance

——Microcontroller Detailed Explanation by Wu Jianying

Leave a Comment