One thing that can improve this code is debouncing/repeat control. Often when handling button presses I use a timer. I will check for button presses at regular periods, say 10 mS or so. If a button press is found, I go ahead and process that press, but disable further checking for a long time, maybe a half second or a second. If I want key repeat, it is automatic with this scheme. Parabolic key repeat can be implemented by sortening the disable time on subsequent tests. If the button has been pressed and then is still pressed next time checking is disabled, then the disable time is shortened to half or so. Debounce happens in a straightforward way - if the button is ever sensed "down" it is assumed it was pressed down, and then it is not checked again for a while. This prevents the software from proccessing "pressed" "Not presed" "pressed again" "not presssed" etc. etc every 10 milliseconds. Some people like to test the key, wait a while, test it again and if it is still pressed then process it. Usually I do not process the key repeat in the timer interrupt, just set a flag - "THE_SELF-DESTRUCT_BUTTON_WAS_PRESSED = 1;" and then in the main loop, in a leisurely way, process that request and clear the flag. I write all this in C so the code won't directly apply to your situation. Mine is definitely not the simplest routine to use, if you want brief code you are going in the right direction. -- Lawrence Lile Bob Japundza Sent by: pic microcontroller discussion list 06/18/2004 12:01 PM Please respond to pic microcontroller discussion list To: PICLIST@MITVMA.MIT.EDU cc: Subject: [PIC]: anding/masking Hi All, I was wondering if my code below can be made to be a bit better. It works fine as is, but just seems to be a bit clunky to me. In a nutshell what I'm doing here is checking two buttons on port A, turning off/on the motor and if one button is pressed, that dictates motor direction. I'm wondering if there's a way without using the temporary register "button_status" to check the the two bits I'm looking at. movlw b'00001100' andwf PORTA,W ;mask all but the RA2,3 bits movwf button_status movlw b'00001100' xorwf button_status,w btfsc STATUS,Z ;are both buttons pressed? goto stopmotor ;yes, stop the motor movlw b'00001100' andwf button_status,w btfsc STATUS,Z ;are both buttons not pressed? goto stopmotor ;yes, stop the motor btfsc PORTA,2 ;check if up button is on goto motorup btfsc PORTA,3 ;check if down button is on goto motordown Regards, Bob -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body