Interrupt handling on 16F628A


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116

    Cool Interrupt handling on 16F628A

    Hi you all!

    made a very small PBP programm that should work with external interrupts on RB.0.

    Ha! won´t work of course otherwise I won´t post this thread.

    Should send a pulse out on RB.7 (blink an LED) every time on rising edge at RB.0 , that means when a pulse gets in.
    Later on when the interrupt works a byte value should be loaded serially into the pic to calculate and cause a delay before the "blink" pulse. I got the serial communication working between two PICs . The value loading doesn´t need to be in sync with the input pulse but the start of the blink hat to. Damned!

    '************************************************* *******************************************
    ' 16F628A 4 Mhz crystal
    ' damn program should blink an LED every time a pulse goes into RB.0
    ' later a value should be serial loaded and set a delay before the blink pulse
    '************************************************* *******************************************

    '
    ' DEFINITIONS


    DEFINE OSC 4
    CMCON=%00000111
    inputData var word ' variable to receive data into
    pulseWidthVar var word



    ' START OF MAIN PROGRAM
    '
    CMCON = 7 ' RA0-RA3 are digital I/O
    TRISA = 0 ' PORT A is output
    TRISB = 1 ' RB0 is Input others output


    on interrupt goto ISr
    OPTION_REG = %01000000 'when RB.0 goes high the interrupt should work
    INTCON = %10010000

    main:
    portb.7 = 0

    serin2 portB.0,16468, [inputData] 'for the future to load a value
    pulseWidthVar = inputData

    goto main

    disable

    ISR:

    pulsout portb.7, 2000 'blink LED 0.02 sec one time when RB.0 goes high
    INTCON = %10010000
    RESUME 'resume main program
    Enable 'Enable interrupts

    END ' End of program


    Whats wrong with my interrupt?

    Thanks in Advance. You helped me quite a lot before!

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    You should be more selective in the things you change.
    Code:
    OPTION_REG = %01000000 'when RB.0 goes high the interrupt should work
    Apparently, the idea in that statement was to set INTEDG so that the interrupt would trigger on the Rising edge.

    Rising edge is the default, so it didn't need to be changed. But in the process, you've changed everything else in the OPTION register.

    The WDT prescaler is assigned to TMR0, and the WDT will now timeout in only 18 ms.
    Settings for TMR0 are changed too.
    PORTB Pull-ups are enabled, which is probably your main problem.

    When you want to change INTEDG, just change it

    OPTION_REG.6 = 1

    But then, like I said, it's already the default.<hr>
    Same thing applies to your use of INTCON.

    When using ON INTERRUPT, PBP controls the GIE bit (INTCON.7).
    Changing it yourself can cause problems.

    And change each bit individually, so that it doesn't interfere with other things.

    INTCON.1 = 0 ; Clear External Interrupt Flag
    INTCON.4 = 1 ; Enable External Interrupt

    -- or --

    INTF VAR INTCON.1
    INTE VAR INTCON.4

    INTF = 0 ; Clear External Interrupt Flag
    INTE = 1 ; Enable External Interrupt

    hth,
    DT

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

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