Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

When using interrupt for 16F84 where to write org 04 ?

Status
Not open for further replies.

scorpionss22

Full Member level 2
Joined
Jan 8, 2004
Messages
146
Helped
4
Reputation
8
Reaction score
1
Trophy points
1,298
Activity points
1,284
interrupt

hi all iam trying to learn pic16f84
when i wanna use interrupt
where i must write org 04
in the programm in whiche place
thanks
 

Re: interrupt

I always start in this way, for any 16 and 12 family:


org 0x00000

goto start

org 0x0004


: interrupt code here:
:
:
:
iret

start: movlw asaslkñjdf


this is an example of my program, with a macro for save w reg and status before got into interrupt:



push macro
movwf WBuffer ;save w reg in Buffer
swapf WBuffer, F ;swap it
swapf STATUS,W ;get status
movwf StatBuffer ;save it
endm
;
pop macro
swapf StatBuffer,W ;restore status
movwf STATUS ; /
swapf WBuffer,W ;restore W reg
endm
;
org 0
goto Start ;skip over interrupt vector
;
org 4

;It is always a good practice to save and restore the w reg,
;and the status reg during a interrupt.

push
call ServiceInterrupts
pop
retfie
;
Start
clrf TempE
call InitPorts
call InitTimers
 
Re: interrupt

Also if you want to place Interrupt routine elsewhere in youtr program you can below org 0x0004 specify od interrupt service routine label:


org 0x00000
goto start
org 0x0004
goto ISR ;on interrupt go to label ISR


.
.
.


ISR




retfie
 
Re: interrupt

it is also good practise not to write interrupt code starting at the interrupt vector because if you get used to doing it and you change micro-controller you may get into trouble.
so it should look like

org 0x0000
goto start

org 0x0004
goto int1

org 0xsomething
goto int2 ;if it exists

start
;put main code here

int1
;put interrupt code here
RETFIE


int2
;put interrupt code here
RETFIE

Also as Moof said you should save W and important registers that may get affected during interrupt servicing and you should also disable interrupts while servicing the interrupt to avoid an interrupt beying interrupted.
 
interrupt

i read thar the program memory begin at address 0000h
so i must put in it org00
and in the address 0004h
i must put org04
is this wright
so i cant put org04 in 0002h
?????????????????
thanks for cooperation
 

Re: interrupt

"org" is an instruction to the assembler and org 0x0004 means "put the instruction
that follows at address 0004h".

You only have to use "org" when you need to put an instruction at some specific
address and it is especially used with interrupts as each interrupt has a fixed
address whereto the program "jumps" when the interrupt is triggered.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top