I have a working program that I was trying to tidy up, I thought I'd move some (all) of my #Define constants and port assignments into an #Include file. Having done this, the program compiles, but my 'Out' pins are being left in an ambiguous state. I'm not sure about the 'In' pins, I didn't test them.
Moving all my 'Dir' directives back into the main program file corrects this and the program (and in/outs) then works as normal.
'Defines header for JT'Pic 16F1829#Chip16F1829,32#ConfigCP=On'Read protected'LCD connection settings#DefineLCD_IO4#DefineLCD_SPEEDFAST#DefineLCD_NO_RW'Port assignments#DefineLCD_RSPortA.0#DefineLCD_EnablePortA.1#DefineLCD_DB4PortA.2#DefineLCD_DB5PortC.0#DefineLCD_DB6PortC.1#DefineLCD_DB7PortC.2#DefineSwallow_EnPortC.5#DefineC_EnPortA.4#DefineB_OutPortA.5#DefineUp_SwPortB.7#DefineDn_SwPortC.7#DefineL_SwPortC.6#DefineR_SwPortC.3#DefineOK_SwPortC.4#DefineT_EnPortB.6#DefineT_SenPortB.5#DefineB_SwitchPortB.4'Storage locations in Eeprom#DefineE_Tick0#DefineE_ErrorE_Tick+2#DefineE_StoreTE_Tick+4'Port directionsDirUp_SwInDirDn_SwInDirL_SwInDirR_SwInDirOK_SwInDirT_EnOutDirT_SenInDirB_SwitchInDirB_OutOutDirC_EnOutDirSwallow_EnOut
If the port directions are in the 'header' file, they fail to work.
If placed in the main file, below the #Include command, they do work.
Ahhh... Just answered (partially) my own question. I see that the compiler doesn't 'Include' the file at the location of the #Include directive, rather it is added at the foot of the main program file. I can only assume this is the reason for the program's failure. I must imagine that doing so messes with the compilation order relating to the direction of the ports.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The best option here would be to put the Dir commands into a subroutine, say "InitJT". Then, add a startup directive to the .h file, like so:
#startup InitJT
Then, if any constants from the file are used, or any subroutines from it are called, GCBASIC will call that subroutine at the start of the program.
The weird handling of #include and #define is something to look out for - unfortunately, there may not be a way of changing it that won't break many existing programs.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Many thanks for your suggestion. If I understand you correctly:
I could place my Dir commands within a subroutine that is itself placed into the header file.
Calling that sub with the #startup command, again, from within the header file?
I'll try that now. One mo.
Success! Thanks.
'Defines header for JT'Pic 16F1829#Chip16F1829,32#ConfigCP=On'Read protected'LCD connection settings#DefineLCD_IO4#DefineLCD_SPEEDFAST#DefineLCD_NO_RW'Port assignments#DefineLCD_RSPortA.0#DefineLCD_EnablePortA.1#DefineLCD_DB4PortA.2#DefineLCD_DB5PortC.0#DefineLCD_DB6PortC.1#DefineLCD_DB7PortC.2#DefineSwallow_EnPortC.5#DefineC_EnPortA.4#DefineB_OutPortA.5#DefineUp_SwPortB.7#DefineDn_SwPortC.7#DefineL_SwPortC.6#DefineR_SwPortC.3#DefineOK_SwPortC.4#DefineT_EnPortB.6#DefineT_SenPortB.5#DefineB_SwitchPortB.4#StartUpSetPortDir'Port directions cannot be set directly within'include files but can be called within a sub.'Storage locations in Eeprom#DefineE_Tick0#DefineE_ErrorE_Tick+2#DefineE_StoreTE_Tick+4SubSetPortDir'Port directionsDirUp_SwInDirDn_SwInDirL_SwInDirR_SwInDirOK_SwInDirT_EnOutDirT_SenInDirB_SwitchInDirB_OutOutDirC_EnOutDirSwallow_EnOutEndSub
The above placed into my header file works as expected. Many thanks for your assistance.
Regarding the handling of #Include and #Define and Dir, I wouldn't want anyone thinking I'm complaining, I was just bemused!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
And, with the v.0.95.010 compiler any variables defined in your header but not used will not be assigned and therefore not use any memory. This is stated in the Help but who reads the manual!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a working program that I was trying to tidy up, I thought I'd move some (all) of my #Define constants and port assignments into an #Include file. Having done this, the program compiles, but my 'Out' pins are being left in an ambiguous state. I'm not sure about the 'In' pins, I didn't test them.
Moving all my 'Dir' directives back into the main program file corrects this and the program (and in/outs) then works as normal.
If the port directions are in the 'header' file, they fail to work.
If placed in the main file, below the #Include command, they do work.
Ahhh... Just answered (partially) my own question. I see that the compiler doesn't 'Include' the file at the location of the #Include directive, rather it is added at the foot of the main program file. I can only assume this is the reason for the program's failure. I must imagine that doing so messes with the compilation order relating to the direction of the ports.
The best option here would be to put the Dir commands into a subroutine, say "InitJT". Then, add a startup directive to the .h file, like so:
Then, if any constants from the file are used, or any subroutines from it are called, GCBASIC will call that subroutine at the start of the program.
The weird handling of #include and #define is something to look out for - unfortunately, there may not be a way of changing it that won't break many existing programs.
Many thanks for your suggestion. If I understand you correctly:
I could place my Dir commands within a subroutine that is itself placed into the header file.
Calling that sub with the #startup command, again, from within the header file?
I'll try that now. One mo.
Success! Thanks.
The above placed into my header file works as expected. Many thanks for your assistance.
Regarding the handling of #Include and #Define and Dir, I wouldn't want anyone thinking I'm complaining, I was just bemused!
Dear Bemused,
There is no harm in asking.
Have a scan through glcd.h for a really good example of the use of these capabilities.
And, with the v.0.95.010 compiler any variables defined in your header but not used will not be assigned and therefore not use any memory. This is stated in the Help but who reads the manual!
Thanks, I didn't know that. Now I've got help working (mostly) on my iMac, I can swot up!
Dont forget... keep checking here.... https://sourceforge.net/p/gcbasic/discussion/579126/thread/39c8a635/