If you post a section of code, please enclose it in "code tags" so the forum doesn't remove formatting. Paste it in the message window, highlight it with your mouse then click on the # symbol in the window header. I will add the code tags to your code for you this time.
When the assembler converts your instructions into a binary image so it will run in the PIC, it normally works from the first address (normally 0000H), stores the first instruction there and moves to the next address to store the next instruction and so on. The 'ORG' directive (its an instruction to the assembler, not a PIC instruction) makes the next instruction start at a different address. It gives you the ability to jump over some addresses which sometimes you have to do. What your code:
Code:
code is here
org 0
goto start
org 04h
BTFSS PIR1,TMR1IF
RETFIE
LCALL SECONDS
org 100h
start:
does is this:
'org 0' tells the assembler the following instruction is to be stored at address zero,
'goto start' creates the instruction to jump to the place you called 'start' at address zero
'org 04h' tells the assemble the next instruction is to be placed at address 4, so you skipped over addresses 1 ,2 and 3. I'll explain why this is done later.
the next two instructions are placed starting at address 4.
The 'LCALL' isn't quite right, it should just be 'call' in this case although it will still work in most cases.
'org 100h' moves the address for the next instruction to address 100h, so you left nearly 250 addresses unused!
In that PIC there are two special addresses, the reset vector (0000h) and the interrupt vector (0004h). They are both 'hard coded' inside the PIC and can never be changed. The reset vector is where the program counter picks up the first instruction after the power is turned on, the MCLR pin goes from low to high or a watchdog timeout occurs. So that's where your program is normally located so it runs straight away. The interrupt vector is the address the PIC automatically jumps to when an interrupt occurs, that's why you will find the interrupt service routine (ISR) is always located at address 0004h. Now you can see why the 'org 04h' is important, if you didn't use it the assembler might put instructions at address 04h that were nothing to do with the interrupt and cause chaos if an interrupt happened.
Instead of 'org 04h' you could have used other instructions to fill in the gap so the first ISR instruction was still at address 04 but that would mean if you changed those instructions the gap they filled may change size and the ISR be placed wrongly. Using the 'org' makes sure the address is always correct.
The normal way we start an assembly program is to put a jump instruction to the real starting address at 0000h, then move the address to 0004h and place the ISR there. After the end of the ISR code, we place the 'real' program to be run. That explains why we use labels in jump instructions rather than a numeric address. When the assembler runs, it goes through the code twice (that's why we call them two-pass assemblers!), the first pass ignores what the instructions actually do, it just looks to see if they are one byte or two bytes long and whether there are any 'org' lines that change the addresses. From this it can work out what addresses each of the labels will be at in the final binary image. It builds a list of labels and their addresses called a 'symbol table'. Then it makes the second pass, this time converting the assembler instructons to their binary equivalents and wherever a label is found it substitutes the value from the symbol table. It make the program very flexible because if you add or remove lines of code, the assembler will re-calculate all the label addresses for you.
Don't worry about it too much for now but there is an alternative way of writing your program in 'relocatable' code where the benefits of labels really show because you can write the code in modules are use them in other programs. Thats really useful if you write library routines.
Back to your program. If you remove the 'org 100h' altogether it will move the 'start' label from address 100h to the next address after "LCALL SECONDS" and save you lots of memory space. Also make the 'LCALL' a normal 'call' and it should assemble with no errors.
It still wont work though! You have a serious error in the ISR. See if you can get it to assemble using the suggestions I gave first.
Brian.