Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
50
Добавлен:
14.04.2015
Размер:
1.37 Mб
Скачать

218

Chapter 8. Library Reference

 

 

Routines by Category

This sections gives a brief overview of the major categories of routines available in the Cx51 standard library. Refer to “Reference” on page 232 for a complete description of routine syntax and usage.

NOTE

Many of the routines in the Cx51 standard library are reentrant, intrinsic, or both. These specifications are listed under attributes in the following tables. Unless otherwise noted, routines are non-reentrant and non-intrinsic.

Buffer Manipulation

Routine

Attributes

Description

memccpy

 

Copies data bytes from one buffer to another until a

 

 

specified character or specified number of characters has

 

 

been copied.

memchr

reentrant

Returns a pointer to the first occurrence of a specified

 

 

character in a buffer.

memcmp

reentrant

Compares a given number of characters from two different

 

 

buffers.

memcpy

reentrant

Copies a specified number of data bytes from one buffer

 

 

to another.

memmove

reentrant

Copies a specified number of data bytes from one buffer

 

 

to another.

memset

reentrant

Initializes a specified number of data bytes in a buffer to a

 

 

specified character value.

The buffer manipulation routines are used to work on memory buffers on a character-by-character basis. A buffer is an array of characters like a string, however, a buffer is usually not terminated with a null character (‘\0’). For this reason, these routines require a buffer length or count argument.

All of these routines are implemented as functions. Function prototypes are included in the STRING.H include file.

8

C51 Compiler

219

 

 

Character Conversion and Classification

Routine

Attributes

Description

isalnum

reentrant

Tests for an alphanumeric character.

isalpha

reentrant

Tests for an alphabetic character.

iscntrl

reentrant

Tests for a Control character.

isdigit

reentrant

Tests for a decimal digit.

isgraph

reentrant

Tests for a printable character with the exception of space.

islower

reentrant

Tests for a lowercase alphabetic character.

isprint

reentrant

Tests for a printable character.

ispunct

reentrant

Tests for a punctuation character.

isspace

reentrant

Tests for a whitespace character.

isupper

reentrant

Tests for an uppercase alphabetic character.

isxdigit

reentrant

Tests for a hexadecimal digit.

toascii

reentrant

Converts a character to an ASCII code.

toint

reentrant

Converts a hexadecimal digit to a decimal value.

tolower

reentrant

Tests a character and converts it to lowercase if it is

 

 

uppercase.

_tolower

reentrant

Unconditionally converts a character to lowercase.

toupper

reentrant

Tests a character and converts it to uppercase if it is

 

 

lowercase.

_toupper

reentrant

Unconditionally converts a character to uppercase.

The character conversion and classification routines allow you to test individual characters for a variety of attributes and convert characters to different formats.

The _tolower, _toupper, and toascii routines are implemented as macros. All other routines are implemented as functions. All macro definitions and function prototypes are found in the CTYPE.H include file.

8

220 Chapter 8. Library Reference

Data Conversion

Routine

Attributes

Description

abs

reentrant

Generates the absolute value of an integer type.

atof / atof517

 

Converts a string to a float.

atoi

 

Converts a string to an int.

atol

 

Converts a string to a long.

cabs

reentrant

Generates the absolute value of a character type.

labs

reentrant

Generates the absolute value of a long type.

strtod /

 

Converts a string to a float.

strtod517

 

 

strtol

 

Converts a string to a long.

strtoul

 

Converts a string to an unsigned long.

The data conversion routines convert strings of ASCII characters to numbers. All of these routines are implemented as functions and most are prototyped in the include file STDLIB.H. The abs, cabs, and labs functions are prototyped in the MATH.H include file. The atof517, and strtod517 function are prototyped in the include file 80C517.H.

8

C51 Compiler

221

 

 

Math Routines

Routine

Attributes

Description

 

 

acos / acos517

 

Calculates the arc cosine of a specified number.

 

 

asin / asin517

 

Calculates the arc sine of a specified number.

 

 

atan / atan517

 

Calculates the arc tangent of a specified number.

 

 

atan2

 

Calculates the arc tangent of a fraction.

 

 

ceil

 

Finds the integer ceiling of a specified number.

 

 

cos / cos517

 

Calculates the cosine of a specified number.

 

 

cosh

 

Calculates the hyperbolic cosine of a specified number.

 

 

exp / exp517

 

Calculates the exponential function of a specified number.

 

 

fabs

reentrant

Finds the absolute value of a specified number.

 

 

floor

 

Finds the largest integer less than or equal to a specified

 

 

 

 

number.

 

 

fmod

 

Calculates the floating-point remainder.

 

 

log / log517

 

Calculates the natural logarithm of a specified number.

 

 

log10 / log10517

 

Calculates the common logarithm of a specified number.

 

 

modf

 

Generates integer and fractional components of a

 

 

 

 

specified number.

 

 

pow

 

Calculates a value raised to a power.

 

 

rand

reentrant

Generates a pseudo random number.

 

 

sin / sin517

 

Calculates the sine of a specified number.

 

 

sinh

 

Calculates the hyperbolic sine of a specified number.

 

 

srand

 

Initializes the pseudo random number generator.

 

 

sqrt / sqrt517

 

Calculates the square root of a specified number.

 

 

tan / tan517

 

Calculates the tangent of a specified number.

 

 

tanh

 

Calculates the hyperbolic tangent of a specified number.

 

 

_chkfloat_

intrinsic,

Checks the status of float numbers.

 

 

 

reentrant

 

 

 

_crol_

intrinsic,

Rotates an unsigned char left a specified number of bits.

 

 

 

reentrant

 

 

 

_cror_

intrinsic,

Rotates an unsigned char right a specified number of bits.

 

 

 

reentrant

 

 

 

_irol_

intrinsic,

Rotates an unsigned int left a specified number of bits.

 

 

 

reentrant

 

 

 

_iror_

intrinsic,

Rotates an unsigned int right a specified number of bits.

 

 

8

 

reentrant

 

 

_lrol_

intrinsic,

Rotates an unsigned long left a specified number of bits.

 

 

reentrant

 

 

_lror_

intrinsic,

Rotates an unsigned long right a specified number of bits.

 

 

 

reentrant

 

 

 

222

Chapter 8. Library Reference

 

 

The math routines perform common mathematical calculations. Most of these routines work with floating-point values and therefore include the floating-point libraries and support routines.

All of these routines are implemented as functions. Most are prototyped in the include file MATH.H. Functions which end in 517 (acos517, asin517, atan517, cos517, exp517, log517, log10517, sin517, sqrt517, and tan517) are prototyped in the 80C517.H include file. The rand and srand functions are prototyped in the STDLIB.H include file.

The _chkfloat_, _crol_, _cror_, _irol_, _iror_, _lrol_, and _lror_ functions are prototyped in the INTRINS.H include file.

8

Соседние файлы в папке HLP