Interruption


Closed Thread
Results 1 to 15 of 15

Thread: Interruption

Hybrid View

  1. #1
    Join Date
    Dec 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Art View Post
    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  <- You forgot that if x = 8 and then x = 1 you must  go to loop or else x will never be 1 but MORE than one
    	x = x << 1
    ELSE
    	IF x = 1 THEN x = 8  <- Same here
    	x = x >> 1
    ENDIF ' direction
    ENDIF ' timerbyte
    
    goto loop
    I have pointed out some mistakes. Thanks for your code man anyway, cool way to do things, much better than ON INTERRUPT I believe. Don't be too harsh on me guys I've been learning this for less than a week

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I've been learning this for less than a week
    I would say you're definitely doing good for someone just getting started.

    It's nice here since you find so many various ways of doing something, which really
    helps one to think outside-the-box. Embedded programming is just creative problem
    solving, and you'll find a lot of different creative approaches around here for
    sure.

    Which one is best for your application is totally up to you.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Dec 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Thanks Bruce, you just pointed out the reason why I love programming and why I love programming a micro controller is because you can see the results in real life, not only digitally.

    Thanks, really

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