|
|
View previous topic :: View next topic |
Author |
Message |
darren logan Guest
|
Optimising tricks of the trade ! |
Posted: Sun Feb 02, 2003 5:53 am |
|
|
Hello,
Im fairly new to PIC C, but have just completed my first project involving many of the more advanced features of a PIC (such as timer and UART interrupts).
My budget was to used a PIC16F870 and several times during the project I was faced with the dreaded OUT OF ROM message.
When this happened, I would go back through my code and check to see if I could cut down or optimise to trim down the code size, and sure enough I did.
I learnt several tricks along the way to save space and Im sure it would be of benefit to share mine, and you share yours. Here are a couple that made a big difference for me...
(Note that these may not apply to you, depending on your setup but I should imagine they will come in handy at some point!):
Instead of using:
output_low(whatever)
Use:
bit_clear(*x,y)
(also use bit_set instead of output_high)
Instead of using:
delay_ms(xxx)
Use:
for(i=0;i
(I.e., use a for/loop. However a for loop instead of delay_us on the other hand does not save space)
Please post your handy tips !
Cheers,
Darren
___________________________
This message was ported from CCS's old forum
Original Post ID: 11198 |
|
|
mark r. hahn Guest
|
Re: Optimising tricks of the trade ! |
Posted: Sun Feb 02, 2003 5:47 pm |
|
|
:=Hello,
--- snip ---
:=Please post your handy tips !
:=
:=Cheers,
:=Darren
I wrote a review of the CCS PCM compiler a few years back. I included several tips on how to make your programs smaller. Most of what I wrote then still holds. You might wish to check out my web page: <a href="http://home.hvc.rr.com/mhahn/HahnTronix.html" TARGET="_blank">http://home.hvc.rr.com/mhahn/HahnTronix.html</a>
Happy crunching,
Mark Hahn
___________________________
This message was ported from CCS's old forum
Original Post ID: 11214 |
|
|
Darren Logan Guest
|
Re: Optimising tricks of the trade ! |
Posted: Wed Feb 26, 2003 6:41 pm |
|
|
Hello,
My program contained several write_eeprom and read_eeprom commands.
I replaced them with my own read/writes thus:
void writetoeeprom(int addr, int data) {
write_eeprom(addr,data);
}
int readfromeeprom(int addr) {
return(read_eeprom(addr));
}
This made a significant difference.
Regards,
Darren
___________________________
This message was ported from CCS's old forum
Original Post ID: 12149 |
|
|
|
|
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
|