interrupts revisited

Discussion in 'Programmer's Corner' started by Chalma, Nov 14, 2013.

  1. Chalma

    Thread Starter Member

    May 19, 2013
    I am so glad I'm getting this 8051 stuff with programming but now I hit another snag. my code is much more modified and I didn't want to paste it here, but I posted before some of my other code. What I would like to happen is I have an interrupt associated with a button, and this button steps through modes, and I had code writting to led's to give me visual patters of what is going on, this code for the LED's has been replaced with significantly more advanced code and the interrupt is not meeting my needs. During one point I have the button cycle a mode that is switchcased and tells it what function to operate. But this interrupt allows the function to finish before it switched and I do not want that. For example in mode 3 I have a stepper motor being controlled, and it's not a safety issue yet but I don't want this stepper motor to execute if a user wants to get to mode 5 or 4. I especially don't want (when I get around to unilizing it) for it to send out streams of data via rs232 when it gets to that mode. My question basically is how do I make a HARD INTERRUPT vs this soft interrupt. I thought about it a little and I considered a 'reset' feature with a static variable, but I don't want it to reinitialize all my setup functions when it does this. Thanks in advance. I am only using functions and 1 button mode.
  2. Chalma

    Thread Starter Member

    May 19, 2013
    Code ( (Unknown Language)):
    2. #include normal stuff
    3. #inlude 'personal headers'
    5. interrupt_associatedwithbutton()
    6. {
    7. buttonmode++;
    8. turn interrupt flag off;
    9. }
    11. buttonmoderoutine();
    12. {
    13. switch (buttonmode)
    14. case:(0) donothing;
    15. case:(1) blink some leds;
    16. case:(2) delay 5 seconds start motor;
    17. case:(3)  delay 20 seconds start buzzer;
    18. case:(4) delay some start lcd;
    19. case:(5) delay some start rs232;
    20. case:(6) delay some blink leds
    21. case:(7) shut down motor;
    22. default: reset buttonmode 0;
    23. }
    25. void main() // main setup
    26. {
    27. initializestuff();
    28. moreinitstuff();
    29. somestartuproutines();
    30. while(1){
    31. buttonmoderoutine();
    32. }
    33. }
    here is the 'code' in half english half c++.

    Lets imagine a user wants to quickly get to mode 4 of my code they would have to cycle AND WAIT for the previous cases to execute this. I don't want this to happen. I hope I make sense in my above two posts.....I appologize for being an illeterate crazy person =P
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    Do you have another button? Then one button can pick the state (or mode) and the other pick GO !

    My way of driving my projects is to use 5 buttons in this pattern:

    Code ( (Unknown Language)):
    2.            UP
    4. LEFT      ENTER      RIGHT
    6.           DOWN
    I copied this pattern from my cable TV remote and it works well in many cases. Left & Right scrolls thru modes, Up and Down changes values, and Enter makes it so.

    If you just have one button you need to figure out a scheme to make it do different things. One way is the time it is pressed: a quick press goes to the next mode, but a longer press performs the current mode.

    Admission is the first step on the road to recovery. :D
    Chalma likes this.
  4. Chalma

    Thread Starter Member

    May 19, 2013
    sorry for the long delay. the end result for me, and it seems very similar to what you did is I have SL1000x wireless unit with a keyfob (in that exact pattern you set out). I ended up just cycling the modes while it was off then turning it on again (which I didn't really want but was a necessity to do so). The project is now on the backburner as I need to work on other things. Thanks for your reply =0)
    ErnieM likes this.