Interruption


Closed Thread
Results 1 to 15 of 15

Thread: Interruption

Hybrid View

  1. #1
    Join Date
    Dec 2009
    Posts
    7

    Default Interruption

    Hello everyone, again!

    This time I'm wondering if there is any way to have an event(like a button press) interrupt the code and go to a line label at any time?

    The problem with my code is that the controller only checks for the button press after that pause. That pretty much means that you have to hold down the button to get the right timing in order for the moving LEDs to switch direction(which is what my code is about). So is there any way to interrupt the program at ANY time and then point it at a line label to continue there?

    this is my code:
    Code:
    x var byte
    switch var bit
    TRISA = 1
    TRISC = 0
    switch = 1
    
    mainloop:
    x = 1
    loop:
    PORTC = x
    pause 500
    if switch = 1 then
    	if PORTA.3 = 0 then
    		switch = ~switch
    		goto loop
    	endif
    	if x == 8 then 
    		goto mainloop
    	else
    		x = x << 1
    		goto loop
    	endif
    else
    	if PORTA.3 = 0 then
    		switch = ~switch
    		goto loop
    	endif
    	if x == 1 then
    		x = 8
    		goto loop
    	else
    		x = x >> 1
    		goto loop
    	endif
    endif

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Look at interrupt on change normally on PORTB.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Dec 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    We'll I've got a premade board - The PICKit 2 so the button is on the PORTA.3 pin - just like in the program. Is there no way to do it with that pin?

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Check the data sheet and see what that pin can do. If it has ADC then with some imagination you could do an ADC interrupt.
    But just change things around to use an interrupt pin. That is what they are for.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Talking

    Hi,

    My crystal ball says ...

    " Pickit2 with a ready made demo card means a 16F690 " ...

    RA.3 shows an Interrupt on change feature ...

    soooo ... just use it !!!

    Alain

    PS: try to give SOME MORE INFOS if you have further questions ...
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    An interrupt is overkill for this, and not the typical way to handle the problem at all.
    I'd use a counter to have your button checked every 10ms, and LED routine run every 500ms like this.
    and you get to save the interrupt for when it's actually needed.

    Code:
    x var byte
    direction var bit
    timerbyte var byte
    TRISA = 1
    TRISC = 0
    x = 1
    
    loop:
    PORTC = x
    pause 10
    timerbyte = timerbyte + 1
    
    IF PORTA.3 = 0 then
    IF direction = 0 THEN
    direction = 1
    ELSE
    direction = 0
    ENDIF ' direction
    ENDIF ' button
    
    IF timerbyte = 50 THEN timerbyte = 0 ' 500ms has passed if timerbyte = 0
    
    IF timerbyte = 0 THEN
    IF direction = 0 THEN
    	IF x = 8 THEN x = 1
    	x = x << 1
    ELSE
    	IF x = 1 THEN x = 8
    	x = x >> 1
    ENDIF ' direction
    ENDIF ' timerbyte
    
    goto loop
    Last edited by Art; - 30th December 2009 at 23:24.

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