View previous topic :: View next topic |
Author |
Message |
MegatroniC
Joined: 08 Dec 2009 Posts: 35
|
Оccupies a large part of the ROM :( |
Posted: Mon Apr 12, 2010 5:29 am |
|
|
Hello.
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 |
|
|
mskala
Joined: 06 Mar 2007 Posts: 100 Location: Massachusetts, USA
|
|
Posted: Mon Apr 12, 2010 8:22 am |
|
|
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: 19553
|
|
Posted: Mon Apr 12, 2010 8:28 am |
|
|
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 |
|
|
|