The datasheet is the PIC programmer best friend. Download it from here http://ww1.microchip.com/downloads/en/devicedoc/39637c.pdf See section 25 for the instrction set. If you still need help free feel to askkindly helping me to solve this: differential between PETFIE & RETURN
for pic18f4580
thx...
That's what I was referring to in my comment, i.e. the resulting effect of a normal Return used in a ISR ?EDIT2: the code in Example 4 has a serious bug. At CK_RB4, if that flag is it will GOTO RB4_CHG and flow into the exit routine using RETFIE. If not set, it erroneously flows into RB7_CHG where it will RETURN to the interrupted code without re-enabling GIE or restoring context.
I guess the simple answer is ignore that example. It’s a bug and shouldn’t be done like that. The interrupt uses exactly the same mechanism as any subroutine except the CALL instruction is jammed in by the hardware with a fixed target address (the interrupt vector at (0004h). When invoked, the return address is pushed on the stack and the PC is set to 0004h where you have to have the service routine. Within the service you can have calls and returns as you would with any other subroutine. When you return from the ‘hardware call’ at the end of the interrupt service, it works the same as any other subroutine return I.e. pops the return address off the stack and into the program counter to resume execution there.That's what I was referring to in my comment, i.e. the resulting effect of a normal Return used in a ISR ?
Max.
That's processor dependent. The "enhanced midrange" PIC processors automatically save various registers when an interrupt call happens, where a function call wouldn't save anything, and then RETFIE restores them, and again, a RETURN wouldn't do that. The items saved are:...
Note that there is nothing special about the stack operation between interrupts and normal calls. Interrupt and calls push the stack and return and retfie pop the stack. The only difference is the additional manipulation of GIE by the hardware interrupt and RETFIE.
IOC works by keeping a copy of the last PORTB value read in an internal register (D flip flops). The N-bit wide output of that register (previous port value) is compared to the current port value on each Q1 cycle (using a digital comparator). When pin(s) on the input of the port change the digital comparator outputs a flag (the mis-match flag) which is latched. Setting mis-match flag also sets the RBIF flip-flop. Note that the mis-match flag is driven by latched data and will be true even if the raw pins return to the original value - or change to something different. The only way to clear the mis-match condition is to read the PORT again. This causes the port input latch AND the compare latch to once again have the same value (the new port pin values) and that clears the mis-match. Only then can you clear RBIF. If you clear RBIF without reading the port, it will be immediately set again. Fig 5-12 in the datasheet shows the compare mechanism and extra latch for RB4. It's the same for the other IOC pins.One thing I am not completely clear on is all the IOC ISR routines open with:
move GPIO, W ; Clear mismatch condition.
??
Max.
I did mention that in #7 but not to that level of detail, thanks.That's processor dependent. The "enhanced midrange" PIC processors automatically save various registers when an interrupt call happens, where a function call wouldn't save anything, and then RETFIE restores them, and again, a RETURN wouldn't do that. The items saved are:
• W register
• STATUS register (except for TO and PD)
• BSR register
• FSR registers
• PCLATH register
They go to "shadow registers", not to the stack. The shadow registers are like any other registers, accessible via software if you ever wanted to do it, and the data sheet says "Upon exiting the Interrupt Service Routine, these registers are automatically restored. Any modifications to these registers during the ISR will be lost. If modifications to any of these registers are desired, the corresponding shadow register should be modified and the value will be restored when exiting the ISR."
I saw that comment this morning, and it didn't register (no pun) with me what you meant. I think that instruction, assuming you mean MOVF, would be a horrible first instruction for saving context. MOVF GPIO,W can affect STATUS,2. The datasheet recommends:MaxHeadRoom said:One thing I am not completely clear on is all the IOC ISR routines open with:
move GPIO, W ; Clear mismatch condition.
??
Max.
MOVWF W_TEMP ;Copy W to TEMP register
SWAPF STATUS,W ;Swap status to be saved into W
;Swaps are used because they do not affect the status bits
MOVWF STATUS_TEMP ;Save status to bank zero STATUS_TEMP register
The IC's refered to in Gooligum is the 12F629/12F683EDIT: I have found Googligum to be pretty reliable. Is there some chance of misunderstanding? Is it, per chance, referring to enhanced mid-range devices, like the 12F1840?
by Duane Benson
by Jake Hertz
by Jake Hertz
by Duane Benson