EASy68K http://www.easy68k.com/EASy68Kforum/ |
|
Hardware Switch Scanning http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=6&t=1679 |
Page 1 of 1 |
Author: | Straylight [ Mon Jul 08, 2019 7:10 pm ] |
Post subject: | Hardware Switch Scanning |
Hey all, I've been working on a 68k based hardware project for a while as a hobby. I have been trying to implement a button function but I'm having trouble figuring out a way to do it. The problem I'm currently having with my code is that if the button is held down, the option I want is repeatedly changed every time the program loops around again so I kinda hacked it with multiple btst. Also, with my current code the option changes the first time the button is pushed. What I want is to press the button, the LCD displays an option (eg "Hello World!"), click the button again, the option changes (eg "Goodbye World"), save that state when the screen is exited. If the state was "Goodbye" and I press the button from some other menu, I want it to say "Goodbye" and not change on the button push entry. Any advice? Here is my current rough code: Code: ButtonTest
btst #5,($FFE1AA).w bne next rts next bchg #0,($FFF0).w tst ($FFF0).w beq bye movea.l #heyworld,a1 bsr LCD_Output bra rts bye movea.l #byeworld,a1 bsr LCD_Output rts btst #5,($FFE1AA).w bne rts rts heyworld dc.b ' Hello ' dc.b ' World! ' byeworld dc.b ' Goodbye ' dc.b ' World! ' |
Author: | marc_256 [ Fri Jul 12, 2019 2:13 pm ] |
Post subject: | Re: Hardware Switch Scanning |
Hello Straylight, I think the best way to do this is to use two variables. ButtonStatusOld.b ButtonStatusNew.b ButtonState.b INITS: CLEAR THE VARIABLES BY START OF THE PROGRAM MOVE.B #$00,D0 MOVE.B D0,ButtonStatusOld MOVE.B D0,ButtonStatusNew MOVE.B D0,ButtonState RUN: Read button input If your button is released the ButtonStatus = 0 If you push the button the ButtonStatus = 1 If ButtonStatus = 1 and ButtonStateOld = 0 then ButtonStateNew = 1 ElseIf ButtonStatus = 1 and ButtonStateOld = 1 then ButtonStateNew = 2 EndIf Do your stuff ... ButtonStateOld = ButtonStateNew ButtonStateNew = 0 greetings, marc |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |