Shop OBEX P1 Docs P2 Docs Learn Events
SX/B - Possible File Inclusion BEFORE Program Statement? — Parallax Forums

SX/B - Possible File Inclusion BEFORE Program Statement?

Sparks-R-FunSparks-R-Fun Posts: 388
edited 2006-11-03 19:41 in General Discussion
Hi,

In trying to keep my programs neat and organized, I like to keep collections of subroutines in separate files and just include them as needed. This works great for most program code provided it comes after the PROGRAM statement. However, I also wish to keep things such as IO Pins, Constants, Variables and my ISRs in separate files as well. I think this would improve the organization and ease-of-use of several of my programs. Whenever I need to change an IO pin, a constant or a variable I would like to be able to simply open the appropriate file, make some changes, then close the file and not have to scroll past it constantly as I edit the rest of my program.

Is it possible to do this already?

Does this seem like a useful enough feature to warrant consideration?

Would anyone else care to share tips for keeping programs nice and orderly?

Just wondering...

- Sparks

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-11-01 19:33
    I had the same idea. What works for me is to define subroutines in
    a special file called <filename>.LB (LB stands for Library Basic)
    See the attachements.
    I use load <filename>.LB to include library subroutines before Program.
    Both the subroutine declarations and the actual subroutines are in the LB file.

    regards peter
  • BeanBean Posts: 8,129
    edited 2006-11-01 22:41
    Yes two files is the way to do it.
    I use "Library.HDR" and "Library.SXB".

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    "People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
    ·
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2006-11-02 19:34
    Ok. It sounds like this can be done. So I am glad that I asked! However, I am still not quite clear how to do what I want.

    Peter,

    Thank you for the example. (Examples help a lot!) I looked at what you did but it looks to me like you are actually loading your library routines after the "Program" statement. I can not get the “Load” or “Include” commands to work if they are encountered before the “Program” statement. Each time I try it generates a “List index out of bounds” error.


    Bean,

    Is it possible to include information from another file before SX/B encounters the “Program” statement? Is this what you use the .HDR file to accomplish? How can I use it or where can I find more information about doing this?



    Example Problem:

    I have not been able to use the “Load” or “Include” commands prior to the point where the SX/B complier encounters the “Program” directive. The reasoning behind wishing to do this is as follows:

    1.) The “Program” directive must come after the (optional) “Interrupt” declaration. I am using interrupts and my heavily commented ISR is three pages long.

    2.) Constants, variables and subroutines that are going to be used by the interrupt must be declared before they are encountered by the SX/B complier as it reads the interrupt routines. So these must be declared before the interrupt and before the "Program" directive.

    3.) Right now I am declaring all of my I/O pin, constant and variable assignments plus my interrupt service routine before the "Program" statement (as is shown in the programming template). With the IDE running full screen (at 1280x1024), I need to scroll through nine pages of heavily commented code just to get to my subroutine declarations. On the tenth page is where the "Start" statement is found. The next three pages contain the remainder of the program code (which includes load and call statements to subroutines contained in separate files but not the content of those files). I am trying to put as much as I can into separate files to make things more manageable.

    So two questions arise. “Can I place my interrupt routine (and the declarations it requires) in a separate file and have it be included in my program?” “If so, how?” The method to accomplish this is not clear to me.


    - Sparks
  • BeanBean Posts: 8,129
    edited 2006-11-02 19:56
    Sparks,
    Check out how I did the code for the MMVGD at this post:
    http://forums.parallax.com/showthread.php?p=598779

    Download the "MMVGD 1_1" and look at how the games LOAD the driver.

    P.S. If you want to use SUBs in your interrupt routine you need to do this:
    '
    INTERRUPT
    · GOTO HandleInt

    MySub1· SUB 0
    MySub2· SUB 0

    PROGRAM Start

    HandleInt:
    · ' Interrupt code goes here
    · MySub1
    · MySub2
    · RETURNINT
    MySub1:
    · RETURN

    MySub2:
    · RETURN

    '
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    "People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin


    Post Edited (Bean (Hitt Consulting)) : 11/2/2006 8:00:00 PM GMT
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2006-11-02 22:15
    Interesting...

    Ok. I finally have the one piece of information that I could not figure out before! Evidently the compiler is not simply copying the contents of the loaded file in place of the "Load" statement.

    It seems that the key to accomplishing what I have been trying to do is to be sure to place the “Program” or "Program Start" statement in the first file I attempt to load!


    Thanks a lot, guys!


    Now I have some code to organize and some resistors to find... (So I can try out those games Bean posted!) wink.gif

    - Sparks
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-11-02 22:51
    Sparks,
    I thought you meant after the Program Code header.
    But I rearranged the order of sections (moving Program up)
    and now have include files for constants, interrupt and subroutines.
    regards peter
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2006-11-03 19:41
    Thanks, Peter.

    That is what I was trying to achieve.


    - Sparks
Sign In or Register to comment.