PDA

View Full Version : Inverting Input Values



Peter1960
- 21st August 2005, 07:14
Hi,
Is there a simple way to invert the dta you want,ie

I have an input going from 5 volt to 0 volts, but I would like
the converted value to read 0 - 5 volts.

I have a Sunday Brain Block!

regards

Peter

Darrel Taylor
- 21st August 2005, 07:41
Depending on what you need...

T VAR BIT
B VAR BYTE

T = ~PORTB.0 ; Single pin

B = ~PORTB ; Invert Full Port

B = PORTB ^ %00000001 ; Read full port and invert bit 0

OR, if you meant Analog values, simply subtract the value from the highest possible A/D reading.

; --- For 8bit results ---
ADCIN 0, B
B = 255 - B

; --- For 10bit results ---
ADCIN 0, W
W = 1023 - W
<br><br>

Peter1960
- 21st August 2005, 07:58
Darryl, your light helped!

Of course all waht you do is subract it from the highest number. as analogue 1024-value.

thks!

Peter

Darrel Taylor
- 21st August 2005, 08:02
Make sure you use 1023, not 1024.

10bit values go from 0 to 1023<br><br>

Peter1960
- 21st August 2005, 08:09
Got that Darrel,

now working like beauty!

cheers

Peter