免费的单片机C语言常用头文件

合集下载

单片机C语言常用头文件

单片机C语言常用头文件

下 列函数注意在你调用任意内存分配程序比如.. calloc malloc 和realloc)之前必须调用 _NewHeap 来初始化堆heap int abs(int i) 返回i 的绝对值 int atoi(char *s) 转换字符串s 为整型数并返回它字符串s 起始必须是整型数形式字符否则返回0 double atof(const char *s) 转换转换字符串s 为双精度浮点数并返回它字符串s 起始必须是浮点数形式字符串 long atol(char *s) 转换字符串s 为长整型数并返回它字符串s 起始必须是长整型数形式字符否则返回0 void *calloc(size_t nelem, size_t size) 分配"nelem"个数据项的内存连续空间每个数据项的大小为size 字节并且初始化为0 如果分 配成功返回分配内存单元的首地址否则返回0 void exit(status) 终止程序运行典型的是无限循环它是担任用户main 函数的返回点 void free(void *ptr) 释放ptr 所指向的内存区 void *malloc(size_t size) 分配size 字节的存贮区如果分配成功则返回内存区地址如内存不够分配则返回0 void _NewHeap(void *start, void *end) 初始化内存分配程序的堆一个典型的调用是将符号_bss_end+1 的地址用作"start"值符号 _bss_end 定义为编译器用来存放全局变量和字符串的数据内存的结束加1 的目的是堆栈检 查函数 使用_bss_end 字节存贮为标志字节这个结束值不能被放入堆栈中 extern char _bss_end; _NewHeap(&_bss_end+1, &_bss_end + 201); // 初始化200 字节大小的堆 int rand(void) 返回一个在0 和RAND_MAX 之间的随机数 void *realloc(void *ptr, size_t size) 重新分配ptr 所指向内存区的大小为size 字节size 可比原来大或小返回指向该内存区的地 址指针

C语言头文件大全(free)

C语言头文件大全(free)

<bitset> -- for defining a template class that administers sets of bits
<complex> -- for defining a template class that supports complex arithmetic
<deque>
-- (STL) for defining a template class that implements a deque container
<exception> -- for defining several functions that control exception handling
<fstream> -- for defining several iostreams template classes that manipulate exteral files
defined
<iostream> -- for declaring the iostreams objects that manipulate the standard streams
<istream> -- for defining the template class that performs extractions
<slist>
The Standard C++ library consists of 51 required headers.This implementation also includes
three additional headers,<hash_map>,<hash_set>,and <slist>,not required by the C++ Standard,

C语言这些常用的标准库(头文件),你不得不知道...

C语言这些常用的标准库(头文件),你不得不知道...

C语⾔这些常⽤的标准库(头⽂件),你不得不知道...有很多⼯程师喜欢⾃⼰封装⼀些标准库已有的函数,其实⾃⼰封装的函数,并不⼀定⽐标准库好,有时候反⽽代码更冗余,且有bug。

下⾯⼩编就来分享⼀下C语⾔常见的⼀些标准库。

标准头⽂件包括:<asset.h><ctype.h><errno.h><float.h><limits.h><locale.h><math.h><stdio.h><signal.h><time.h><stddef.h><stdlib.h><string.h><stdarg.h><setjmp.h>⼀、标准定义(<stddef.h>)⽂件<stddef.h>⾥包含了标准库的⼀些常⽤定义,⽆论我们包含哪个标准头⽂件,<stddef.h>都会被⾃动包含进来。

这个⽂件⾥定义:●类型size_t(sizeof运算符的结果类型,是某个⽆符号整型);●类型ptrdiff_t(两个指针相减运算的结果类型,是某个有符号整型);●类型wchar_t(宽字符类型,是⼀个整型,其中⾜以存放本系统所⽀持的所有本地环境中的字符集的所有编码值。

这⾥还保证空字符的编码值为0);●符号常量NULL(空指针值);●宏offsetot (这是⼀个带参数的宏,第⼀个参数应是⼀个结构类型,第⼆个参数应是结构成员名。

offsetot(s,m)求出成员m在结构类型t的变量⾥的偏移量)。

注:其中有些定义也出现在其他头⽂件⾥(如NULL)。

⼆、错误信息(<errno.h>)<errno.h>定义了⼀个int类型的表达式errno,可以看作⼀个变量,其初始值为0,⼀些标准库函数执⾏中出错时将它设为⾮0值,但任何标准库函数都设置它为0。

C51常用头文件

C51常用头文件

C51常用头文件在KEIL 中,对于单片机所使用的头文件,除了reg51 reg52以外,还有一些从各芯片制商的官网下载与reg51,reg52功能类似的头文件,需了解透外,还要对各类型单片机均可通用且相当有用的的头文件,做相应的了解。

因为,内部所包含的函数与宏定义,可以及大的方便我们编写应用程序1字符函数 ctype.h1 extern bit isalpha(char);功能:检查参数字符是否为英文字母,是则返回12 extern bit isalnum(char)功能:检查字符是否为英文字母或数字字符,是则返回13 extern bit iscntrl(char)功能:检查参数值是否在0x00~0x1f 之间或等于0x7f,是则返回14 extern bit isdigit(char)功能:检查参数是否为数字字符,是则返回15 extern bit isgraph(char)功能:检查参数值是否为可打印字符,是则返回1,可打印字符为0x21~0x7e 6 extern bit isprint(char)功能:除了与isgraph相同之外,还接受空格符0x207 extern bit ispunct(char)功能:不做介绍。

8 extern bit islower(char)功能:检查参数字符的值是否为小写英文字母,是则返回19 extern bit isupper(char)功能:检查参数字符的值是否为大写英文字母,是则返回110 extern bit isspace(char)功能:检查字符是否为下列之一,空格,制表符,回车,换行,垂直制表符和送纸。

如果为真则返回111 extern bit isxdigit(char)功能:检查参数字符是否为16进制数字字符,是则返回112 extern char toint(char)功能:将ASCII字符0~9 a~f(大小写无关)转换成对应的16进制数字,返回值00H~0FH13 extern char tolower(char)功能:将大写字符转换成小写形式,如字符变量不在A~Z之间,则不作转换而直接返回该字符14 extern char toupper(char)功能:将小写字符转换成大写形式,如字符变量不在a~z之间,则不作转换而直接返回该字符15 define toascii(c) ((c)&0x7f)功能:该宏将任何整形数值缩小到有效的ASCII范围之内,它将变量和0x7f相与从而去掉第7位以上的所有数位16 #define tolower(c) (c-‘A’+’a’)功能:该宏将字符与常数0x20 逐位相或17 #define toupper(c) ((c)-‘a’+’A’)功能:该宏将字符与常数0xdf 逐位相与2数学函数 math.hextern int abs (int val);extern char cabs (char val);extern long labs (long val);extern float fabs (float val);功能:返回绝对值。

C语言常用头文件

C语言常用头文件

头文件 time.h
日期和时间函数: 本类别给出时间和日期处理函数
----------------------------------------
时间操作函数得到处理器时间 clock
得到时间差 difftime
设置时间 mktime
1 错误处理 errno.h
2 字符处理 ctype.h
3 地区化 local.h
4 数学函数 math.h
5 信号处理 signal.h
6 输入输出 stdio.h
7 实用工具程序 stdlib.h
8 字符串处理 string.h
C标准中的数据格式并不符合IEEE754标准,一些C语言编译器却遵循IEEE754(例如frinklin C51)
----------------------------------------
反余弦 acos
反正弦 asin
反正切 atan
错误处理函数
错误清除 clearerr
文件结尾判断 feof
文件错误检测 ferror
得到错误提示字符串 perror
头文件 stdlib.h
实用工具函数: 本分类给出了一些函数无法按以上分类,但又是编程所必须要的。
自然对数 log
以10为底的对数 log10
浮点数分解函数 modf
幂函数 pow
平方根函数 sqrt
求下限接近整数 ceil
绝对值 fabs
求上限接近整数 floor
求余数 fmod
头文件 setjmp.h io.h
本分类函数用于实现在不同底函数之间直接跳转代码。

单片机C语言头文件详解

单片机C语言头文件详解

单片机C语言头文件详解单片机中用c编程时头文件reg51.h及reg52.h解析我们在用c语言编程是往往第一行就是reg51.h或者其他的自定义头文件,我们怎么样来理解呢?1)“文件包含”处理。

程序的第一行是一个“文件包含”处理。

所谓“文件包含”是指一个文件将另外一个文件的内容全部包含进来。

程序中包含REG51.h文件的目的是为了要使用P1 (还有其他更多的符号)这个符号,即通知C 编译器,程序中所写的P1 是指80C51 单片机的P1 端口而不是其它变量。

这是如何做到的呢?打开reg51.h 可以看到这样的一些内容:(此文件一般在C:\KEIL\C51\INC下,INC文件夹根目录里有不少头文件,并且里面还有很多以公司分类的文件夹,里面也都是相关产品的头文件。

如果我们要使用自己写的头文件,使用的时候只需把对应头文件拷贝到INC文件夹里就可以了。

)/*---------------------------------------------------------REG51.HHeader file for generic 80C51 and 80C31 microcontroller.Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.All rights reserved.------------------------------------------------------------*/#ifndef __REG51_H__#define __REG51_H__/* BYTE Register */sfr P0 = 0x80;sfr P1 = 0x90;sfr P2 = 0xA0;sfr P3 = 0xB0;sfr PSW = 0xD0;sfr ACC = 0xE0;sfr B = 0xF0;sfr SP = 0x81;sfr DPL = 0x82;sfr DPH = 0x83;sfr PCON = 0x87;sfr TCON = 0x88;sfr TMOD = 0x89;sfr TL0 = 0x8A;sfr TL1 = 0x8B;sfr TH0 = 0x8C;sfr IE = 0xA8;sfr IP = 0xB8;sfr SCON = 0x98; sfr SBUF = 0x99; /* BIT Register */ /* PSW */sbit CY = 0xD7; sbit AC = 0xD6; sbit F0 = 0xD5; sbit RS1 = 0xD4; sbit RS0 = 0xD3; sbit OV = 0xD2; sbit P = 0xD0;/* TCON */sbit TF1 = 0x8F; sbit TR1 = 0x8E; sbit TF0 = 0x8D; sbit TR0 = 0x8C; sbit IE1 = 0x8B; sbit IT1 = 0x8A; sbit IE0 = 0x89; sbit IT0 = 0x88; /* IE */sbit EA = 0xAF; sbit ES = 0xAC; sbit ET1 = 0xAB; sbit EX1 = 0xAA; sbit ET0 = 0xA9; sbit EX0 = 0xA8; /* IP */sbit PS = 0xBC; sbit PT1 = 0xBB; sbit PX1 = 0xBA; sbit PT0 = 0xB9; sbit PX0 = 0xB8; /* P3 */sbit RD = 0xB7; sbit WR = 0xB6; sbit T1 = 0xB5; sbit T0 = 0xB4; sbit INT1 = 0xB3; sbit INT0 = 0xB2; sbit TXD = 0xB1;/* SCON */sbit SM0 = 0x9F;sbit SM1 = 0x9E;sbit SM2 = 0x9D;sbit REN = 0x9C;sbit TB8 = 0x9B;sbit RB8 = 0x9A;sbit TI = 0x99;sbit RI = 0x98;#endif熟悉80C51 内部结构的读者不难看出,这里都是一些符号的定义,即规定符号名与地址的对应关系。

C语言头文件大全

C语言头文件大全

标准C语言头文件ISO C标准定义的头文件(24项)〈assert.h〉验证程序断言<complex。

h> 支持复数算术运算<ctype.h〉字符类型<errno.h> 出错码<fenv。

h〉浮点环境〈float.h〉浮点常量<inttypes。

h> 整型格式转换〈iso646.h> 替代关系操作符宏〈limits.h> 实现常量〈locale.h〉局部类别<math.h〉数学常量<setjmp。

h〉非局部goto<signal。

h〉信号<stdarg。

h> 可变参数表〈stdbool。

h〉布尔类型和值<stddef.h> 标准定义<stdint。

h> 整型〈stdio.h> 标准I/O库<stdlib。

h〉实用程序库函数〈string。

h> 字符串操作<tgmath.h〉通用类型数学宏<time.h〉时间和日期〈wchar。

h> 宽字符支持<wctype。

h〉宽字符分类和映射支持POSIX标准定义的必须的头文件(26项)〈dirent.h> 目录项〈fcntl.h> 文件控制<fnmatch.h> 文件名匹配类型〈glob。

h> 路径名模式匹配类型<grp。

h> 组文件〈netdb。

h〉网络数据库操作<pwd。

h> 口令文件〈regex。

h> 正则表达式<tar。

h〉 tar归档值〈termios。

h> 终端I/O 〈unistd。

h〉符号常量〈utime。

h> 文件时间<wordexp。

h〉字扩展类型〈arpa/inet。

h〉 Internet定义<net/if.h> 套接字本地接口<netinet/in。

h〉 Internet地址族〈netinet/tcp。

C语言头文件大全

C语言头文件大全

标准C语言头文件ISO C标准定义的头文件(24项)<assert.h> 验证程序断言<complex.h> 支持复数算术运算<ctype.h> 字符类型<errno.h> 出错码<fenv.h> 浮点环境<float.h> 浮点常量<inttypes.h> 整型格式转换<iso646.h> 替代关系操作符宏<limits.h> 实现常量<locale.h> 局部类别<math.h> 数学常量<setjmp.h> 非局部goto<signal.h> 信号<stdarg.h> 可变参数表<stdbool.h> 布尔类型和值<stddef.h> 标准定义<stdint.h> 整型<stdio.h> 标准I/O库<stdlib.h> 实用程序库函数<string.h> 字符串操作<tgmath.h> 通用类型数学宏<time.h> 时间和日期<wchar.h> 宽字符支持<wctype.h> 宽字符分类和映射支持POSIX标准定义的必须的头文件(26项)<dirent.h> 目录项<fcntl.h> 文件控制<fnmatch.h> 文件名匹配类型<glob.h> 路径名模式匹配类型<grp.h> 组文件<netdb.h> 网络数据库操作<pwd.h> 口令文件<regex.h> 正则表达式<tar.h> tar归档值<termios.h> 终端I/O <unistd.h> 符号常量<utime.h> 文件时间<wordexp.h> 字扩展类型<arpa/inet.h> Internet定义<net/if.h> 套接字本地接口<netinet/in.h> Internet地址族 <netinet/tcp.h> 传输控制协议<sys/mman.h> 内存管理声明<sys/select.h> select函数<sys/socket.h> 套接字接口<sys/stat.h> 文件状态<sys/times.h> 进程时间<sys/types.h> 基本系统数据类型<sys/un.h> UNIX域套接字定义<sys/utsname.h>系统名<sys/wait.h> 进程控制POSIX标准定义的XSI扩展头文件(26项)<cpio.h> cpio归档值<dlfcn.h> 动态链接<fmtmsg.h> 消息显示结构<ftw.h> 文件树漫游<iconv.h> 代码集转换实用程序<langinfo.h> 语言信息常量<libgen.h> 模式匹配函数定义<monetary.h> 货币类型<ndbm.h> 数据库操作<nl_types.h> 消息类别<poll.h> 轮询函数<search.h> 搜索表<strings.h> 字符串操作<syslog.h> 系统出错日志记录<ucontext.h> 用户上下文<ulimit.h> 用户限制<utmpx.h> 用户帐户数据库<sys/ipc.h> IPC<sys/msg.h> 消息队列<sys/resource.h> 资源操作<sys/sem.h> 信号量<sys/shm.h> 共享存储<sys/statvfs.h> 文件系统信息<sys/time.h> 时间类型<sys/timeb.h> 附加的时间<sys/uio.h> 矢量I/O操作POSIX标准定义的可选头文件(8项)<aio.h> 异步I/O <mqueue.h> 消息队列<pthread.h> 线程<sched.h> 执行调度<semaphore.h> 信号量<spawn.h> 实时spawn接口<stropts.h> XSI STREAMS接口<trace.h> 时间跟踪标准 C++ 语言头文件(54个其中16个用于构建STL,3个为附加非必须)<algorithm>STL通用算法<bitset> STL位集容器<cassert> 用于在程序运行时执行断言<cctype> 字符处理<cerrno> 错误码<cfloat> 用于测试浮点类型属性<ciso646> ISO646变体字符集<climits> 测试整数类型属性<clocale> 本地化函数<cmath> 数学函数<complex>复数类<csetjmp> 执行非内部的goto语句<csignal> 信号<cstdarg> 访问参数数量变化的函数<cstddef> 用于定义实用的类型和宏<cstdio> 输入/输出<cstdlib> 杂项函数及内存分配<cstring> 字符串<ctime> 时间<cwchar> 宽字符处理及输入/输出<cwctype> 宽字符分类<deque> STL双端队列容器<exception> 异常处理类<fstream> 文件流<functional> STL函数对象<iomanip> 参数化输入/输出<ios>基本输入/输出支持<iosfwd> 输入/输出前置声明<iostream> 数据流输入/输出<istream> 基本输入流<iterator> 遍历序列的类<limits> 各种数据类型最值常量<list>STL线性列表容器<locale> 国际化支持<map> STL映射容器<memory> 专用内存分配器<new> 基本内存分配和释放<numeric> 通用的数字操作<ostream> 基本输出流<queue> STL 队列容器<set> STL 集合容器<sstream> 基于字符串的流<stack> STL 堆栈容器<stdexcept> 标准异常类<streambuf> iostream 的缓冲区类<string> 字符串类<strstream> 非内存字符序列的流类<typeinfo> 运行时类型标识<utility> STL 通用模板类<valarray> 支持值数组的类和模版类<vector> STL 动态数组容器标准C++附加的头文件(3个)非必须<hash_map> <hash_set> <slist>The Standard C++ library consists of 51 required headers.This implementation also includes three additional headers,<hash_map>,<hash_set>,and <slist>,not required by the C++ Standard,for a total of 54 headers.Of these 54 headers,16 constitute the Standard Template Library,or STL.These are indicated below with the notation<algorithm> -- (STL) for defining numerous templates that implement useful algorithms<bitset> -- for defining a template class that administers sets of bits<complex> -- for defining a template class that supports complex arithmetic<deque> -- (STL) for defining a template class that implements a deque container<exception> -- for defining several functions that control exception handling<fstream> -- for defining several iostreams template classes that manipulate exteral files<functional>-- (STL) for defining several templates that help construct predicates for the templates defined in <algorithm> and <numeric><hash_map> -- (STL) for defining template classes that implement hashed associative containersthat map keys to values<hash_set> -- (STL) for defining template classes that implement hashed associative containers<iomanip> -- for declaring several iostreams manipulators that take an argument<ios> -- for defining the template class that serves as the base for many iostreams classes<iosfwd> -- for declaring several iostreams template classes before they are necessarilydefined<iostream> -- for declaring the iostreams objects that manipulate the standard streams<istream> -- for defining the template class that performs extractions<iterator> -- (STL) for defining several templates that help define and manipulate iterators<limits> -- for testing numeric type properties<list>-- (STL) for defining a template class that implements a doubly linked list container<locale> -- for defining several classes and templates that controllocale-specific behavior, as in the iostreams classes<map>-- (STL) for defining template classes that implement associative containers thatmap keys to values<memory>-- (STL) for defining several templates that allocate and free storage for variouscontainer classes<new> -- for declaring several functions that allocate and free storage<numeric>-- (STL) for defining several templates that implement useful numeric functions<ostream> -- for defining the template class that performs insertions<queue> -- (STL) for defining a template class that implements a queue container<set>-- (STL) for defining template classes that implement associative containers<slist>-- (STL) for defining a template class that implements a singly linked list container<sstream> -- for defining several iostreams template classes that manipulate string containers<stack> -- (STL) for defining a template class that implements a stack container<stdexcept> -- for defining several classes useful for reporting exceptions<streambuf> -- for defining template classes that buffer iostreams operations<string> -- for defining a template class that implements a string container<strstream> -- for defining several iostreams classes that manipulate in-memory character sequences<typeinfo> -- for defining class type_info, the result of the typeid operator<utility>-- (STL) for defining several templates of general utility<valarray> -- for defining several classes and template classes that support value-oriented arrays<vector>-- (STL) for defining a template class that implements a vector container新的C标准库<cassert> -- for enforcing assertions when functions execute<cctype> -- for classifying characters<cerrno> -- for testing error codes reported by library functions<cfloat> -- for testing floating-point type properties<ciso646> -- for programming in ISO 646 variant character sets<climits> -- for testing integer type properties<clocale> -- for adapting to different cultural conventions<cmath> -- for computing common mathematical functions<csetjmp> -- for executing nonlocal goto statements<csignal> -- for controlling various exceptional conditions<cstdarg> -- for accessing a varying number of arguments<cstddef> -- for defining several useful types and macros<cstdio> -- for performing input and output<cstdlib> -- for performing a variety of operations<cstring> -- for manipulating several kinds of strings<ctime> -- for converting between various time and date formats<cwchar> -- for manipulating wide streams and several kinds of strings<cwctype> -- for classifying wide characters旧的C标准库<assert.h> -- for enforcing assertions when functions execute<ctype.h> -- for classifying characters<errno.h> -- for testing error codes reported by library functions<float.h> -- for testing floating-point type properties<iso646.h> -- for programming in ISO 646 variant character sets<limits.h> -- for testing integer type properties<locale.h> -- for adapting to different cultural conventions<math.h> -- for computing common mathematical functions<setjmp.h> -- for executing nonlocal goto statements<signal.h> -- for controlling various exceptional conditions<stdarg.h> -- for accessing a varying number of arguments<stddef.h> -- for defining several useful types and macros<stdio.h> -- for performing input and output<stdlib.h> -- for performing a variety of operations<string.h> -- for manipulating several kinds of strings<time.h> -- for converting between various time and date formats<wchar.h> -- for manipulating wide streams and several kinds of strings<wctype.h> -- for classifying wide charactersFinally, in this implementation, the Standard C++ library also includes several headers for compatibility with traditional C++ libraries:<fstream.h> -- for defining several iostreams template classes that manipulate exteral files <iomanip.h> -- for declaring several iostreams manipulators that take an argument<iostream.h> -- for declaring the iostreams objects that manipulate the standard streams <new.h> -- for declaring several functions that allocate and free storage<stl.h> -- for declaring several template classes that aid migration from older versions of the Standard Template Library。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

免费的函数原形的头文件读者可参考返回非整型值的函数函数原形的头文件读者可参考返回非整型值的函数assert.h - assert(), 声明宏ctype.h –字符类型函数float.h –浮点数原形limits.h –数据类型的大小和范围math.h –浮点运算函数stdarg.h –变量参数表.stddef.h –标准定义stdio.h –标准输入输出IO 函数stdlib.h –包含内存分配函数的标准库string.h –字符串处理函数3 字符类型库下列函数按照输入的ACS II 字符集字符分类使用这些函数之前应当用"#include <ctype.h>"包含int isalnum(int c)如果c 是数字或字母返回非零数值否则返回零int isalpha(int c)如果c 是字母返回非零数值否则返回零int iscntrl(int c)如果c 是控制字符如FF, BELL, LF ..等返回非零数值否则返回零int isdigit(int c)如果c 是数字返回非零数值否则返回零int isgraph(int c)如果c 是一个可打印字符而非空格返回非零数值否则返回零int islower(int c)如果c 是小写字母返回非零数值否则返回零int isprint(int c)如果c 是一个可打印字符返回非零数值否则返回零int ispunct(int c)如果c 是一个可打印字符而不是空格数字或字母返回非零数值否则返回零int isspace(int c)如果c 是一个空格字符返回非零数值包括空格CR, FF, HT, NL, 和VT 否则返回零int isupper(int c)如果c 是大写字母返回非零数值否则返回零int isxdigit(int c)如果c 是十六进制数字返回非零数值否则返回零int tolower(int c)如果c 是大写字母则返回c 对应的小写字母其它类型仍然返回cint toupper(int c)如果c 是小写字母则返回c 对应的大写字母其它类型仍然返回c4 浮点运算库下列函数支持浮点数运算使用这些函数之前必须用#include <math.h> 包含float asin(float x)以弧度形式返回x 的反正弦值float acos(float x)以弧度形式返回x 的反余弦值float atan(float x)以弧度形式返回x 的反正切值float atan2(float x, float y)返回y/x 的反正切其范围在- ~+ 之间float ceil(float x)返回对应x 的一个整型数小数部分四舍五入float cos(float x)返回以弧度形式表示的x 的余弦值float cosh(float x)返回x 的双曲余弦函数值float exp(float x)返回以e 为底的x 的幂即exfloat exp10(float x)返回以10 为底的幂即10xfloat fabs(float x)返回x 的绝对值float floor(float x)返回不大于x 的最大整数float fmod(float x, float y)返回x/y 的余数float frexp(float x, int *pexp)把浮点数x 分解成数字部分y 尾数和以2 为底的指数n 两个部分即x=y 2 n y 的范围为0.5 y 1 y 值被函数返回而n 值存放到pexp 指向的变量中float fround(float x)返回最接近x 的整型数float ldexp(float x, int exp)返回x 2 e x pfloat log(float x)返回x 的自然对数float log10(float x)返回以10 为底的x 的对数float modf(float x, float *pint)把浮点数分解成整数部分和小数部分整数部分存放到pint 指向的变量小数部分应当大于或等于0 而小于1 并且作为函数返回值返回float pow(float x, float y)返回x y 值float sqrt(float x)返回x 的平方根float sin(float x)返回以弧度形式表示的x 的正弦值float sinh(float x)返回x 的双曲正弦函数值float tan(float x)返回以弧度形式表示的x 的正切值float tanh(float x)返回x 的双曲正切函数值5 标准输入输出库标准的文件输入输出是不能真正植入微控制器MCU 的标准stdio.h 的许多内容不可以使用不过有一些IO 函数是被支持的同样使用之前应用"#include <stdio.h>"预处理并且需要初始化输出端口最低层的IO 程序是单字符的输入(getchar)和输出(putchar)程序如果你针对不同的装置使用高层的IO 函数例如用printf 输出LCD 你需要全部重新定义最底层的函数为在ATMEL 的AVR Studio 模拟器终端IO 窗口使用标准IO 函数应当在编译选项中选中相应的单选钮注意作为缺省单字符输出函数putchar 是输出到UART 装置没有修改无论如何为使输出能如期望的那样出现在程序终端窗口中'\n' 字符必须被映射为成对的回车和换行CR/LFint getchar()使用查寻方式从UART 返回一个字符int printf(char *fmt, ..)按照格式说明符输出格式化文本frm 字符串格式说明符是标准格式的一个子集%d--输出有符号十进制整数%o --输出无符号八进制整数%x - 输出无符号十六进制整数%X –除了大写字母使用'A'-'F'外同%x%u - 输出无符号十进制整数%s –输出一个以C 中空字符NULL 结束的字符串%c –以ASCII 字符形式输出只输出一个字符%f –以小数形式输出浮点数%S –输出在FLASH 存贮器中的字符串常量printf 支持三个版本取决于你的特别需要和代码的大小越高的要求代码越大基本形: 只有%c, %d, %x, %u, 和%s 格式说明符是承认的长整形: 针对长整形数的修改%ld, %lu, %lx 被支持, 以适用于精度要求较高的领域浮点形: 全部格式包括%f 被支持你使用编译选项对话框来选择版本代码大小的增加是值得关注的int putchar(int c)输出单个字符这个库程序使用了UART 以查寻方式输出单个字符注意输出’\n’字符至程序终端窗口int puts(char *s)输出以NL 结尾的字符串int sprintf(char *buf, char *fmt)按照格式说明符输出格式化文本frm 字符串到一个缓冲区格式说明符同printf( )"const char *" 支持功能cprintf 和csprintf 是将FLASH 中的格式字符串分别以prinf 和sprinf 形式输出6 标准库和内存分配函数标准库头文件<stdlib.h>定义了宏NULL 和RAND_MAX 和新定义的类型size_t 并且描述了下列函数注意在你调用任意内存分配程序比如.. calloc malloc 和realloc)之前必须调用_NewHeap来初始化堆heapint abs(int i)返回i 的绝对值int atoi(char *s)转换字符串s 为整型数并返回它字符串s 起始必须是整型数形式字符否则返回0double atof(const char *s)转换转换字符串s 为双精度浮点数并返回它字符串s 起始必须是浮点数形式字符串long atol(char *s)转换字符串s 为长整型数并返回它字符串s 起始必须是长整型数形式字符否则返回0void *calloc(size_t nelem, size_t size)分配"nelem"个数据项的内存连续空间每个数据项的大小为size 字节并且初始化为0 如果分配成功返回分配内存单元的首地址否则返回0void exit(status)终止程序运行典型的是无限循环它是担任用户main 函数的返回点void free(void *ptr)释放ptr 所指向的内存区void *malloc(size_t size)分配size 字节的存贮区如果分配成功则返回内存区地址如内存不够分配则返回0void _NewHeap(void *start, void *end)初始化内存分配程序的堆一个典型的调用是将符号_bss_end+1 的地址用作"start"值符号_bss_end 定义为编译器用来存放全局变量和字符串的数据内存的结束加1 的目的是堆栈检查函数使用_bss_end 字节存贮为标志字节这个结束值不能被放入堆栈中extern char _bss_end;_NewHeap(&_bss_end+1, &_bss_end + 201); // 初始化200 字节大小的堆int rand(void)返回一个在0 和RAND_MAX 之间的随机数void *realloc(void *ptr, size_t size)重新分配ptr 所指向内存区的大小为size 字节size 可比原来大或小返回指向该内存区的地址指针void srand(unsigned seed)初始化随后调用的随机数发生器的种子数long strtol(char *s, char **endptr, int base)按照"base."的格式转换"s"中起始字符为长整型数如果"endptr"不为空* endptr 将设定"s"中转换结束的位置unsigned long strtoul(char *s, char **endptr, int base)除了返回类型为无符号长整型数外其余同"strtol"7 字符串函数用"#include <string.h>"预处理后编译器支持下列函数<string.h>定义了NULL 类型size_t和下列字符串及字符阵列函数void *memchr(void *s, int c, size_t n)在字符串s 中搜索n 个字节长度寻找与c 相同的字符如果成功返回匹配字符的地址指针否则返回NULLint memcmp(void *s1, void *s2, size_t n)对字符串s1 和s2 的前n 个字符进行比较如果相同则返回0 如果s1 中字符大于s2 中字符则返回1 如果s1 中字符小于s2 中字符则返回-1 void *memcpy(void *s1, void *s2, size_t n)拷贝s2 中n 个字符至s1 但拷贝区不可以重迭void *memmove(void *s1, void *s2, size_t n)拷贝s2 中n 个字符至s1 返回s1 其与memcpy 基本相同但拷贝区可以重迭void *memset(void *s, int c, size_t n)在s 中填充n 个字节的c 它返回schar *strcat(char *s1, char *s2)拷贝s2 到s1 的结尾返回s1char *strchr(char *s, int c)在s1 中搜索第一个出现的c 包括结束NULL 字符如果成功返回指向匹配字符的指针如果没有匹配字符找到返回空指针int strcmp(char *s1, char *s2)比较两个字符串如果相同返回0 如果s1>s2 则返回1 如果s1<s2 则返回-1char *strcpy(char *s1, char *s2)拷贝字符串s2 至字符串s1 返回s1size_t strcspn(char *s1, char *s2)在字符串s1 搜索与字符串s2 匹配的第一个字符包括结束NULL 字符其返回s1 中找到的匹配字符的索引size_t strlen(char *s)返回字符串s 的长度不包括结束NULL 字符char *strncat(char *s1, char *s2, size_t n)拷贝字符串s2 不含结束NULL 字符中n 个字符到s1 如果s2 长度比n 小则只拷贝s2返回s1int strncmp(char *s1, char *s2, size_t n)基本和strcmp 函数相同但其只比较前n 个字符char *strncpy(char *s1, char *s2, size_t n)基本和strcpy 函数相同但其只拷贝前n 个字符char *strpbrk(char *s1, char *s2)基本和strcspn 函数相同但它返回的是在s1 匹配字符的地址指针否则返回NULL 指针char *strrchr(char *s, int c)在字符串s 中搜索最后出现的c 并返回它的指针否则返回NULL .size_t strspn(char *s1, char *s2)在字符串s1 搜索与字符串s2 不匹配的第一个字符包括结束NULL 字符其返回s1 中找到的第一个不匹配字符的索引char *strstr(char *s1, char *s2)在字符串s1 中找到与s2 匹配的子字符串如果成功它返回s1 中匹配子字符串的地址指针否则返回NULL"const char *" 支持函数这些函数除了它的操作对象是在FLASH 中常数字符串外其余同c 中的函数size_t cstrlen(const char *s)char *cstrcpy(char *dst, const char *src);int cstrcmp(const char *s1, char *s2);8 变量参数函数<stdarg.h>提供再入式函数的变量参数处理它定义了不确定的类型va_list 和三个宏va_start(va_list foo, <last-arg>)初始化变量foova_arg(va_list foo, <promoted type>)访问下一个参数分派指定的类型注意那个类型必须是高级类型如int long 或double小的整型类型如"char"不能被支持va_end(va_list foo)结束变量参数处理例如printf()可以使用vfprintf()来实现#include <stdarg.h>int printf(char *fmt, ...){va_list ap;va_start(ap, fmt);vfprintf(fmt, ap);va_end(ap);}9 堆栈检查函数有几个库函数是用于检查堆栈是否溢出内存图如下如果硬件堆栈增长到软件堆栈中那么软件堆栈的内容将会被改变也就是说局部变量和别的堆栈项目被改变硬件堆栈是用作函数的返回地址如果你的函数调用层次太深偶然会发生这种情况同样地软件堆栈溢出进数据区域将会改变全局变量或其它静态分配的项目如果你使用动态分配内存还会改变堆项目这种情况在你定义了太多的局部变量或一个局部集合变量太大也会偶然发生高端地址硬件堆栈区警戒线软件堆栈区警戒线数据区低端地址警戒线启动代码写了一个正确的关于数据区的地址字节和一个类似的正确的关于软件堆栈的地址字节作为警戒线[注意如果你使用了你自己的启动文件而其又是以6.20 版本之前的启动文件为基础的你将需要额外改造为新的启动文件]注意如果你使用动态分配内存你必须跳过警戒线字节_bss_end 来分配你的堆参考内存分配函数堆栈检查你调用_StackCheck(void)函数来检查堆栈溢出如果警戒线字节仍然保持正确的值那么函数检查通过如果堆栈溢出那么警戒线字节将可能被破坏注意当你的程序堆栈溢出的时候你的程序将可能运行不正常或偶然崩溃当_StackCheck 检查错误条件时它调用了带一个参数的函数_StackOverflowed(char c) 如果参数是1 那么硬件堆栈有过溢出如果参数是0 那么软件堆栈曾经溢出在那个例子中制造了两个功能调用它是两个堆栈都可能溢出的无论如何在_StackOverflowed 执行起作用时第二个调用不可以出现作为例子如果函数复位了CPU 那么将不能返回_StackCheck 函数缺省的_StackOverflowed 函数当它被调用时库会用一个缺省的_StackOverflowed 函数来跳转到0 的位置因此复位CPU 和程序你可能希望用一个函数来代替它以指示更多的错__。

相关文档
最新文档