| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Sep 01, 2009 12:12 pm |   |  
				| 
 |  
				| Here is a post of mine from the old CCS forum on this topic. These comments apply to 16F PICs.
 
 ===================================
 I had a similar problem. My 16c77 was 93% full.
 I know that the compiler starts to have problems if it
 gets to 95%, so I really only had 2% space left.
 
 So I looked at the .LST file. I saw many, many places
 where the compiler used ROM very inefficiently.
 In the first hour of examining the .LST file, I recovered
 400 bytes by re-writing my code. In the next hour I
 got back maybe 300 more bytes, and so on. Eventually,
 I probably recovered at least 1500 bytes.
 
 1. CCS does pointer operations very inefficiently.
 
 Don't do:
 ptr = buffer;
 a = *ptr++;
 b = *ptr++;
 c = *ptr++;
 
 Do this, if possible. It uses a lot less ROM:
 a = buffer[0];
 b = buffer[1];
 c = buffer[2];
 
 -----------------------------------
 2. Avoid using CCS string functions. They use up tons of ROM.
 
 If you are calling one string function many times,
 then it's not so bad. But if you use a CCS string
 function just once, then you are wasting a lot of
 ROM for just one function. There is usually a cheaper
 way to do it.
 
 ----------------------------------
 3. Avoid using printf() or lcd_putc() with strings.
 If you are sending 5 characters or less, then it is
 cheaper to use constant characters.
 
 Don't do:
 printf("ABC");
 
 Do:
 putc('A');
 putc('B');
 putc('C');
 
 ----------------------------------------------
 Code can usually be written more efficiently.
 Here was the original way that I sent commands.
 Note: I sent a lot more than 3 commands, and they
 were spread out all over the program. I am just
 using 3 commands together, below, as an example.
 
 puts("$PXXXP"); // Send P command
 puts("$PXXXA"); // Send A command
 puts("$PXXXR"); // Send R command
 
 Here's a cheaper way to do it. Create a central
 routine that sends the command string. Then just
 call that routine with the command letter.
 
 send_command('P');
 send_command('A');
 send_command('R');
 
 void send_command(char command_letter)
 {
 printf("$PXXX");
 putc(command_letter);
 putc(0x0d);
 putc(0x0a);
 }
 
 It might take you a few days, but I will bet that
 you can recover 1K to 2K of your ROM space by looking
 at the .LST file.
 |  |