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.

code optimization help (characters on graphic lcd)

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
Below is the test code for my Graphic LCD. Nothing problem with the code. But I would like to know any other code optimization is there to run the code faster.

Is my for and if loops are okey? or to increase code efficiency how can i modify it.

Code:
	for(m = 0; m < 3; m++)
	{
	   glcd_command(address+m); // row address
	   glcd_command(upper_address);
	   glcd_command(lower_address);   // column shift
	
	   for(i = 0; temp_value[i] != '\0'; i++)
	   {
	      if(temp_value[i] == '-') 	// temp_Value is minus
	      {
	         for(x = m; x < 24; x = x+3)   
	         {
	            glcd_data(negative_22[temp_value[i]-45][x]);
	         }
	      }
	
	      if(temp_value[i] == '.')	// temp_value is decimal
	      {
	         for(x = m; x < 24; x = x+3)   
	         {
	            glcd_data(decimal_point_22[temp_value[i]-46][x]);
	         }
	      }
	      
	      else if((temp_value[i] >= '0') && (temp_value[i] <= '9')) // temp_value is between 0 and 9
	      {         
	         for(x = m; x < 48; x = x+3)   
	         {
	            glcd_data(numbers_22[temp_value[i]-48][x]);
	         }
	      }
	      
	      else
	      {
	         for(x = m; x < 48; x = x+3)   
	         {
	            glcd_data(space_22[temp_value[i]-32][x]);
	         }         
	      }
	   }
	}
 

Perhaps not faster, but cleanest by changing the if-else statements by switch-case. Try putting the temp_value variable as the switch selector, for case as '-', '.', '0'...'9' and for the default you put the last expressions.
 

Thank you andre.

@easyrider: This code will display the character on graphic LCD
 

Why so weird way to do that? Usually, you should convert number to string, and then print it out.
 

How can i modify the code? This code prints on the GLCD slowly when i want to display a value of 100.00
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top