Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/25/08 21:12
Read: times


 
#157747 - Why so much code expansion?
Responding to: ???'s previous message
You have
if(seg_count==0)				 
{	  							  //remove switch case;to if else latency
     address(0x01);
	 write(LCD_digits[0]);
	 seg_count=1; 
}
if(seg_count==1)
{
     address(0x02);
	 write(LCD_digits[1]);
	 seg_count=2; 
}

if(seg_count==2)
{
      address(0x04);
	  write(LCD_digits[2]);
	  seg_count=3; 
}
...

instead of
address(1 << seg_count);
write(LCD_digits[seg_count]);
seg_count = (seg_count+1) & 0x07;

And you have:
if(asc=='~'){a=0x20;return;}
if(asc=='!'){a=0x10;return;}
if(asc=='@'){a=0x08;return;}
if(asc=='#'){a=0x04;return;}
if(asc=='$'){a=0x02;return;}
if(asc=='%'){a=0x01;return;}
if(asc=='^'){a=0x80;return;}
if(asc=='&'){a=0x40;return;}
...

instead of
if (asc >= ' ' && asc < 128) {
    a = lookup[asc - ' '];
} else {
    // Replace unsupported character with '?'
    a = lookup['?' - ' '];
}

And why do you use global variables when not needed? You let convert take an input parameter, but assign (sometimes) to the global variable a. What happens if convert() gets a character that isn't supported? Your code doesn't give a new value for a, so the previous character will repeat.

Another thing: Some parts of your code is indented. Some are not. Always indent your code properly. It doesn't take long time, but you can read the code very much faster when your eyes can jump directly from a block-start to a block-end without a need to scan every single character in-between...

You are defining a huge number of bit variables for your LCD - what are you using them for?

List of 9 messages in thread
TopicAuthorDate
printf and putchar lcd driver            01/01/70 00:00      
   Why so much code expansion?            01/01/70 00:00      
      RE:printf and putchar lcd driver            01/01/70 00:00      
   Solved first problem,now second one            01/01/70 00:00      
      Resistors?            01/01/70 00:00      
   y cannot edit previous thread            01/01/70 00:00      
      Mistake?            01/01/70 00:00      
      try to contact the Webmaster            01/01/70 00:00      
   ANG KAH BENG            01/01/70 00:00      

Back to Subject List