Thanks for asking, Thunderchild, because I've been working through this stuff myself lately. Anything following a semicolon (";'), is a remark, right? So whenever you see that, you've gotta think, "Ok, this isn't something the program's doing, it's something someone thought they'd write in there to make this all easier for me to understand. So what are they trying to tell me?"
Bear in mind I'm not an expert, just trying to work through it like you. Looking at the first part of the .inc
Code:
LIST
; P16F628.INC Standard Header File, Version 1.01 Microchip Technology, Inc.
NOLIST
; This header file defines configurations, registers, and other useful bits of
; information for the PIC16F628 microcontroller. These names are taken to match
; the data sheets as closely as possible.
; Note that the processor must be selected before this file is
; included. The processor may be selected the following ways:
; 1. Command line switch:
; C:\ MPASM MYFILE.ASM /PIC16F628
; 2. LIST directive in the source file
; LIST P=PIC16F628
; 3. Processor Type entry in the MPASM full-screen interface
;================================================= =========================
I'm not sure what the "LIST.. ...NO LIST" part's suppose to do exactly, so maybe someone else can clarify that. But the rest is all remarks, mostly describing four different ways that the programmer can select the processor. Kind of makes sense that the processor be selected before the include file, so that the compiler can be sure that it's using the appropriate code for the chip being used.
Code:
================================================= =========================
;
; Revision History
;
;================================================= =========================
;Rev: Date: Reason:
;1.01 13 Sept 2001 Added _DATA_CP_ON and _DATA_CP_OFF
;1.00 10 Feb 1999 Initial Release
;================================================= =========================
;
More remarks, this time on revision history. Pretty boring and nothing really to be bothered about - it's not exactly as exciting as the history channel, is it? Remember, as remarks, you could delete all this stuff from any include file, and it would make a difference - but don't! Someone, for some reason, saw some reason to put this stuff in there. You wouldn't want him to lose his job, would you?
Code:
=========================
IFNDEF __16F628
MESSG "Processor-header file mismatch. Verify selected processor."
ENDIF
;================================================= =========================
For all my smart remarks, you'd think I'd be able to shed some light on how the stuff that
isn't the code remarks works, but I can't. I'm not sure exactly how this "IF" statement works, but it looks like at this point in the .inc file it checks to make sure you did indeed select this particular chip before it goes ahead and does all the rest of the work in the .inc file. If the chip you've selected is different than this .inc file (i.e. the include file you've indicated in your .asm code in MPLAB), the .inc file returns an error at this point.
The rest of the include file is doing as Diver300 stated. It's essentially saying, "When the programmer writes this in assembly code, it equals (equ) this number." It's assistance that enables you to use assembly code that has more apparent meaning than if you had to use the actual numerical equivalents for certain registers. So it keeps you programming in assembly, instead of requiring you to think/program in what is basically hex.
Diver300 said:
Also it makes the source code more portable, meaning that it is easier to translate for other processors.
That's the best reason I can think of for using a .inc file for any given chip. Figuring out the hex equivalent registers for any one chip would be hard enough. Keeping them straight in your head (e.g. which hex values represent which register functions) when you start using more than one chip would be near impossible.