Interrupt question


Closed Thread
Results 1 to 3 of 3
  1. #1
    stone's Avatar
    stone Guest

    Default Interrupt question

    (first interrupt program attempt - thanks)

    I am trying to sense an interrupt signal on portb0 and then read portb1 and portb2 as inputs.

    Is this possible?

    This is a rotary encoder that is put thru a flipflop and I have used both outputs thru diodes as my interrupt trigger.

    It was working, but not correctly. I'm not sure if my board is noisy or if the program is not working correctly.

    I would like to know if intcon is set properly and if I need to set the register to make high priority interrupts.

    I'm a little confued about the datasheet, it doesn't seem to specifically talk about using portb<0-2>. And how does the pic know to watch for an interrupt on portb0?

    Thanks. /code below

    INCLUDE "modedefs.bas"
    DEFINE LOADER_USED 1
    DEFINE OSC 40
    value var byte
    cw var portB.1
    ccw var portB.2
    INTCON = %01001000
    TRISB.1 = 1
    TRISB.2 = 1

    value=0
    begin:
    on interrupt goto myint
    GOTO begin

    'Interrupt handler
    Disable
    myint:

    value = value + cw - ccw

    serout2 portc.6, 16468, [dec3 value,13,10]
    INTCON.1 = 0
    resume
    Enable

    END

    btw - is there a way to reset the printing using serout2 to the home position?

  2. #2
    stone's Avatar
    stone Guest


    Did you find this post helpful? Yes | No

    Default

    above, I'm using a pic 18F452 with the 40mhz clock

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    try this one
    Code:
    INCLUDE "modedefs.bas"
    DEFINE LOADER_USED 1
    DEFINE OSC 40
    
    TRISB.0 = 1
    TRISB.1 = 1
    TRISB.2 = 1
    TRISB.3 = 0
    TRISC.6 = 0
    
    PORTC.6 = 1
    DelayLoop var word
    value var byte
    cw var portB.1
    ccw var portB.2
    MainLoopStatuLED var PORTB.3
    
    INTCON = %10010000 'Enable all unmasked interrupt, Enable RB0/INT0 Interrupt
    
    on interrupt goto myint
    value=0
    
    begin:
         ' Main Loop will blink a led every 0.5 secondes     
         Toggle MainLoopStatusLED
         For delayloop = 1 to 50000
              Pauseus 10 ' using Pauseus to avoid interrupt latency
         Next
         GOTO begin
    
    
    'Interrupt handler
    Disable
    myint:
         value = value + cw - ccw
         serout2 portc.6, 16468, [dec3 value,13,10]
         INTCON.1 = 0
         resume
    Enable
    btw - is there a way to reset the printing using serout2 to the home position?
    Are you using a serial LCD???

    Try serout2 portc.6, 16468, [254,1,dec3 value,13,10]

    Make sure your MCLR pin (PIN1) is attach to 5V with a pull-up resistor. 0.1uF + 47 uF can be installed to your supply line, close to the pic, to avoid nois and glitches.

    try to remove all interrupt and test it in the main loop. Is it working without interrupt ?

    If nothing is better, can you provide your schematic ??
    Last edited by mister_e; - 25th January 2005 at 23:15.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Interrupt question
    By ultiblade in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 26th November 2009, 20:12
  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