Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

.INC includes in header

Status
Not open for further replies.

AGCB

Member
I've been starting to put some of the program routines that I use often into .inc files,
stored in MPASM/suite. It makes the visible program much shorter and easier to scroll.
At first I was getting an error "overwritng previous address" when I included them in the header. I found that if the include directive was put at the end of the program, that everything worked OK. But I don't remember seeing it this way in other peoples programs.
Am I doing something wrong or is this the way it should be done? It seems if there are any CBLOCK directives after the includes that there is where the problem lies. Thanks Aaron
 
The .inc files seen included at the top of other .asm files are header files. They would normally contain constant definitions (e.g. settings values or pin assignments) and macros.

If you want to split your project up into multiple files, then do so.. but the normal way is to have multiple .asm files holding the code; they are all linked together by the MPASM linker.

If you just want to #include code, just note that the file contents of the included file with replace the #include statement. Therefore put the #includes at a more appropriate position such as the end of the program if they contain functions and code. This way they won't be overwriting the code you've placed in the .asm file after "ORG 0"

Have a look here for info on multiple file projects in MPLAB: https://www.electro-tech-online.com/custompdfs/2013/02/PIC_Base_A_3.pdf
 
Thanks dougy.
What I take from your reply is that what I'm doing is OK. I read the linked tutorial now and 3 years ago. I do not use relocatable code although I tried, it just seems like more trouble than it's worth to me. Aaron
 
Here is an example from a PIC program I have been working on in tha past few days.

At the beginning of the program is the INC file for the processor definitions
Code:
		list		p=16F887, r=dec, w=-302
		include		<P16F887.INC>
;		__config	_CONFIG1,b'1110000011100100'
;		__config	_CONFIG2,b'1111100011111111'

I then put the interupt routine in an include file.
Code:
		org		0x000			;reset vector address
		goto		Start
 
		org		0x004			;interrupt vector address
		#include	<Interupt_Handler.inc>
Start
		call		Initialise_PIC

And finally all the other includes with my standard bit of code which I use from project to project, at the end of the program.
Code:
;*********************************************************************************************************
;**				     Includes								**
;*********************************************************************************************************
		#include	<LCD_Routines.inc>
;		#include	<bin2asc.inc>
		#include	<BIN8BCD.inc>
		#include	<Initialisation_Routine.inc>
		#include	<Timers_8Mhz.inc>

		end					;end of file

When you have a chunk of code which does something usefull and you would like to use it in several places, and if it is well debugged and working, just put it in an INC file and call it as a subroutine.

Then when you are tearing your hair out trying to decide why the main program does not work, a simple command such as

Call Initialise_PIC
or
Call Write_to_LCD

tells exactly what is happening there, instead of having to scroll through a page of code which is already working (Hopefully!).

JimB
 
Jim
Apart from the ISR, that's what I'm doing. It also works, I find, to put an .inc file of MACROS in the header. Any others only work if at end of program, so they don't interfere with variables. I also put all the variables for a particular routine with the routine so I don't have to add them somewhere esle or even think about them. Thanks. Aaron
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top