how top make a library for a modual
Hi guys,
can you send me a link on how to make a library for a chip ,
I have a module / chip with a lot of register settings that will be constants that i want to include and use for future designs , during a compile but dont want to keep them in the main program as i write it , to keep the main program it a bit cleaner
is it a mater of adding it as an include " modulename.bas" statement in the main program and use the command " symbol" in front of the list of the register constants / var i want to use and save as "modulename.bas"
cheers
Sheldon
I
Re: how top make a library for a modual
That is actually a good question Sheldon, I wish I had the answer.
That is one area that I think the folks that make the PBP compiler could help out. I think that is one area where the Arduino community shines. They are able to share "Libraries" with each other. Now granted the Arduino is limited to just a few versions so there is not a lot of variety to adapt the libraries to. Where as the literally dozens of PIC's with each of their different pin assignments, PWM, comparators, etc. presents much more of a challenge to the concept of "modules" or "libraries".
Someone more knowledgeable than me might jump in here to give some guidance.
I do think that is an area that the PBP folks could help the users learn how to at least do easier and understand better the use of include files.
I know that Darrell Taylor and others have mastered the concept of "Include" files.
I really think Melabs could make an effort to keep this excellent PBP compiler community alive and vibrant and growing (and to attract some of the other microcontroller users over to the PBP compiler.)
Re: how top make a library for a modual
According to the manual, you can insert any block of source code. When you use INCLUDE "mystuff.bas" for example, the complete contents of "mystuff.bas" is inserted in place of the INCLUDE line during compile. I have done this with simple things, and it seems to work fine. Is there something specific you are having trouble with?
Re: how top make a library for a modual
i have just not seen how its done i thought you may need to have some commands within the included file to allow it to be included & compile correctly or can it be a standalone bit of code and just be stated as included during a compile
Re: how top make a library for a modual
All you need is the code you want included. Just like it was there in place of the include, it is simply added to your code when compiled. You do not compile the the files you want to include.
Re: how top make a library for a modual
ok ill give it a go , still very new to Picbasic , the module code is now over 4 printed pages of registers and settings MOST of which can be standalone from the main program so rather keep it that way for easier on going programming
Re: how top make a library for a modual
Using the "include MySetUp.bas" is a great way, another way is make a file using all the setups you want and name it something like 16F628ANoAnalog.bas and when you start a project open it and save as MyNewProject.PBP . Both methods work well. I like this method if I am creating a new folder for the project.
Re: how top make a library for a modual
is it possible to write functions in this way as well
Re: how top make a library for a modual
Quote:
Originally Posted by
longpole001
is it possible to write functions in this way as well
Does PBP support functions?
Re: how top make a library for a modual
If by function you mean logic or math function, most are already there. If by function you mean subroutine where you put values in variables, call the routine, and have it return with new values in variables based on some operation, then yes you can do that too. In terms of getting a transform, there is little difference between the two except for code size.
Re: how top make a library for a modual
Re: how top make a library for a modual
i have made a "myfile.bas" where i have common subroutines and use common variables for specific added hardware modules, these are stated as " include ' in the main program code.
the main program calls the subroutines as required.
PB3 compiles the file , how ever the hex output when tested , shows that subroutines are being executed prior to being called from the main program.
its seems clear that from the point of where put the " include myfile.bas" in the main program it just jumps to that point and executes all the subs within "myfile.bas" without being called by the program
What am i missing to make it work correctly as if it were part of the main program but allow standard subrontines to be stored in "myfile.bas " and compile correctly.
cheers
sheldon
Re: how top make a library for a modual
You need to put on top of include GOTO OverMyInclude, and put label OverMyInclude on end of it.
Look at any Darrel's include.
Re: how top make a library for a modual
Without seeing your code I will bet you did not jump to the end of the include file.
MyInclude.bas
Code:
GOTO MyIncludeEnd
'Sub Routines
MyIncludeEnd:
Re: how top make a library for a modual
can you point to an code example , this is what i have
Myfile.bas has
sub1:
do this 1
return
sub2:
do this 2
Return
--------------
Main prog has
include "myfile.bas"
main:
gosub sub1
gosub sub2
goto main
Re: how top make a library for a modual
Code:
GOTO MyIncludeEnd
sub1:
do this 1
return
sub2:
do this 2
Return
MyIncludeEnd:
Re: how top make a library for a modual
so by putting the goto label within the " myfile.bas ", and also putting that label at the end of the file , the compiler compiles the included file but jumps all code within the file when it generates the hex code
Re: how top make a library for a modual
Yes.
Think of it like this, Where ever the INCLUDE statement is in the main code is where what ever is in the include file will be put. So to see what will happen at compile time, paste the code from the include into the main code at the include statement. That is what the compiler sees/does.
Re: how top make a library for a modual
Here is one example of using module library, Using Nokia 3310 LCD.
ScaleRobotics has documented this very clearly, so you should be able to get idea how the library is used.
BR,
-Gusse-
Re: how top make a library for a modual
thanks guys , yes it works fine now , i have about 6 -8 libs to make for dif modules for this project , so doing it better really counts ,
cheers