Bob Japundza wrote: > 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 While it would seem that testing that a key is pressed would seem simple, it actually isn't because most applications need to know when it was RELEASED as well. In fact, for me, a keypress occurs when it is PRESSED THEN RELEASED. About 10 years ago I began using a bulletproof way to process keys: 1. I read the keys- all of them- every 10ms or so. I can either read 'em all at one tome, or rotate so that I read each one on a rotating basis. Doesn't matter how its done, it works perfectly regardless. 2. Every 10ms I read the key and shift its value into a register decicated just for that application. 3. If the key is ZERO when it is pressed, I look for the pattern b'11110000' on that key's register. When that is seen, that key was PRESSED AND RELEASED, so set a flag. To prevent more action, jam the key's register with '11111111' so it can't be used again. This works great. If anyone is interested, I'll publish some code. -- Just Another Bob -- Replier: Most attachments rejected -------------- Bob Axtell PIC Hardware & Firmware Dev http://beam.to/baxtell 1-520-219-2363 -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body