C51库函数

1.前言

重新回来审视单片机的开发,发现C51居然也支持库函数的开发。库函数中支持printf的串口输出函数、memcpy类的内存操作函数、malloc/free类的内存申请与释放函数、sin类的数学计算函数。

库函数的使用不仅可以加快开发效率,还能提供友好的程序跨平台移植特性。

2.库函数

C51库函数的帮助文档可以在Keil4的安装目录下找到,相对地址为:Keil4\C51\hlp\c51.chm,文档内的Library Reference目录下有以类别划分的库函数(Routines By Category)、有头文件介绍(Include Files)、有单个函数的介绍(Reference)。其中划分的库函数类别主要有:

缓存操作类(Buffer Manipulation Routines)

字符类(Character Routines)

数据转换类(Data Conversion Routines)

数学类(Math Routines)

内存分配类(Memory Allocation Routines)

IO流类(Stream I/O Routines)

字符串类(String Routines)

可变长度参数(Variable Length Argument Routines)

本征库函数(Intrinsic Routines)

其他(Miscellaneous Routines)

3.详细分类

缓存操作类(Buffer Manipulation Routines)

RoutineIncludeDescription
memccpystring.hCopies data bytes from one buffer to another until a specified character or specified number of characters has been copied.
memchrstring.hReturns a pointer to the first occurrence of a specified character in a buffer.
memcmpstring.hCompares a given number of characters from two different buffers.
memcpystring.hCopies a specified number of data bytes from one buffer to another.
memmovestring.hCopies a specified number of data bytes from one buffer to another. This routine is typically used when the two buffers may overlap.
memsetstring.hInitializes a specified number of data bytes in a buffer to a specified character value.

字符类(Character Routines)

RoutineIncludeDescription
isalnumctype.hTests for an alphanumeric character.
isalphactype.hTests for an alphabetic character.
iscntrlctype.hTests for a Control character.
isdigitctype.hTests for a decimal digit.
isgraphctype.hTests for a printable character with the exception of space.
islowerctype.h 
isprintctype.hTests for a printable character.
ispunctctype.hTests for a punctuation character.
isspacectype.hTests for a whitespace character.
isupperctype.hTests for an uppercase alphabetic character.
isxdigitctype.hTests for a hexadecimal digit.
toasciictype.hConverts a character to an ASCII code.
tointctype.hConverts a hexadecimal digit to a decimal value.
tolowerctype.hTests a character and converts it to lowercase if it is uppercase.
_tolowerctype.hUnconditionally converts a character to lowercase.
toupperctype.hTests a character and converts it to uppercase if it is lowercase.
_toupperctype.hUnconditionally converts a character to uppercase.

数据转换类(Data Conversion Routines)

RoutineIncludeDescription
absmath.hGenerates the absolute value of an integer type.
atofstdlib.hConverts a string to a float.
atoistdlib.hConverts a string to an int.
atolstdlib.hConverts a string to a long.
cabsmath.hGenerates the absolute value of a character type.
labsmath.hGenerates the absolute value of a long type.
strtodstdlib.hConverts a string to a float.
strtolstdlib.hConverts a string to a long.
strtoulstdlib.hConverts a string to an unsigned long.

数学类(Math Routines)

RoutineIncludeDescription
acosmath.hCalculates the arc cosine of a specified number.
asinmath.hCalculates the arc sine of a specified number.
atanmath.hCalculates the arc tangent of a specified number.
atan2math.hCalculates the arc tangent of a fraction.
ceilmath.hFinds the integer ceiling of a specified number.
cosmath.hCalculates the cosine of a specified number.
coshmath.hCalculates the hyperbolic cosine of a specified number.
expmath.hCalculates the exponential function of a specified number.
fabsmath.h 
floormath.hFinds the largest integer less than or equal to a specified number.
fmodmath.hCalculates the floating-point remainder.
logmath.hCalculates the natural logarithm of a specified number.
log10math.hCalculates the common logarithm of a specified number.
modfmath.hGenerates integer and fractional components of a specified number.
powmath.hCalculates a value raised to a power.
randstdlib.hGenerates a pseudo random number.
sinmath.hCalculates the sine of a specified number.
sinhmath.hCalculates the hyperbolic sine of a specified number.
srandstdlib.hInitializes the pseudo random number generator.
sqrtmath.hCalculates the square root of a specified number.
tanmath.hCalculates the tangent of a specified number.
tanhmath.hCalculates the hyperbolic tangent of a specified number.
_chkfloat_intrins.hChecks the status of a floating-point number.
_crol_intrins.hRotates an unsigned char left a specified number of bits.
_cror_intrins.hRotates an unsigned char right a specified number of bits.
_irol_intrins.hRotates an unsigned int left a specified number of bits.
_iror_intrins.hRotates an unsigned int right a specified number of bits.
_lrol_intrins.hRotates an unsigned long left a specified number of bits.
_lror_intrins.hRotates an unsigned long right a specified number of bits.

内存分配类(Memory Allocation Routines)

RoutineIncludeDescription
callocstdlib.hAllocates storage for an array from the memory pool.
freestdlib.hFrees a memory block that was allocated using calloc, malloc, or realloc.
init_mempoolstdlib.hInitializes the memory location and size of the memory pool.
mallocstdlib.hAllocates a block from the memory pool.
reallocstdlib.hReallocates a block from the memory pool.

IO流类(Stream I/O Routines)

RoutineIncludeDescription
getcharstdio.hReads and echoes a character using the _getkey and putchar routines.
_getkeystdio.hReads a character using the 8051 serial interface.
getsstdio.hReads and echoes a character string using the getchar routine.
printfstdio.hWrites formatted data using the putchar routine.
putcharstdio.hWrites a character using the 8051 serial interface.
putsstdio.hWrites a character string and newline ('\n') character using the putchar routine.
scanfstdio.hReads formatted data using the getchar routine.
sprintfstdio.hWrites formatted data to a string.
sscanfstdio.hReads formatted data from a string.
ungetcharstdio.hPlaces a character back into the getchar input buffer.
vprintfstdio.hWrites formatted data using the putchar function.
vsprintfstdio.hWrites formatted data to a string.

字符串类(String Routines)

RoutineIncludeDescription
strcatstring.hConcatenates two strings.
strchrstring.hReturns a pointer to the first occurrence of a specified character in a string.
strcmpstring.hCompares two strings.
strcpystring.hCopies one string to another.
strcspnstring.hReturns the index of the first character in a string that matches any character in a second string.
strlenstring.hReturns the length of a string.
strncatstring.hConcatenates up to a specified number of characters from one string to another.
strncmpstring.hCompares two strings up to a specified number of characters.
strncpystring.hCopies up to a specified number of characters from one string to another.
strpbrkstring.hReturns a pointer to the first character in a string that matches any character in a second string.
strposstring.hReturns the index of the first occurrence of a specified character in a string.
strrchrstring.hReturns a pointer to the last occurrence of a specified character in a string.
strrpbrkstring.hReturns a pointer to the last character in a string that matches any character in a second string.
strrposstring.hReturns the index of the last occurrence of a specified character in a string.
strspnstring.hReturns the index of the first character in a string that does not match any character in a second string.
strstrstring.hReturns a pointer in a string that is identical to a second sub-string.

可变长度参数(Variable Length Argument Routines)

RoutineIncludeDescription
va_argstdarg.hRetrieves an argument from an argument list.
va_endstdarg.hResets an argument pointer.
va_startstdarg.hSets a pointer to the beginning of an argument list.

本征库函数(Intrinsic Routines)

RoutineIncludeDescription
_chkfloat_intrins.hChecks the status of a floating-point number.
_crol_intrins.hRotates an unsigned char left a specified number of bits.
_cror_intrins.hRotates an unsigned char right a specified number of bits.
_irol_intrins.hRotates an unsigned int left a specified number of bits.
_iror_intrins.hRotates an unsigned int right a specified number of bits.
_nop_intrins.hExecutes one NOP instruction.
_pop_intrins.hPops an SFR from the hardware stack using the POP instruction.
_push_intrins.hPushes an SFR onto the hardware stack using the PUSH instruction.
_testbit_intrins.hTests the value of a bit and clears it to 0.

其他(Miscellaneous Routines)

RoutineIncludeDescription
setjmpsetjump.hSaves the current stack condition and program address.
longjmpsetjump.hRestores the stack condition and program address.
_nop_intrins.hInserts an 8051 NOP instruction.
_testbit_intrins.hTests the value of a bit and clears it to 0.

4.例程

Keil4为C51提供了较为丰富的例程,例程在Keil的安装目录下,相对地址为:Keil4\C51\Examples。

 

参考资料:

1. Keil C51的库函数

2. Keil C51的库函数

附件:

 

  • 6
    点赞
  • 49
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值