On Thu, 26 Mar 2009, Rick wrote: > Looking for advice on a way to insure that only one of four push buttons is > active at one time. (IE - prevent multiple button press's) I have 4 pushbuttons > on Port A (16F88) and have AND'ed these bits out. The only idea that I've tossed > around so far is to rotate the bits and count them.. If count = 1 then only one > push button is selected. Is there a better way to do this? > > Regards, > > Rick A very simple solution would be to have an array of 16 flags. Each flag corresponds to a combination of pressed switches. You would use each flag to tell you if the combination is valid or not. 0000 0 no buttons pressed - invalid 0001 1 only button 0 pressed - valid 0010 1 only button 1 pressed - valid 0011 0 buttons 0 and 1 pressed - invalid 0100 1 only button 2 pressed - valid 0101 0 buttons 2 and 0 pressed - invalid 0110 0 buttons 2 and 1 pressed - invalid 0111 0 buttons 2, 1 and 0 pressed - invalid 1000 1 only button 3 pressed - valid 1001 0 buttons 4 and 0 pressed - invalid etc to 1111 then all you would need to do is use the pattern on the input port (masked so that it only looks as the pushbutton inputs) as an index into the array to see if it is valid or not. Regards Sergio Masci -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist