Hello, I have attempted to make a small subroutine to wait for the user to press the 2nd button before proceeding. Upon calling this subroutine twice in a row, it does not wait for a second keypress. I have asked in the IRC and a lovely OP by the name of KermPhD told me to request advice on debouncing. I'm fairly new to assembly programming, so I don't know where I can go to learn how to implement this. A pastebin of my subroutine: http://pastebin.com/cE8eRb7d
You have two options, before entering the routine you can check if [2nd] is being pressed, if it is loop until the key is not being pressed, or you can wait for the key to be released before exiting the routine. I'm not sure how keys are checked on the 84+CE, but it might be worth looking into the continuous scan mode.

Code:
waitfor2ndPROTO:
    di ; disable OS interrupts
    call setSingleMode
; first we need to make sure 2nd wasn't already pressed/held down before the routine was started
wait2ndReleased:
    ld a, (hl)
    cp %00100000
     jp z, wait2ndReleased
    call setSingleMode
; now we need to wait for 2nd to be released
wait2nd:
    ld a, (hl)
    sub %00100000
     jp nz, wait2nd
    ld (hl), a ; a = 0 (because sub %00100000 set the z flag)
    ei ; reenable interrupts
    ret

setSingleMode:
    ld hl, DI_Mode
    ld (hl), %00000010 ; set bit 1 to true, which puts the LCD in scan mode 2
    xor a, a ; set a to 0, which is the scanmode we should be in to continue
waitforLCDidle:
    cp (hl)
     jp nz, setSingleMode
    ld hl, kbdG1 ; load keyboard row 1 into hl and read the value into accumulator
    ret
If mode 3 works how i assume it does, the code could be a bit smaller since you wouldn't have to reset the keypad mode and could just keep reading from (hl). I dunno if this code works, i don't have a CE to test it out on.
For something like this, I would recommend the ROM call _GetCSC. Here's some (untested) code I threw together for you:


Code:

WaitFor2ndKey:
    call _GetCSC ; Checks if the user is pressing a key and, if so, returns it in register A
    cp a,sk2nd ; If the key pressed was [2nd]...
    ret z ; then return...
    jr WaitFor2ndKey ; else try again

This routine will wait until the user presses the [2nd] key. (It might not work if other keys are pressed at the same time.) You can also modify it to wait for another key, by changing sk2nd to any one of these codes. If you want the routine to wait for any key, replace cp a,sk2nd with or a,a and ret z with ret nz.

Hope that helps!
Hactar wrote:
For something like this, I would recommend the ROM call _GetCSC. Here's some (untested) code I threw together for you:


Code:

WaitFor2ndKey:
    call _GetCSC ; Checks if the user is pressing a key and, if so, returns it in register A
    cp a,sk2nd ; If the key pressed was [2nd]...
    ret z ; then return...
    jr WaitFor2ndKey ; else try again

This routine will wait until the user presses the [2nd] key. (It might not work if other keys are pressed at the same time.) You can also modify it to wait for another key, by changing sk2nd to any one of these codes. If you want the routine to wait for any key, replace cp a,sk2nd with or a,a and ret z with ret nz.

Hope that helps!


Thanks a million! I'll try using this. ^.^
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
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 vote in polls in this forum

 

Advertisement