[Back] [Top] [Next]

12 C51 Library Functions

One of the main characteristics of C is its ability to allow complex functions to be constructed from the basic commands. To save programmer effort many common mathematical and string functions are supplied ready compiled in the form of library files.

12.1 Library Function Calling

Library functions are called as per user-defined functions, i.e


    #include ctype.h
    {
    char test_byte ;
    result = isdigit(test_byte) ;
    }

where "isdigit()" is a function that returns value 1 (true) if the test_byte is an ASCII character in the range 0 to 9.

The declarations of the library functions are held in files with a ".h" extension - see the above code fragment.

Examples are:

ctype.h, 
stdio.h, 
string.h etc.. 

These are included at the top of the module which uses a library function.

Many common mathematical functions are available such as ln, log, exp, 10x, sin, cos, tan (and the hyperbolic equivalents). These all operate on floating point numbers and should therefore be used sparingly! The include file containing the mathematical function prototypes is "math.h".

Library files contain many discrete functions, each of which can be used by a C program. They are actually retrieved by the linker utility covered in section 8. These files are treated as libraries by virtue of their structure rather than their extension. The insertion or removal of functions from such a file is performed by a library manager called LIB51.

12.2 Memory-Model Specific Libraries

Each of the possible memory models requires a different run-time library file. Obviously if the LARGE model is used the code required will be different for a SMALL model program.

Thus with C51, 6 different library files are provided:

C51S.LIB - SMALL model 
C51C.LIB - COMPACT model 
C51L.LIB - LARGE model

plus three additional files containing floating point routines as well as the integer variety.

C51 library functions are registerbank independent. This means that library functions can be used freely without regard to the current REGISTERBANK() or USING status. This is a major advantage as it means that library functions can be used freely within interrupt routines and background functions without regard to the current register bank.


[Back] [Top] [Next]