EASy68K  
It is currently Thu Aug 22, 2019 10:01 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Hardware Switch Scanning
PostPosted: Mon Jul 08, 2019 7:10 pm 
Offline

Joined: Mon Jul 08, 2019 6:32 pm
Posts: 1
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!      '


Top
 Profile  
 
PostPosted: Fri Jul 12, 2019 2:13 pm 
Offline

Joined: Sun Nov 01, 2009 4:02 pm
Posts: 25
Location: Belgium
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

_________________
Greetings from Belgium
Hobby robot builder
www.marc-systems.be


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group