Menu

Clarification of include file usage

2 days ago
17 hours ago
  • philip leboeuf

    philip leboeuf - 2 days ago

    The code I wrote is this:

    #include "I:!GCbasic\Alarm System\PortsIO.h"
    in my main code which is: "Alarm System.gcb"

    in the 'PortsIO.h' file, I have port definitions:
    #Define DM13Data PortB.2

    Define DM13Clock PortB.3

    Define DM13Latch PortB.4

    followed by:
    dir DM13Data out 'DM13Data
    dir DM13Clock out 'DM13Select/clock
    dir DM13Latch out 'DM13Latch
    ' In the same file.

    in the do forever loop I have:

    do forever
    DM13display = LEDALL
    SendToDM13A DM13display
    wait 1 sec
    SendToDM13A 0
    wait 1 s
    loop

    It doesn't work but,
    if I write inside the do/loop:
    dir DM13Data out 'DM13Data
    dir DM13Clock out 'DM13Select/clock
    dir DM13Latch out 'DM13Latch

    it works, DM13A is an LED driver .

    the sub routine works fine, as long as I define the port direction in the main code and not in an include file...
    I even created a separate include file called: portdirset.h and placed the dir statements in there... Nothing.

    WHY?

     
  • Anobium

    Anobium - 2 days ago

    Hello,

    Post as an attachment your program as the code above is not complete.

     
  • Anobium

    Anobium - 2 days ago

    Hello,

    Post as an attachment your program as the code above is not complete.

     
  • Anobium

    Anobium - 1 day ago

    I guessed your code. See comments in the code.

    Your program may look like this.

    #chip 16f886
    #option Explicit
    #include "C:\temp\PortsIO.h"
    
    Dim DM13display as Byte
    Dim LEDALL as Byte
    
    // DM13init
    
    do forever
            DM13display = LEDALL
            SendToDM13A DM13display
            wait 1 sec
            SendToDM13A 0
             wait 1 s 
    loop
    

    Your I:!GCbasic\Alarm System\PortsIO.h needs to look like this.

    #option Explicit
    #startup InitDM13
    
    
    //! I would Recommend a script so you can change these constants in your main program
    // #Define DM13Data PortB.2
    // #Define DM13Clock PortB.3
    // #Define DM13LATCH PortB.4
    
    #SCRIPT
        IF NODEF(DM13DATA) THEN
            DM13DATA = PORTB.2
        END IF
        IF NODEF(DM13CLOCK) THEN
            DM13CLOCK = PORTB.3
        END IF
        IF NODEF(DM13LATCH) THEN
            DM13LATCH = PORTB.4
        END IF
    
    #ENDSCRIPT
    
    //!this code is never executed as this is not within a method
    dir DM13Data out        'DM13Data
    dir DM13Clock out       'DM13Select/clock
    dir DM13Latch out       'DM13Latch
    //!end of code that is never executed as this is not within a method
    
    
    
    
    
    Sub InitDM13
        Nop
        dir DM13Data out
        dir DM13Clock out
        dir DM13Latch out
    End Sub
    
    
    //! You to have called ONE SUB in this library to inform the compiler to load the library
    Sub SendToDM13A ( in somevar as Byte )
    
        Dir DM13Data In
    
    End Sub
    
     

    Last edit: Anobium 1 day ago
  • philip leboeuf

    Thanks for the reply. The attachment shows the actual code I am using with the INCLUDEs at the end.
    A little bit about my experience with Microchip etc.

    I started programming way back in 1976... Yea, I'm old.
    1- I was thrilled to finally find a basic language for the microchip/atmel systems.
    2- From 1993 to 2001, I was the second hire in a company producing remote controlled car starters/alarms. I looked at one of the first Microchip processors (a 512 word device) used for the remote car starter then later a 2k word device using 4 pages of memory. I can't remember the names of them at the time but it was early in Microchip's existance.
    3- After several years, the ceo of Microchip visited us in Montreal Canada to see our operation and told us we were the largest user of Microchip controllers on the east coast of north america and that if there was anything we needed from them, to call his number.
    4- Sales engineers for different processors would meet with me to see if we could use their processors and one of them happened to be Atmel. I was surprised to know that Microchip bought them out.
    So, you can see that I've been around. I wrote a basic translator for the Microchip micro controllers which translated basic to assembler then I would use Microchip's assembler to code the chips (back then requiring an external programmer.) My basic also allowed for inline assembler code which was simply: during parsing, if it wasn't a basic instruction, must be assembler so add it inline. I love the way GCBASIC seems to use the same concept making the resulting code 1:1.

    There are a few comments I have though of which I won't get into here, for now. Suffice it to say I will be donating a monthly amount to encourage the team to continue making it better.

    P.S. I wrote a visual basic 6-like IDE for the android phone several years ago and will more than likely build another one for GCBASIC. The best IDE so far has been the Visual Basic 6 ide.

    Thanks again.
    Let me know what my code says and what's wrong. Also, some of the document needs a bit of clarification such as: #startup works or is it like C's void setup block?

     
  • Anobium

    Anobium - 19 hours ago

    Thank you for the message — and for sharing your background. The attachment makes things much clearer, especially with the INCLUDEs at the end, so I appreciate you sending that over.

    See attached a new project.... recommended changes are in the ZIP. Do enjoy.

    You’ve had quite a journey with Microchip and embedded systems. Starting in 1976 puts you right at the beginning of the microcontroller era, and it shows in the way you describe those early PIC devices. A 512‑word part and then a 2K device with four pages… that really was the wild west of embedded development. Having the CEO of Microchip visit your operation in Montreal is remarkable. Not many people can say they were there when Microchip was still figuring out what it would become.

    And thank you for the support. Monthly contributions genuinely help keep the project moving forward, and feedback from someone with your depth of experience is invaluable.

    If you ever want to discuss any of those comments you mentioned — or bounce ideas about the IDE — I’d be happy to continue the conversation. Send me a Personal Message for my email address.

     

Log in to post a comment.