Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help with code optimization in Embedded C

Status
Not open for further replies.

hemnath

Advanced Member level 3
Joined
Jun 24, 2012
Messages
702
Helped
61
Reputation
120
Reaction score
57
Trophy points
1,308
Location
Chennai
Activity points
6,588
Hi,

I have many menu sections which will display on LCD depending on the input parameter. Below is the sample.

Code:
void main_menu()
{
	int i;

	switch(i)
	{	
		case 1:	printf("text1");
			break;

		case 2:	printf("text2");
			break;
		.
		.
		.
	
		case 5: printf("text5");
			break;	
	}

	if(i == 1)
		// do some action

	else if (i == 2)
		// do someother action

	.
	.
	.
}

void sub_menu()
{
	int i;

	switch(i)
	{	
		case 1:	printf("text1");
			break;

		case 2:	printf("text2");
			break;
		.
		.
		.
	
		case 5: printf("text5");
			break;	
	}

	if(i == 1)
		// do some action

	else if (i == 2)
		// do someother action

	.
	.
	.
}

void sub_menu1()
{
	.
	.
	.	
}
// submenus goes on

Is this the efficient way of programming the menu structure? Or any other methods available to reduce the memory size and faster execution of program.
 

Yes, it is optimal from memory consumption point of view, but it is not flexible.
Do you think you are good enought to start using pointers and structures?
 

Why do not do the action after the printf on case 1 for instance?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top