Ok, now I smell what you're cooking.
I know you don't care about the 'Z' state, but you probably have to 'worry' about it in this case.
How about this... when you write to a port, you write the data register, when you read a port, you read the actual pin...so...
The button's are set up just like in the schematic above.
You set the pin to an output, and high...read back the pin...
If it's still high, either the one button pulling it high is pressed or, neither are pressed, if it's low, the other button is pressed...
Then you set the pin low...read back the pin...
If it's still low, the one button pulling it low is pressed or, neither are pressed, if it's high, the other button is pressed...
Problem with this approach is finding a low value to pull the pin far enough (either way) to change states, and yet not smoke the guts of the pin itself.
pinput var portd.0 : temp var bit : realinput var byte '0=lo, 1=hi, 2=no push
output pinput : pinput = 1 : temp = pinput
if temp = 0 then
realinput = 0 : goto finish
else
pinput = 0 : temp = pinput
if temp = 1 then
realinput = 1
else
realinput = 2 : goto finish
endif
endif
finish: 'done here
I haven't tried this, might work, might not. If you do go this route, start with high resistor values (10k or so) and work your way down. It'll either start working or smoke the PIC.
Personally, I like sougata's solution better. If you drop the cap and resistor values, you'll be able to drop the pause values as well, and make everything a lot faster.


						
					
				
				
				
				
			

Bookmarks