PDA

View Full Version : how top make a library for a modual



longpole001
- 6th June 2012, 10:46
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

Heckler
- 6th June 2012, 22:55
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.)

Charlie
- 7th June 2012, 10:08
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?

longpole001
- 7th June 2012, 11:44
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

spcw1234
- 7th June 2012, 12:49
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.

longpole001
- 7th June 2012, 13:24
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

Archangel
- 7th June 2012, 16:39
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.

longpole001
- 8th June 2012, 00:33
is it possible to write functions in this way as well

rmteo
- 8th June 2012, 06:22
is it possible to write functions in this way as well

Does PBP support functions?

Charlie
- 8th June 2012, 11:49
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.

longpole001
- 11th June 2012, 00:15
thanks for that

longpole001
- 21st June 2012, 08:49
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

pedja089
- 21st June 2012, 09:31
You need to put on top of include GOTO OverMyInclude, and put label OverMyInclude on end of it.
Look at any Darrel's include.

mackrackit
- 21st June 2012, 09:35
Without seeing your code I will bet you did not jump to the end of the include file.

MyInclude.bas


GOTO MyIncludeEnd
'Sub Routines
MyIncludeEnd:

longpole001
- 21st June 2012, 10:12
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

mackrackit
- 21st June 2012, 10:26
GOTO MyIncludeEnd

sub1:
do this 1
return

sub2:
do this 2
Return

MyIncludeEnd:

longpole001
- 21st June 2012, 10:53
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

mackrackit
- 21st June 2012, 11:04
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.

Gusse
- 21st June 2012, 11:11
Here is one example of using module library, Using Nokia 3310 LCD (http://www.picbasic.co.uk/forum/content.php?r=174-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-

longpole001
- 21st June 2012, 11:32
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