当前位置:网站首页>Blue Bridge Cup multi interface switching processing (enumeration plus state machine method)

Blue Bridge Cup multi interface switching processing (enumeration plus state machine method)

2022-07-01 12:08:00 Proficient in embedded

Preface

In this paper, we mainly introduce how to deal with the problem of multi interface switching in the Blue Bridge Cup .

One 、 What is multi interface switching

Multi interface switching is that the title requires a specific interface to be displayed in the case of characteristics , At this time, we need to switch the interface .

Two 、 Code display

#include <STC15F2K60S2.H>

static void DIP_ser(void)// Handling multiple interfaces 
static void key_scan(void);// Press the key to switch the interface 

typedef enum
{
    
	ID_NULL=0,
	ID_1,// Interface 1
	ID_2,// Interface 2
	ID_3,// Interface 3
	
}ID_DATA;

ID_DATA id_data;// Declare an enumeration variable 

void DIP_ser(void)
{
    
	switch(id_data)
	{
    
		case ID_1:
		{
    
			// Interface 1 Function main body 
		}
		break;
		case ID_2:
		{
    
			// Interface 2 Function main body 
		}
		break;
		case ID_3:
		{
    
			// Interface 3 Function main body 
		}
		break;
	}
}

void key_scan(void)
{
    
	// Operate enumeration variables to achieve interface switching 
	( There is no need to explain this part of the code , Press the key to change id_data that will do )	
}

void main()
{
    
	id_data=ID_1;// Power on initialization interface 1( You can also change to other interfaces )
	while(1)
	{
    
		key_scan();
		DIP_ser();
	}
}


summary

Using this method to switch the interface is simple and clear , The code will look clearer .

原网站

版权声明
本文为[Proficient in embedded]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202160034598951.html