Searching \ for 'Simple RB0/INT setup question.' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=simple+rb0int+setup
Search entire site for: 'Simple RB0/INT setup question.'.

Truncated match.
PICList Thread
'Simple RB0/INT setup question.'
1998\10\15@204117 by netquake

flavicon
face
Hello piclisters!

I want to use an external interrupt source (on RB0/'INT)
to wake up my PIC from SLEEP .
Are these previous steps OK?

LIST    p=16F84
include   <p16f84.inc>
; compiled with MPASM v02.13

       ORG     0
       goto    start
       nop                     ;filling the gap with nops up to 0x4
       nop
       nop
       ORG     4
       goto    inter           ;INT/RB0 should put PC here (0x0004) when droppe
d LOW

start   bcf     INTCON,GIE      ;disable global int. bit
       btfsc   INTCON,GIE      ;test if done
       goto    start           ;not done, retry
       bsf     INTCON,INTE     ;use RB0 as external interrupt source
       bsf     STATUS,RP0      ;select mem bank 1
       bcf     0x1,INTEDG      ;interrupt on falling edge (0x1 is option reg.)
       movlw   b'00000110'     ;hate this bank switching stuff!
       movwf   0x5             ;0x5 is trisa
                               ;RA0 output, RA1 & RA2 inputs
       bsf     0x6,0           ;set RB0 as input (0x6 is trisb)
                               ;(Must I set RB0 as an input in order to get it
                               ; to work as an
external interrupt?)
       bcf     STATUS,RP0      ;back to bank 0
       clrf    FSR             ;clear indirect addr. reg.
       bsf     PORTA,0 ;RA0 HIGH
       bsf     INTCON,GIE      ;enable global interrupts
       sleep


;0004h : We should get here when interrupted

inter   bcf     INTCON,GIE      ;disable ints while in this routine
       [some more code]
       goto loop
       [some more code]        ;must I enable global int bit before 'sleeping'?
       sleep                   ;Can I do this?

loop    [some more code]
       sleep                   ;Will sleep always be coming back to 0x4 vector?

Is it OK not to use RETFIE ?
Will this pseudo code put the program counter at 0x4 every time RB0 pin
switches from HIGH to LOW?

Sorry, I'm confused!

P.D: Thanks to James Cameron and Regulus Berdin for their
help on coding.


--------------------------------------------
"I must not fear. Fear is the mind-killer.
Fear is the little death that brings total
obliteration. I will face my fear... I will
permit it to pass over me and through me."

Kwisatz Haderach - Dune

       netQ
<spam_OUTnetquakeTakeThisOuTspaminnocent.com>

1998\10\15@233509 by Regulus Berdin

flavicon
face
netQ wrote:
>
> Is it OK not to use RETFIE ?
You should use RETFIE, but in your program you should include a loop to
put to sleep again your pic.

Example:

start:
       ...
infiniteloop:
       ...
       sleep
       nop                     ;this nop is NEEDED!
       ...
       goto infiniteloop

> Will this pseudo code put the program counter at 0x4 every time RB0 pin
> switches from HIGH to LOW?
Your interrupt routine (0x04) will be called every edge transition of
RB0 (high-to-low and low-to-high).

Reggie.

1998\10\18@200042 by Tony Nixon

flavicon
picon face
netQ wrote:
>
> Hello piclisters!
>
> start   bcf     INTCON,GIE      ;disable global int. bit
>         btfsc   INTCON,GIE      ;test if done
>         goto    start           ;not done, retry

Probably not necessary to do this because the GIE bit = 0 on power up.

>         bsf     0x6,0           ;set RB0 as input (0x6 is trisb)
>                                 ;(Must I set RB0 as an input in order to get i
t                                 ; to work as an
> external interrupt?)

For normal RB0Int use, yes.

I think you can also trigger this interrupt, if enabled, if RB0 is set
as an output because the input circuits are also connected to the output
drivers.

>        bcf     STATUS,RP0      ;back to bank 0
>        clrf    FSR             ;clear indirect addr. reg.
>        bsf     PORTA,0 ;RA0 HIGH
>        bsf     INTCON,GIE      ;enable global interrupts
>        sleep

You should have a loop here because the PC will end up pointing to an
instruction following SLEEP, which you don't have.

Try this..

Loop    sleep
       nop
       goto Loop

The 'nop' is executed after the interrupt occurs and before the
interrupt routine begins.

> inter   bcf     INTCON,GIE      ;disable ints while in this routine
>         [some more code]
>         goto loop
>         [some more code]        ;must I enable global int bit before 'sleeping
'?
>         sleep                   ;Can I do this?
>
> loop    [some more code]
>         sleep                   ;Will sleep always be coming back to 0x4 vecto
r?


The GIE bit is automatically cleared when an interrupt is responded to
so you do not need 'bcf INTCON,GIE'. Instead you need to clear the
RB0Int flag, otherwise the interrupt will recur when the GIE bit is set
to 1 again.

You should have a RETFIE to finish your interrupt routine. Then after
that executes, the 'goto sleep' instruction will execute and put the PIC
back to sleep.

inter   bcf     INTCON,INTE      ;clear int. bit

       [some more code]
       goto loop
       [some more code]
       retfie

loop    [some more code]
       retfie



> Is it OK not to use RETFIE ?

I gather that you want to keep waking the PIC each time an RB0Int
occurs, so you need to use the RETFIE instruction to reenable the RB0INT
interrupt. If you omit the RETFIE and use a RETURN, then the interrupt
will not happen again because GIE will stay = 0. If you do not use
either of these instructions then the stack will overflow.

> Will this pseudo code put the program counter at 0x4 every time RB0 pin
> switches from HIGH to LOW?

If the PIC is asleep AND the GIE bit = 1, then after the RB0Int
interrupt occurs, the instruction following the sleep instruction is
executed and then the PC is loaded with address 0004h.


Hope this helps.

--
Best regards

Tony

Multimedia 16F84 Beginners PIC Tools.
**New Improved PicNPost**

http://www.picnpoke.com
Email .....picnpokeKILLspamspam@spam@cdi.com.au

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...