Beginner in need of help !!


Closed Thread
Results 1 to 40 of 72

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: Beginner in need of help !!

    Hi Rob,
    If you want the button to enable/disable the blining LED then you can't toggle the LED itself in the interrupt and then just continue to blink it in the main program loop. What you need is flag or semaphore telling the main loop if the LED is supposed to blink or not.
    Code:
    BLINK VAR BIT
    
    ON INTERRUPT GOTO int1 
    
    main:
    If Blink = 1 THEN
      HIGH LED
      PAUSE 500
      LOW LED
      PAUSE 500
    ENDIF
    GOTO main
    
    DISABLE
    int1:
    Blink = !Blink   ' Invert the state of the semapore
    RESUME
    ENABLE
    Please note that the PAUSE statement is basically delaying the Int1 routine from executing until the PAUSE statement finishes (that's the drawback of ON INTERRUPT). So if you push the button just as the PAUSE 500 start to exectute the ISR won't execute until 500ms later. This won't matter in this case but please keep that in mind when you start doing more complicated stuff.

    Also, the above does not incorporate any debounce, you may want to add that.

    /Henrik.

  2. #2
    Join Date
    Jan 2015
    Posts
    45


    Did you find this post helpful? Yes | No

    Default Re: Beginner in need of help !!

    Hi Henrik, thanks for explaing that to me it will help me a lot I am learning more & more as I go on

    Rob

    Quote Originally Posted by HenrikOlsson View Post
    Hi Rob,
    If you want the button to enable/disable the blining LED then you can't toggle the LED itself in the interrupt and then just continue to blink it in the main program loop. What you need is flag or semaphore telling the main loop if the LED is supposed to blink or not.
    Code:
    BLINK VAR BIT
    
    ON INTERRUPT GOTO int1 
    
    main:
    If Blink = 1 THEN
      HIGH LED
      PAUSE 500
      LOW LED
      PAUSE 500
    ENDIF
    GOTO main
    
    DISABLE
    int1:
    Blink = !Blink   ' Invert the state of the semapore
    RESUME
    ENABLE
    Please note that the PAUSE statement is basically delaying the Int1 routine from executing until the PAUSE statement finishes (that's the drawback of ON INTERRUPT). So if you push the button just as the PAUSE 500 start to exectute the ISR won't execute until 500ms later. This won't matter in this case but please keep that in mind when you start doing more complicated stuff.

    Also, the above does not incorporate any debounce, you may want to add that.

    /Henrik.

Similar Threads

  1. Beginner help!
    By Recognize in forum General
    Replies: 14
    Last Post: - 26th April 2012, 14:55
  2. pic24 beginner
    By robertpeach in forum General
    Replies: 23
    Last Post: - 13th August 2009, 11:57
  3. need help! to beginner
    By emilhs in forum mel PIC BASIC Pro
    Replies: 27
    Last Post: - 6th May 2009, 18:44
  4. Beginner at PB
    By alphahr in forum Off Topic
    Replies: 1
    Last Post: - 21st April 2008, 17:43
  5. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29

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