16F676 Interupt on Change pin determination


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Oct 2004
    Location
    Fayetteville Arkansas
    Posts
    44

    Default 16F676 Interupt on Change pin determination

    Melanie helped with some example code in this thread http://www.picbasic.co.uk/forum/showthread.php?t=3589
    and I figure I'm still confused somewhere in the setup. I defines both "OldPorta" and "NewPorta" which I THINK was the way to start it but when I get the interupt it just defaults to the operation for Porta.5. The following program was supposed to do the following.

    If pin Porta.5 is interupted an led would blink 4 times. Porta.4, 3 times, Porta.3, 2 times. Every time it is interupted it blinks 4 times no matter which pin. I can't seem to figure out, probibly from inexperience, what I'm doing wrong. If someone could help I'd appriciate it.


    @ DEVICE PIC16F676,INTRC_OSC_NOCLKOUT,WDT_ON,PWRT_OFF,BOD_O FF,PROTECT_OFF,CPD_OFF,MCLR_OFF
    ANSEL = 0 ' DISABLE THE ANALOG INPUT
    CMCON = 7 ' DISABLE COMPARATOR ON PORTA
    VRCON = 0 ' A/D Voltage reference disabled
    TRISA = %00111110 ' SETS ALL PORTA PINS TO INPUT ' Set PORTAA to all input
    WPUA = %00000110
    SYMBOL LED = PORTA.0
    I VAR WORD
    OLDPORTA VAR WORD
    NEWPORTA VAR WORD
    INTCON = %10000000
    IOCA = %00111000
    OPTION_REG = %00001000
    OUTPUT PORTA.0
    LOW LED
    PAUSE 1000
    HIGH LED
    GOTO BASE
    MYINT:
    NEWPORTA = PORTA
    INTCON = %10000000
    IF NEWPORTA.5 <> OLDPORTA.5 THEN
    ILOOP:
    I = I + 1
    IF I = 5 THEN
    resume BASE
    ENDIF
    LOW LED
    PAUSE 1000
    HIGH LED
    PAUSE 1000
    GOTO ILOOP
    ENDIF
    IF NEWPORTA.4 <> OLDPORTA.5 THEN
    I = I + 1
    IF I = 4 THEN
    resume BASE
    ENDIF
    LOW LED
    PAUSE 1000
    HIGH LED
    PAUSE 1000
    GOTO ILOOP
    ENDIF
    IF NEWPORTA.3 <> OLDPORTA.5 THEN
    I = I + 1
    IF I = 3 THEN
    resume BASE
    ENDIF
    LOW LED
    PAUSE 1000
    HIGH LED
    PAUSE 1000
    GOTO ILOOP
    ENDIF
    BASE:
    OLDPORTA = PORTA
    I = 0
    ON INTERRUPT GOTO MYINT:
    INTCON = %10001000
    LOOP:
    SLEEP 240
    GOTO LOOP

  2. #2
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Hi HH,
    Just at a quick glance, it looks like these two lines are off a bit:


    IF NEWPORTA.4 <> OLDPORTA.5 THEN < compares A.4 to A.5

    IF NEWPORTA.3 <> OLDPORTA.5 THEN < compares A.3 to A.5


    I think they should be:

    IF NEWPORTA.4 <> OLDPORTA.4 THEN

    IF NEWPORTA.3 <> OLDPORTA.3 THEN

    Arch

  3. #3
    Join Date
    Oct 2004
    Location
    Fayetteville Arkansas
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Sorry arch, I edited it to simplify it and may have messed that up. Let me check it and I'll post again.

  4. #4
    Join Date
    Oct 2004
    Location
    Fayetteville Arkansas
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    I fixed it and it still does the same thing. In addition, it seems that if I even get close to it sometimes it goes off. Is there a pin I should ground or have I really screwed something up?
    Last edited by BGreen; - 4th May 2006 at 01:10.

  5. #5
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    I tossed the code into MicroCode Studio to get a better look - think I see the problem...

    Code:
    	IF NEWPORTA.5 <> OLDPORTA.5 THEN
    ILOOP:
    		I = I + 1
    		IF I = 5 THEN
    			resume BASE
    		ENDIF
    		LOW LED : PAUSE 1000 : HIGH LED
    		PAUSE 1000
    		GOTO ILOOP
    	ENDIF
    
    	IF NEWPORTA.4 <> OLDPORTA.4 THEN
    		I = I + 1
    		IF I = 4 THEN
    			resume BASE
    		ENDIF
    		LOW LED : PAUSE 1000 : HIGH LED
    		PAUSE 1000
    		GOTO ILOOP  ; <<<<<<<<<< JUMPS BACK TO Iloop
    	ENDIF
    No matter which pin is interrupted, the code jumps back to "Iloop", which is in the middle of the "IF NEWPORTA.5 <> OLDPORTA.5 THEN" test. It loops there until done, blinking the LED as if A.5 were interrupted, no matter which pin actually caused it.

    Arch

    PS - on the erratic triggering, make sure your programmer is actually setting MCLR off, and check for 'floating' inputs.
    What value pullup/pulldowns are you using?
    Last edited by Archilochus; - 4th May 2006 at 01:27.

  6. #6
    Join Date
    Oct 2004
    Location
    Fayetteville Arkansas
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    I wasn't using anything but internals on this Arch. I'll check out what you posted and give it a whirl. Thanks for the help. I think my brain began to die after I passed 50.

Similar Threads

  1. Is this a K Type sensor?
    By jessey in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 21st November 2009, 13:55
  2. HELP !!! How change the voltage of a pin ????
    By stormdacta in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 21st August 2007, 20:55
  3. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  4. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07
  5. 16F676 Interupt
    By BGreen in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th March 2006, 20:56

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts