No longs? ... We don't need no stinking Longs ...
But a little N-Bit_MATH will definitely help. http://www.picbasic.co.uk/forum/showthread.php?t=12433
To go from decimal degrees to 16-bit binary it would take ...
65535 * degrees / 35999
If you were using an 18F with PBPL ... that's all you would need.
But if you don't want LONGs, then ...
65535 * anything bigger than 1 will take more than 16-bits.
And since DIV32 is really DIV31/15 ... 35999 is too big for the divisor (max is 32767).
So N-Bit_Math to the rescue.
And here's some of the output from a 16F876A ...Code:rxd var PORTC.7 txd var PORTC.6 HIGH txd Decimal_value_16bit var word '(0-65535) Decimal_value_12bit var word '(0-4098) degrees var word '(0-360) degrees_fraction var byte '(.xx) degree_Total var word '----[N-Bit Math]----------------------------------------------------------- PRECISION CON 4 SYSTEM ; 4 bytes=32-bit INCLUDE "N-Bit_MATH.pbp" Temp1 VAR BYTE[PRECISION] Temp2 VAR BYTE[PRECISION] '----[Main Program Loop]---------------------------------------------------- Main: serout2 txd,84,[13,10,"Enter Degrees (Max=359.99): "] serin2 rxd,84,[DEC degrees,DEC2 degrees_fraction] Degree_Total = degrees * 100 + degrees_fraction ASM MOVE?WP _degree_Total, _Temp1 ; copy degrees to a PVAR MOVE?CP 65535, _Temp2 ; put multiplier in a PVAR MATH_MUL _Temp1, _Temp2, _Temp1 ; Temp1 = DEG * 65535 MOVE?CP 35999, _Temp2 MATH_DIV _Temp1, _Temp2, _Temp1 ; Temp1 = Temp1 / 35999 (16-bit result) MOVE?PP _Temp1, _Temp2 ; copy result to Temp2 MATH_ROR _Temp2 ; rotate right 4 times MATH_ROR _Temp2 MATH_ROR _Temp2 MATH_ROR _Temp2 ; Temp2 is now 12-bits MOVE?PW _Temp1, _Decimal_value_16bit ; copy PVAR's to WORDs MOVE?PW _Temp2, _Decimal_value_12bit ENDASM serout2 txd,84,[13,10,"16-bit: ",HEX4 Decimal_value_16bit," ",DEC Decimal_value_16bit,13,10] serout2 txd,84,["12-bit: ",HEX4 Decimal_value_12bit," ",DEC Decimal_value_12bit,13,10] GOTO Main
![]()





Bookmarks