Sharing an Embedded Programming Template

Sharing an Embedded Programming Template

Input Events to State Machine #include "stdio.h" #define EXECUTE_VOID(func) {if((func)!=NULL) (func());} typedef void (*select_machine_t)(void); typedef enum _event_index{ event_index_1 = 0, event_index_2, event_index_3, event_index_end} event_index_e; typedef enum _status_index{ status_index_1 = 0, status_index_2, status_index_end} status_index_e; void machine_1(void);void machine_2(void);void machine_3(void);void machine_4(void); select_machine_t select_machine[event_index_end][status_index_end] = { {machine_1, machine_2}, {NULL, machine_3}, {machine_4, NULL}}; void machine_1(void){ printf("machine_1\r\n");} void machine_2(void){ printf("machine_2\r\n");} void … Read more

How to Achieve Byte High-Low Bit Swapping in Embedded Programming?

How to Achieve Byte High-Low Bit Swapping in Embedded Programming?

Follow+Star Public Account, don’t miss out on exciting content Source | Technology Makes Dreams Greater Recently, I encountered the issue of byte high-low bit conversion in a protocol, so I lazily searched online and found a similar problem, and learned a new term called butterfly swapping. The protocol requires that the low byte is on … Read more

Embedded Programming (24) – How to Use the #ifndef Directive?

Embedded Programming (24) - How to Use the #ifndef Directive?

Lifetime Technical Support:186 3636 9649 Author Introduction: Fan Shengmin (186 3636 9649), Member of the Science Writers Association of Yuncheng City, Member of the Science Writers Association of Shanxi Province. Author of maker education. Published “Playing with Electronics” in 2016, “Super Fun Electronic Production” in 2017, “Electrical Experiments in Life” in 2018, “Arduino Programming and … Read more

Applications of Structures and Unions in Embedded Programming

Applications of Structures and Unions in Embedded Programming

01Union In the previous article “Combining Enumerations and Structures”, it was mentioned that a structure is like a packaging encapsulation, encapsulating some variables with common characteristics inside. A structure is a constructed type or complex type that can contain multiple members of different types. In the C language, there is another syntax very similar to … Read more

Applications of Embedded Programming: The Intricacies of Union

Applications of Embedded Programming: The Intricacies of Union

Concept of union In Chinese, union is referred to as a union, joint, or collective. Its definition format is the same as that of a struct, but its meaning is entirely different. Below is the definition format of a union: union union_name { member_list } union_variable_name; Since its definition format is the same as that … Read more

Layering Code Structure in Embedded Programming

Layering Code Structure in Embedded Programming

Follow and star our public account for exciting content ID: Technology Makes Dreams Greater Source: Online Materials For a beginner transitioning from novice to expert, a learning model like identifying problems → engaging in thought → proposing solutions is very effective. 1. Problems Encountered  Through this period of coding practice, I have accumulated some coding … Read more

Understanding the Significance of the Stack in Embedded Programming

Understanding the Significance of the Stack in Embedded Programming

Follow+Star Public Account, don’t miss out on exciting content Author | Li Xiaoyao Source | Technology Makes Dreams Greater What is a Variable? Variables can generally be subdivided as shown in the figure below: The focus of this section is to help everyone understand the “stack” in the memory model, temporarily disregarding the case of … Read more

The Beauty of Mathematics: The Intricacies of Embedded Programming (with C Code)

The Beauty of Mathematics: The Intricacies of Embedded Programming (with C Code)

[Introduction] Ah, you have been successfully drawn in, not quite what you expected, huh?~~~ Just kidding, back to the point. Today, a netizen asked me a question about a sensor measuring a physical quantity and needing to determine its trend of change. I provided some suggestions, and here I will elaborate on those suggestions and … Read more

A Method for Context Switching and Perfect Decoupling in Embedded Programming

A Method for Context Switching and Perfect Decoupling in Embedded Programming

Follow “Embedded Mix” and select “Star the Official Account” to progress together! Source: CSDN Fast Context Switching – cpost Application It is commonly believed that time-consuming operations cannot be executed during interrupts, as this would affect system stability, especially in embedded programming. For programs with an operating system, interrupt handling can be divided into two … Read more

Sharing Years of Experience in Embedded Programming: A Different Perspective on Programming

Sharing Years of Experience in Embedded Programming: A Different Perspective on Programming

1. Limitations of Traditional Programming Structures When not using an RTOS, embedded software typically employs two traditional programming structures: one is called the “front-back structure” or “super loop structure,” which is essentially an event-driven programming method; the other is a time-triggered programming method, such as Michael J. Pont’s “time-triggered programming model.”In practical work, when the … Read more