The Conversions2 library is independent of the replacement lib, but the replacement lib uses Conversions2. It is therefore possible to use the Conversions2 library alongside the official conversions lib, but if one replaces the latter, one has to add Conversions2 lib to the ...Uses\P18 subdirectory.
For those that are unfamiliar with previous version of the Conversions2 library, a short description follows.
Conversions2 routines do not follow the way the official routines work. For example, routine Word2str converts number of type word to string of minimal length - not, like the official one, WordToStr, always to string of length 5. If one needs such formatting, one may use more general procedure, Word2strN, which may produce string of any (resonable) length with spaces filling the beginning of string. (Word2strN('123',st,5) gives st:=' 123' just like WordToStr.) The advantage of such approach is that strings of the same length may be produced (and displayed in simple way) from variables of different types:
Byte2strN(b,st,6);
Word2strN(w,st,6);
Int2strN(i,st,6);
If one needs to, one may replace spaces with other characters (like zeroes) using procedure StrReplChr from strings library replacement (http://www.mikroe.com/forum/viewtopic.php?t=20125). Additionally, Conversions2 routines converting strings to numbers detect errors and set the result to maximum value, if error occurs.
Due to use of assembly, the library produces smaller and faster code (up to several times) than the official one.
New library is also more extensive, introducing new functions and procedures. To differenciate from the official lib, different naming convention was assumed. Here is the list of routines in Conversions2 library:
Byte2Hex .................. Hex2Byte
Word2Hex ................ Hex2Word
Byte2Bin
Word2Bin
dWord2Bin
Bcd2Dec_8 ............... Dec2Bcd_8
Bcd2Dec_16 ............. Dec2Bcd_16
Byte2str .................... str2byte
Byte2strN
Short2str ................... str2short
Short2strN
Word2str ................... str2word
Word2strN
Int2str ....................... str2int
Int2strN
long2str ...................... str2long
dWord2str .................. str2dWord
float2str ..................... str2float
IP2str ......................... str2IP
MAC2str ..................... str2MAC
strU ............................ Val
strS
You'll find their descriptions in a Conversions2.txt file added to the library.
The real innovation of the library is function Val and procedures str (there are separate routines for signed and unsigned numbers) resembling those from Delphi.
Function Val converts string of length 1-11 to number of any type (but real) - defined by assignment instruction, like
byte_var:=Val('123',Res);
integer_var:=Val('-1234',Res);
dWord_var:=Val('12345678',Res);
Res (variable of type byte), like in Delphi, is zero when conversion is successful, indicates position of unrecognizable character (if spotted), or equals $FF, if the number is out of dWord type range, or negative limit for Longint.
If one uses conversions from string to numbers of different type, Val is the perfect choice, saving code space. On the other hand, if one uses only one type of variables, code will be faster when function corresponding to the type is used (like str2byte for numbers ranging from 0 to 255).
The str procedures, strU & strS, convert any (but real) unsigned/signed number to string using only required string space (i.e. working with bytes one may use just string[3] as output in strU). One may also wish to obtain strings of specified length, like
strU(number, output_string, 15);
where the number in string will be preceeded by spaces.
You may download the library here: http://www.cobir.com/ConvPRO.rar. Unpack it and place the Conversions2.mcl file in mP PRO installation directory where official libs for PIC18s are placed (...\Uses\PIC18). To be able to use the library, one has to add it's name to the uses clause in one's program:
Code: Select all
Uses Conversions2;
If one wants to use also the replacement lib (__Lib_Conversions.mcl), it's enough to replace the official lib in the ...\Uses\PIC18 subdirectory (it's advisable to save a copy of the official lib first).