PDA

View Full Version : How to use include files?



keithv
- 22nd June 2016, 17:08
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?

pedja089
- 22nd June 2016, 17:59
Files and some examples can be downloaded from here: http://www.picbasic.co.uk/forum/content.php?r=517-darrel-taylors-s-works

keithv
- 22nd June 2016, 18:18
Files and some examples can be downloaded from here: http://www.picbasic.co.uk/forum/content.php?r=517-darrel-taylors-s-works

Thanks. But is there some sort of tutorial on how to actually install the include files?

pedja089
- 22nd June 2016, 18:21
Just copy them in same folder as your .pbp file, that is all.

Scampy
- 23rd June 2016, 08:26
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



include "DT_INTS-18.bas"

keithv
- 23rd June 2016, 17:30
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.

Scampy
- 24th June 2016, 13:47
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


'************************************************* ******************************
' 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


INCLUDE "hardware18F4620.pbp"


Saves having to write out or copy and paste lots of code

Art
- 27th June 2016, 15:32
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).

picster
- 19th August 2016, 18:22
Can one put an Include within an Include file?

HenrikOlsson
- 19th August 2016, 22:44
Have you tried?

picster
- 21st August 2016, 21:37
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?

HenrikOlsson
- 22nd August 2016, 06:20
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.

Scampy
- 22nd August 2016, 19:18
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 !

picster
- 23rd August 2016, 15:16
Agreed Scampy, it could become more difficult to debug if there was some "hidden" conflict since it wouldn't be as readable.

technotronix
- 24th August 2016, 11:20
See below for Include file. This may help you.
http://www.perlmonks.org/?node_id=393426

Scampy
- 24th August 2016, 17:46
In what way does perl scrip help with PicBASIC pro ?