28029 Parallax Inc, 28029 Datasheet - Page 157

KIT PARTS SMART SENSORS W/TEXT

28029

Manufacturer Part Number
28029
Description
KIT PARTS SMART SENSORS W/TEXT
Manufacturer
Parallax Inc
Datasheet

Specifications of 28029

Accessory Type
Parts Kit
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Contains lead / RoHS non-compliant
For Use With/related Products
BASIC Stamp® or Javelin Modules
Lead Free Status / RoHS Status
Lead free / RoHS Compliant, Contains lead / RoHS non-compliant
Other names
28029PAR
Example Program: TestCompassAveraged.bs2
PBASIC Division with Negative Numbers
The PBASIC division and modulus (/ and //) operators are for use with positive numbers. If
the numerator might be negative, the best approach is to save the numerator's sign before
taking its absolute value (sign = numerator.BIT15).
operation. Optionally, you can also round up or down depending on the remainder of the
division. Before you're done, check the sign, and if it's negative, make the result negative
(result = - result).
Free Download This program is available as a free .bs2 file download from the Smart
Sensors and Applications Product Page at www.parallax.com.
' Divide xSum
sign = xSum.BIT15
xSum = ABS(xSum)
x = xSum / 10
IF xSum // 10 >=5 THEN x = x + 1
IF sign = Negative THEN x = - x
sign = ySum.BIT15
ySum = ABS(ySum)
y = ySum / 10
IF ySum // 10 >=5 THEN y = y + 1
IF sign = Negative THEN y = - y
RETURN
numerator VAR Word
denominator VAR Word
result VAR Word
sign VAR Bit
Negative CON 1
Positive CON 0
' Division routine with a numerator that might be negative.
sign = numerator.BIT15
numerator = ABS(numerator)
result = numerator / denominator
IF numerator // denominator >= (denominator / 2) THEN
ENDIF
IF sign = Negative THEN result = - result
result = result + 1
Chapter 4: Hitachi HM55B Compass Module · Page 145
' Store sign of xSum
' Take absolute value
' x = the average measurement
' Fraction > .5? Round up
' if xSum negative, negate x
' Store sign of ySum
' Take absolute value
' y = the average measurement
' Fraction > .5? Round up
' if ySum negative, negate y
Then, perform the division

Related parts for 28029