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
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
 

Moof

Full Member level 2
Full Member level 2
Joined
Nov 21, 2003
Messages
149
Helped
7
Reputation
14
Reaction score
3
Trophy points
1,298
Location
Argentina
Activity points
1,230
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
 

pixel

Advanced Member level 2
Advanced Member level 2
Joined
Sep 16, 2004
Messages
508
Helped
69
Reputation
138
Reaction score
16
Trophy points
1,298
Activity points
3,993
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
 

R00KIE

Full Member level 2
Full Member level 2
Joined
Jan 19, 2003
Messages
149
Helped
23
Reputation
46
Reaction score
3
Trophy points
1,298
Location
Portugal
Activity points
1,240
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.
 

scorpionss22

Full Member level 2
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

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
 

XNOX_Rambo

Advanced Member level 1
Advanced Member level 1
Joined
Jul 13, 2002
Messages
434
Helped
90
Reputation
180
Reaction score
2
Trophy points
1,298
Location
Far out, man!
Activity points
3,568
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top