Thought I already did.
It's using hardware to do what should and can be done in software.
Like wiring a circuit to turn the pic's power off to turn an LED off.
and developing bad habit at the same time, and not learning anything.
Thought I already did.
It's using hardware to do what should and can be done in software.
Like wiring a circuit to turn the pic's power off to turn an LED off.
and developing bad habit at the same time, and not learning anything.
Well after you made an edit to your post you have some explanation.
Looping back through the code every so often to check on a button smells like some sort of pasta to me.
Maybe the OP should learn to use the hardware. Then when the code grow to more than a few lines......
Wait a minute. Your joking, right?
Using an interrupt is forming bad habits.
Now I get it.
NOT!
Dave
Always wear safety glasses while programming.
When it's not needed, I think it is.
What if the platform didn't support interrupts?
I think using an interrupt when it isn't needed is forming a bad habit.
The loop is happening anyway, and I have one less label in my code.
It's less spaghetti than the original which doesn't run in one single loop.
An interrupt would add more spaghetti in the generated asm to goto 0x04.
This is a simple program, but as it grew, you might need an interrupt for something else.
EDIT; ps I edited to edit the program, but haven't actually run it.
if it has any issue, it still offers a solution.
Last edited by Art; - 31st December 2009 at 00:25.
Fair enough.
Good to see all possible solutions and reasons for the solutions.
Dave
Always wear safety glasses while programming.
I'll give it a shot with a simple ON INTERRUPT version.
There must be ten gozillion ways to do something like this, even without an interrupt, butCode:x var BYTE Switch VAR BIT TRISA = $FF TRISC = 0 ANSEL = 0 ' A/D disabled (all digital) ANSELH = 0 IOCA.3 = 1 ' int-on-change enabled for RA3 INTCON = %10001000 ' enable global & int-on-change interrupts Switch = 1 ON INTERRUPT GOTO MyISR mainloop: x = 1 loops: PORTC = x pause 500 if switch = 1 then if x == 8 then goto mainloop else x = x << 1 goto loops endif else if x == 1 then x = 8 goto loops else x = x >> 1 goto loops endif endif GOTO mainloop ' just in case DISABLE MyISR: WHILE PORTA.3=0 ' wait for button release (so we can clear the int flag & be WEND ' sure it interrupts on a high-to-low transition) Switch = ~Switch ' toggle Switch INTCON.0 = 0 ' clear interrupt flag bit RESUME END
it's still handy to at least learn about interrupts.
Note that you could also do something similar by just monitoring the interrupt flag-bit with
global interrupts disabled. You just need to get a tad more creative...;o}
Tap & release the button as fast as you can to see how quickly it reacts.
Last edited by Bruce; - 31st December 2009 at 01:00. Reason: Tap & release fast
Bookmarks