CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Оccupies a large part of the ROM :(

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MegatroniC



Joined: 08 Dec 2009
Posts: 35

View user's profile Send private message ICQ Number

Оccupies a large part of the ROM :(
PostPosted: Mon Apr 12, 2010 5:29 am     Reply with quote

Hello. Smile

This fragment of my code occupies 20% ROM. (Here most of the code)
How can I optimize?


Code:
void detect_buttons1(void)                                       
{
 if(scroll_click)                                  // 1%
  {                                                   
   switch(adc_channel)                       
    {                                                 
     case 0: adc_channel=1;               
       break;                                       
     case 1: adc_channel=2;                       
       break;                                     
     case 2: adc_channel=3;                 
       break;                                       
     case 3: adc_channel=0;                   
    }
  }
  if(select_click) time_data();        //  19%
  if(set_hold) main_menu();          //
}


thanks Smile
mskala



Joined: 06 Mar 2007
Posts: 100
Location: Massachusetts, USA

View user's profile Send private message

PostPosted: Mon Apr 12, 2010 8:22 am     Reply with quote

I'm pretty sure people have written a more compact printf replacement that saves code space by not having to deal with floats, etc. You should look into that.
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Mon Apr 12, 2010 8:28 am     Reply with quote

You have already marked that 'time_data' is occupying 19%.
Your chip only has a small amount of memory. The print statements in this, are the big 'memory hogs'.
You might find they would code smaller, by using a separate 'printval' function, that just outputs a single int8, and calling this in turn for each value, and just using putc, to send the extra characters between. This way one single print function does 80% of the work.

Your 'switch' can be coded smaller as:

adc_channel=(adc_channel+1)&3;

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group