How to use include files?


Closed Thread
Results 1 to 16 of 16
  1. #1

    Default How to use include files?

    I would like to try some of the interrupts here http://www.picbasic.co.uk/forum/showthread.php?p=23259 but I'm not sure how to add the include files. The website seems to be defunct now. Can someone please explain to me how to use the include files?

  2. #2
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: How to use include files?

    Files and some examples can be downloaded from here: http://www.picbasic.co.uk/forum/cont...aylors-s-works

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: How to use include files?

    Quote Originally Posted by pedja089 View Post
    Files and some examples can be downloaded from here: http://www.picbasic.co.uk/forum/cont...aylors-s-works
    Thanks. But is there some sort of tutorial on how to actually install the include files?

  4. #4
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: How to use include files?

    Just copy them in same folder as your .pbp file, that is all.

  5. #5
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: How to use include files?

    Quote Originally Posted by pedja089 View Post
    Just copy them in same folder as your .pbp file, that is all.
    and then add the include statement in your main code, placing whatever file you want to include in quotes, for example

    Code:
    include "DT_INTS-18.bas"

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: How to use include files?

    Thanks! I was confused as to how you "physically" got the include file in there. I didn't realize it was as simple as just putting the file in the same folder as your .pbp file.

  7. #7
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: How to use include files?

    If you tend to use the same family of PICs, and the same hardware configurations (eg port B for an LCD display, or port A for input switches etc) then you can simply make one file with all the hardware definitions in, and then include that using one line in your main code.

    For example, I tend to use an 18F2620 or 18F4620 in most of my projects, and use the same LCD and pins for input switches so I have
    Code:
    '*******************************************************************************
    '  18F4620 config settings - for use with MPSAM
    '*******************************************************************************
    
    ASM 
      __CONFIG    _CONFIG1H, _OSC_HS_1H
      __CONFIG    _CONFIG2L, _PWRT_ON_2L  
      __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
      __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H  
      __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    
    '*******************************************************************************
    ' LCD (20 x 4) set up 
    '*******************************************************************************
    
    DEFINE LCD_DREG  PORTB                  ' LCD Data port
    DEFINE LCD_DBIT  0                      ' starting Data bit (0 or 4)
    DEFINE LCD_EREG  PORTB                  ' LCD Enable port
    DEFINE LCD_EBIT  5                      '     Enable bit  (on EasyPIC 5 LCD)
    DEFINE LCD_RSREG PORTB                  ' LCD Register Select port
    DEFINE LCD_RSBIT 4                      '     Register Select bit   (on EasyPIC 5 LCD)
    DEFINE LCD_BITS  4                      ' LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 4                      ' number of lines on LCD
    DEFINE LCD_COMMANDUS 2000               ' Command delay time in us 
    DEFINE LCD_DATAUS 50                    ' Data delay time in us 
    
    '*******************************************************************************
    ' Defines Statements
    '*******************************************************************************
    
    DEFINE  OSC 20                          ' 18F4520, 20mhz crystal
    ADCON1 = $0F
    clear    
    
    '*******************************************************************************
    'Analog and Comparator settings
    '*******************************************************************************
    
    ADCON0 = %00000000                      'AD converter module disabled
    ADCON1 = %00001111                      'All Digital
    ADCON2 = %00000000
    CMCON = 7                               'Disable Comparators
    
    '*******************************************************************************
    'Port and Register settings  (interrupts)
    '*******************************************************************************
        
    TRISA  = %00010111              
    TRISB  = %00000011 
    TRISD  = %00000011              
    T0CON  = %11000111
    
     ;----[UART Settings]------------------------------------------------------------
    
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 8   ' 9600 Baud @ SPBRGH = 2
    BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    
    
    RCSTA = $90   ' Enable serial port & continuous receive
    TXSTA = $24   ' Enable transmit, BRGH = 1
    SPBRG = 8     ' 9600 Baud @ -0.03%
    SPBRGH = 2
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    
    
    RCIF                VAR PIR1.5                    ' USART receive flag
    Char                VAR BYTE                      ' USART byte received
    GIE                 VAR INTCON.7 
    nTest               var byte
    
    '*******************************************************************************
    ' Pins used for connections to outside world
    '*******************************************************************************
    
    DecButton          var PORTA.0	        'Press to Decrement Button
    SetButton          var PORTA.1          'Press to Set/memorise Button
    IncButton          var PORTA.2	        'Press to Increment Button
    
    OnButton           var PORTA.0	        'Press to Decrement Button
    OffButton          var PORTA.2	        'Press to Increment Button
    
    H_butt             VAR PORTA.2          'hour increase 
    M_butt             VAR PORTA.0          'minutes increase
    S_butt             VAR PORTA.1          'set / memorise
    
    SCLpin             var PORTC.3          'RTC pin - clk
    SDApin             var PORTC.4          'RTC pin - data
    led                var PORTD.4
    An then save that as "hardware18F4620" and then in the main program use the
    Code:
    INCLUDE "hardware18F4620.pbp"
    Saves having to write out or copy and paste lots of code

  8. #8
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: How to use include files?

    You can copy and paste it straight into your main file if you want to see it, or change it.
    There are times when the include file is annoying, such as any variable you want to add in the include file has to be
    declared before your main code (i.e. in the include file).

  9. #9


    Did you find this post helpful? Yes | No

    Default Re: How to use include files?

    Can one put an Include within an Include file?

  10. #10
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,518


    Did you find this post helpful? Yes | No

    Default Re: How to use include files?

    Have you tried?

  11. #11


    Did you find this post helpful? Yes | No

    Default Re: How to use include files?

    Well no, but really I'm wondering if there is a limitation. Multiple includes with includes within them. Since it all "happens" before compile time, I suppose it doesn't matter?

  12. #12
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,518


    Did you find this post helpful? Yes | No

    Default Re: How to use include files?

    As far as I know - no, it doesn't matter.
    Whatever is in the included file gets put, byte for byte, where the INCLUDE "thisorthatfile.pbp" line is placed so you can have a source file wich includes two other files, which each includes two other files and so on. It's not a good idea to include the SAME file more than once though, if that's a "risk" you need to use conditionals to make sure it's only "compiled in" once even though it's included at several places.

    Disclaimer: I haven't done anything like the above.

    /Henrik.

  13. #13
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: How to use include files?

    The only issue I could see with having lots of include files for standard things, say routines for reading and RTC, writing to an EEPROM, updating an LCD etc is that you wouldn't have much code structure in the main program !

  14. #14


    Did you find this post helpful? Yes | No

    Default Re: How to use include files?

    Agreed Scampy, it could become more difficult to debug if there was some "hidden" conflict since it wouldn't be as readable.

  15. #15
    Join Date
    Aug 2016
    Posts
    22


    Did you find this post helpful? Yes | No

    Default Re: How to use include files?

    See below for Include file. This may help you.
    http://www.perlmonks.org/?node_id=393426

  16. #16
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: How to use include files?

    In what way does perl scrip help with PicBASIC pro ?

Similar Threads

  1. Post your INCLUDE files here
    By mackrackit in forum Code Examples
    Replies: 4
    Last Post: - 17th September 2011, 00:50
  2. Where are all the INCLUDE files??
    By Heckler in forum General
    Replies: 3
    Last Post: - 13th September 2011, 09:27
  3. Include Files for some Routines
    By rsocor01 in forum PBP Wish List
    Replies: 2
    Last Post: - 23rd April 2010, 20:13
  4. Using ASM files as include
    By Josuetas in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 15th August 2007, 21:40
  5. Modified include files
    By Joe Rocci in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th August 2006, 19:39

Members who have read this thread : 2

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