Using INCLUDES, FUNCTIONS PROCEDURES and SUBROUTINES in Oshonsoft

ericgibbs

Joined Jan 29, 2010
21,448
hi C,
First try removing the 'Space' character from the file names "slave mcu.bas" to say "slavemcu.bas"
Ensure the Include file and the code file are in the same folder.
E
 

ericgibbs

Joined Jan 29, 2010
21,448
hi C,
It is not a thumbs up, it was to show I had got your post and had downloaded it, and I was not sleeping on the job.;)

You have a problem on line #91 of your Code, if you try with that line remmed out it compiles.#

E
EG57_ 464.png
 

Thread Starter

camerart

Joined Feb 25, 2013
3,831
hi C,
It is not a thumbs up, it was to show I had got your post and had downloaded it, and I was not sleeping on the job.;)

You have a problem on line #91 of your Code, if you try with that line remmed out it compiles.#

E
View attachment 285285
Hi E,
Sorry, a bit too hasty :)
It always compiles, but in image #101. it shows the TRIS's are all inputs, so doesn't work.
C
 

ericgibbs

Joined Jan 29, 2010
21,448
hi,
This is not what you said in your opening post.
No mention of TRIS's, you said the Included file doesn't get Included in the compiled code.

Look at the compiled .lts file, the Include is being read by the compiler, you have an error elsewhere in your code.
E
EG57_ 465.png
 

Thread Starter

camerart

Joined Feb 25, 2013
3,831
hi,
This is not what you said in your opening post.
No mention of TRIS's, you said the Included file doesn't get Included in the compiled code.

Look at the compiled .lts file, the Include is being read by the compiler, you have an error elsewhere in your code.
E
View attachment 285286
Hi E,
I didn't pick out TRIS'S as I don't think any of the INTERRUPT is being read, perhaps apart from the CONFIGS.

I've never understood .LTS files, but now I can see that [ oxd8 ] is the setting for TRISA, and being accepted (interesting!) so perhaps it is being read, but somehow not being implemented as the program steps through the INCLUDE.
If I put the TRIS's (for example) in the main program, then they get set in the SIM, and 'live'
C.
 

sagor

Joined Mar 10, 2019
1,050
Not sure if this makes any difference, but one should always define all constants and variables before using them. Not sure how the compiler handles this in your case.
You are defining constants after you already put values into the TRIS registers:
Code:
TRISA = TRISAinit
TRISB = TRISBinit
TRISC = TRISCinit
TRISD = TRISDinit
TRISE = TRISEinit

'SET BITS ON/OFF before TRIS!
Const LATAinit = %00000000  'ON/OFF
Const LATBinit = %00000000
Const LATCinit = %00000000
Const LATDinit = %00000000
Const LATEinit = %00000000  'POSS MCLR RE3

'SET PIN IN/OUT 18F4431
Const TRISAinit = %11011000  '7=OSC, 6=OSC, 4=QEIB 3=QEIA 2=TEMP SEROUT
Const TRISBinit = %00000000
Const TRISCinit = %01000100  '6=1-slave4431_cs, 2=MOSI
Const TRISDinit = %00100000  '6=led, 7=led, 5=synch
Const TRISEinit = %00000000
I would do it this way:

Code:
'SET BITS ON/OFF before TRIS!
Const LATAinit = %00000000  'ON/OFF
Const LATBinit = %00000000
Const LATCinit = %00000000
Const LATDinit = %00000000
Const LATEinit = %00000000  'POSS MCLR RE3

'SET PIN IN/OUT 18F4431
Const TRISAinit = %11011000  '7=OSC, 6=OSC, 4=QEIB 3=QEIA 2=TEMP SEROUT
Const TRISBinit = %00000000
Const TRISCinit = %01000100  '6=1-slave4431_cs, 2=MOSI
Const TRISDinit = %00100000  '6=led, 7=led, 5=synch
Const TRISEinit = %00000000

TRISA = TRISAinit
TRISB = TRISBinit
TRISC = TRISCinit
TRISD = TRISDinit
TRISE = TRISEinit
 

Thread Starter

camerart

Joined Feb 25, 2013
3,831
Not sure if this makes any difference, but one should always define all constants and variables before using them. Not sure how the compiler handles this in your case.
You are defining constants after you already put values into the TRIS registers:
Code:
TRISA = TRISAinit
TRISB = TRISBinit
TRISC = TRISCinit
TRISD = TRISDinit
TRISE = TRISEinit

'SET BITS ON/OFF before TRIS!
Const LATAinit = %00000000  'ON/OFF
Const LATBinit = %00000000
Const LATCinit = %00000000
Const LATDinit = %00000000
Const LATEinit = %00000000  'POSS MCLR RE3

'SET PIN IN/OUT 18F4431
Const TRISAinit = %11011000  '7=OSC, 6=OSC, 4=QEIB 3=QEIA 2=TEMP SEROUT
Const TRISBinit = %00000000
Const TRISCinit = %01000100  '6=1-slave4431_cs, 2=MOSI
Const TRISDinit = %00100000  '6=led, 7=led, 5=synch
Const TRISEinit = %00000000
I would do it this way:

Code:
'SET BITS ON/OFF before TRIS!
Const LATAinit = %00000000  'ON/OFF
Const LATBinit = %00000000
Const LATCinit = %00000000
Const LATDinit = %00000000
Const LATEinit = %00000000  'POSS MCLR RE3

'SET PIN IN/OUT 18F4431
Const TRISAinit = %11011000  '7=OSC, 6=OSC, 4=QEIB 3=QEIA 2=TEMP SEROUT
Const TRISBinit = %00000000
Const TRISCinit = %01000100  '6=1-slave4431_cs, 2=MOSI
Const TRISDinit = %00100000  '6=led, 7=led, 5=synch
Const TRISEinit = %00000000

TRISA = TRISAinit
TRISB = TRISBinit
TRISC = TRISCinit
TRISD = TRISDinit
TRISE = TRISEinit
Hi S,
No good! Same result.

There is a Simulator speed control line in the INCLUDE:
[ Define SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC ]
This also doesn't compile into the program, and I'm not sure all of the rest of the INCLUDE does either, so I assume there's a bug?
Thanks,
C.
 

jjw

Joined Dec 24, 2013
823
Hi S,
No good! Same result.

There is a Simulator speed control line in the INCLUDE:
[ Define SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC ]
This also doesn't compile into the program, and I'm not sure all of the rest of the INCLUDE does either, so I assume there's a bug?
Thanks,
C.
Test it without include file and put everything in it into the main file.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,831
Test it without include file and put everything in it into the main file.
Hi J,
I've been trying lots of combinations of INCLUDE and MAIN also the HELP comment in #101, and it only works with it in the main program.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,831
Is it a problem to test without include files?
Hi J,
No problem! Perhaps my answer wasn't clear.
I tried moving each section of the INCLUDE into the main program, and anything in the INCLUDE is not used in the main program, so it all has to be in the program, and not the INCLUDE.
C
 

BobaMosfet

Joined Jul 1, 2009
2,211
Hi, EDIT: Title changed to suit the situation.

I'm working on a program, that is too long, so I need to use INCLUDES.

I've used them before and up to now, have avoided them, as I prefer all of the CODE on one page, but time has come to change.

How is what goes in an INCLUDE chosen? How long etc? I guess CODE that doesn't change goes in them.
C.
Don't think about an include as something magic - it isn't. All an include does is tell the compiler or interpreter that you want to load text from another file in, at the place where the include is. That's it.

the reason you use includes is so that you can organize things. Math routines/functions in one file that you include. Graphics routines/functions in another file you include. etc. 'routines' don't return a value. 'functions' do return a value. That is the difference between routines and functions.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,831
Don't think about an include as something magic - it isn't. All an include does is tell the compiler or interpreter that you want to load text from another file in, at the place where the include is. That's it.

the reason you use includes is so that you can organize things. Math routines/functions in one file that you include. Graphics routines/functions in another file you include. etc. 'routines' don't return a value. 'functions' do return a value. That is the difference between routines and functions.
Hi B,
Recently, I've had it explained why INCLUDES, PROCEDURES and FUNCTIONS are used, and I've just about got used to them now, and appreciate why they're there.
However, in this case, the INCLUDE appears in the .LTS file, but is not adopted in the the program, so the sttings in it aren't used.
It may be a bug, I'll report it later, if it isn't sorted out.
Thanks, C.
 
Top