how top make a library for a modual


Closed Thread
Results 1 to 20 of 20
  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838

    Cool 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

  2. #2
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default 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.)
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  3. #3
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default 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?

  4. #4
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default 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

  5. #5
    Join Date
    Apr 2007
    Location
    Pennsylvania, USA
    Posts
    158


    Did you find this post helpful? Yes | No

    Default 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.
    Shawn

  6. #6
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default 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

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default 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.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  8. #8
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: how top make a library for a modual

    is it possible to write functions in this way as well

  9. #9
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default Re: how top make a library for a modual

    Quote Originally Posted by longpole001 View Post
    is it possible to write functions in this way as well
    Does PBP support functions?
    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

  10. #10
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default 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.

  11. #11
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: how top make a library for a modual

    thanks for that

  12. #12
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default 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

  13. #13
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default 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.

  14. #14
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default 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:
    Dave
    Always wear safety glasses while programming.

  15. #15
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default 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

  16. #16
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: how top make a library for a modual

    Code:
    GOTO MyIncludeEnd
    
    sub1:
    do this 1
    return
    
    sub2:
    do this 2
    Return
    
    MyIncludeEnd:
    Dave
    Always wear safety glasses while programming.

  17. #17
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default 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

  18. #18
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default 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.
    Dave
    Always wear safety glasses while programming.

  19. #19
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    191


    Did you find this post helpful? Yes | No

    Default 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-

  20. #20
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default 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

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts