Making PBP code more modular
Hi there,
I've been using PBP on and off for a few years, now semi-professionally. I'm interested in what coding techniques people use to keep their PBP code modular and portable (i.e. the way that you code using C for a PC)...... or should I be using a C compiler to satisfy my desire for modular code? I find that things become unwieldy and messy when I start splitting projects into multiple files, as far as variable/pin declarations go.
I don't want to start the tired old BASIC vs C flamewar here, I just want to know if anyone else uses multiple files for their PBP projects in a way that is properly modular/portable as well as being very readable.
Any code examples/tips/tricks/whatever would be appreciated.
Thanks,
Nick Forge
Magic numbers and aliases.
I write a bit of software and I very seldom use includes. I follow a routine similar to Melanie's in that I tend to structure all of my programs the same way, pretty much as Melanie described. One differance, I usually write my ISR in assembly and stick it at the very top. I also define magic numbers (constants) for things like timer preloads and initial variable states. I also use aliases to define registers. This way my code looks the same, regardless of PIC, because I try and use the same names. I too find that I cut and paste routines when writing code.
All in all code portablity is pretty good but remember we are talking about micros. I mean, its not like you are gonna run your PBP code on an AVR! Now that would be portable!
Regards,
Joe.
I've taken your advice and....
Following the PBP experts lead I went through the task of converting my 7 files project into a single, big momma file. In the process it has helped me tidy up alot of my PBP coding style as well as variable naming. It's taken me a while to adjust to a different style of indenting (and the visual appearance of PBP code is so different to C style code it's really hard to find it readable without doing a hell of a lot of it):
If oranges = apples Then
Do something
Endif
vs
If (oranges = apples) {
Do something;
}
Overall I am much more happy with PBP as a language since forcing myself to do it the 'hard' way. I can see perfectly well why C-experienced PC-programming people don't take to it, but I think it's perfectly up to the task that it has in front of it (programming pics, not multimedia software packages).
Thanks for the tips guys,
Nick
EDIT: damn these auto-formatting forums.... the guys who wrote the code must have thought they were being so clever. oh well i hope you get the picture of what i tried (and failed) to show. if not.... well it doesn't really matter, does it?
includes for assembly macros
Now this is more like what includes make sense for (in my mind)..... Peripheral control macros. You could make a file that contains all the macros for one uC (e.g. 18f452.pbp). Every time you use a peripheral, you make a macro and add it to the uCs peripheral macro file. I was going to make another post asking about how to do assembly macros (I too want my own command set to make things tidier) but seeing your example shows me what I need to know.
Only one question: is there any way to make a macro in asm, then put PBP code inside the macro? (I guess I could go and pick the PBP-ASM files apart to find the ASM macros that PBP uses and use them, but if I don't have to I won't waste my time)
So, for example, is there some way to write, say an LCD command macro that uses LCDOUT?
so that
LCDCMD Clear, Line1, Right
would have the effect of
LCDOUT $FE, $01, $FE, $80, $FE, $14
(BTW I already have constants representing all those commands anyway, but it would be nice to not have to enter the them all in this way)
I like it! I like it! Hey Mikey likes it!
Hi Darrel,
I haven't been on this board in a while (busy doing some contract work --- gotta make money). I see besides writing a great LCD routine you have been enhancing your posts as well (I especially liked the video presentation). And hey it all looked great under FireFox.
Keep up the great work,
Michael
Whew!! Finally back to writing PBP code again
Darrel,
Quote:
I hope that contract work is PIC related
Yes it was, but unfortunately it wasn't done in PBP. Actually it is a ressurection of pic assembly code I wrote back in 1998, with some minor changes to adapt it to newer hardware.
If you are interested, here is a link to what I was doing: www.mytekcontrols.com/specialproducts/
What had originally started out as a contract proposal, changed into an actual product instead. This allowed me to retain the rights to sell it to anyone, and kept it more affordable for the buyer since they weren't paying for the full engineering time (it gets spread out over several unit sales --- hopefully).
Now I am back to working on my main project (StampVue), which has an OS written in PBP. In fact this morning I just got an Auto Baud Detect PBP routine to work for it, which I'll be posting some sample code in an appropriate forum within the next couple of days.
I'll need to do some catching up on your macro escapades. Which I can see from other posts, you've been busy as well.
I hope all is well with you,