Interrupt mystery - need some guru help


Closed Thread
Results 1 to 40 of 44

Hybrid View

  1. #1
    xnihilo's Avatar
    xnihilo Guest

    Smile Interrupt mystery - need some guru help

    In the code below, something strange happens.
    (I'm using an LCD display to check what's happening in the program.)

    When the program starts, it seems to jump directly to the On Interrupt routine and when the porta pins states are displayed I see that the values are those I expect:
    A.0=1, A.1=1, A.2=1, A.3=0, A.4=1, A.5=1 so no interrupt should have occured because there is absolutely nothing connected to portA.

    WHY???

    Can someone help me to solve this mystery.

    Thanks for any help.














    @ device pic16F684, intrc_osc_noclkout, BOD_OFF, PWRT_OFF, wdt_off, mclr_off, protect_off

    DEFINE OSC 8 'set OSC value to 8MHz for instructions PAUSE, PAUSEus and SOUND

    '-----------------------------------------
    DEFINE LCD_DREG PORTC 'data port out is portc
    DEFINE LCD_DBIT 0 'data on portc0-portc3

    DEFINE LCD_RSREG PORTC 'rs is on portC5
    DEFINE LCD_RSBIT 5

    DEFINE LCD_EREG PORTC 'enable in on portC4
    DEFINE LCD_EBIT 4

    DEFINE LCD_BITS 4 '4bits data bus
    DEFINE LCD_LINES 2 '2lines display
    DEFINE LCD_COMMANDUS 2000 '2ms cmd delay
    DEFINE LCD_DATAUS 50 '50us data delay

    CLEAR

    OSCCON = %01110001
    CMCON0 = %00000111 'comparators OFF, val = 7
    ANSEL = %00000000 'choose digital i/o, val = 0
    OPTION_REG = %01111111 'enable porta weak pullups (no weak pull-up available for porta.3), p12
    WPUA = %110111 'enable internal weak pull ups resistors individually on portA pins to bring them HIGH internaly, except for porta.3 (Ra3 can be set as mclr or as i/o port with config words)
    INTCON = %10001000 'enable GIE and porta interrupts on change, datasheet p13
    IOCA = %111111 'no int for ra4 = r/s bit
    TRISA = %111111
    TRISC = %000000 'all portc pins are set to output mode, PWM starts if CCP1CON is enabled
    'PORTA = %000000 'turn off porta pins
    'PORTC = %000000 'turn off portc pins

    i VAR BYTE

    ON INTERRUPT GOTO in_sig 'when interrupt occurs on any portA pin (except portA.3) go to int routine

    loop1: 'main program is a stupid loop waiting for a int on change triggered by an ir signal on sensors

    '-----------------
    'test
    lcdout $fe,2 'home pos
    lcdout $fe,1,"loop1" 'clear and display
    '-----------------

    PAUSEus 15 'shortest pause possible to quickly jump to routine for extracting bullet signal contents
    'at 8MHz, minimum delay is 12 uS (or 24 uS at 4MHz)
    'in my routine, some uS can be wasted until the signal decoding occurs, too much and the signal will be invalid because of the offset
    GOTO loop1

    DISABLE
    'disable interrupts while executing the interrupt routine (do not put check interrupts calls after each instruction)
    in_sig: 'int routine code starts here
    '--------------
    for i = 0 to 5
    LCDOUT $FE, 1,"value",#i,"=",#portA.0(i)
    PAUSE 2000
    nEXT i

    INTCON.0 = 0

    resume 'end int routine
    enable 'REENABLE interrupts (global flag), PBP lame instruction

    END 'end of program

    '1. How can I reference a BIT in a BYTE?
    'http://www.picbasic.co.uk/forum/archive/index.php/t-544.html
    ' For MyVar=0 to 7
    'MyBit=MyByte.0(MyVar)
    'LCDOut $FE,1,"Bit ",#MyVar,"=",#MyBit
    'Pause 2000
    'Next MyVar

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    No mystery here...
    Re-read the IOC section in the datasheet...
    Your answer is there...

  3. #3
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Smile Interrupts

    yes, there are a lot of answers there.
    I'm not a programmer so it requires a lot of efforts for me to program. I'm new with PBP and PICs.
    It's pretty complicated and I'm tired because I work on my project every night till late so I must be missing the point. So if you know the answer, could you help me please.

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by xnihilo View Post
    I'm not a programmer so it requires a lot of efforts for me to program. I'm new with PBP and PICs.
    It's pretty complicated and I'm tired because I work on my project every night till late so I must be missing the point. So if you know the answer, could you help me please.
    I'm not a programmer either...just ask anybody around here!
    But you're answer really is in the datasheet, DS41202F, Section 4.2.3
    And if I tell you, then you will have learned but ONE single thing.
    If you figure it out, you'll have begun to understand a number of things...

  5. #5
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Default

    is it because pic sets all ports to input pins upon powerup?

  6. #6
    Join Date
    Mar 2004
    Location
    UK-Midlands
    Posts
    84


    Did you find this post helpful? Yes | No

    Default

    Hi xnihilo,

    skimask has pinpointed the passage in the datasheet that clearly tells you what you need to do before enabling the interrupt and after servicing the interrupt. I appreciate that English is probably not your first language but re-examine the paragraph and what it tells you is required before enabling the interrupt?

    Regards,
    Bob

Similar Threads

  1. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  2. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  3. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  4. NEWBIE: Some basic questions using interrupts
    By JackPollack in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2006, 02:59
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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