C51库函数

  • 格式:doc
  • 大小:40.50 KB
  • 文档页数:11

C51库函数积累:(1)_chkfloat_:函数定义:unsigned char _chkfloat_ ( float val); /* number to check */函数功能:_chkfloat_函数检查浮点数val 的类型。

返回值:_chkfloat_函数返回浮点数val 的类型。

P2=~_chkfloat_; delay(50000);P2=~_chkfloat_; delay(50000);P2=~_chkfloat_; delay(50000);P2=~_chkfloat_(*((float *)f)); while(1);}(2)_crol_:函数定义:unsigned char _crol_ ( unsigned char c, unsigned char b);/* character to rotate left *//* bit positions to rotate */函数功能:_crol_函数将一个字节c循环左移b位。

返回值:_crol函数返回将c循环左移b位后的值。

/*本实验测试本征库中的_crol_函数函数定义:unsigned char _crol_(unsigned char c,unsigned char b);返回值:_crol_函数返回将c循环左移b位后的值。

用P1指示返回值*/y=cos(x);y=cosh(x); //y=while(1);}(28)exp:函数定义:float exp ( float x); /* power to use for ex function */函数功能:取x的自然指数值。

返回值:x的自然指数值。

/*本实验测试标准库中的exp函数函数定义:float exp(float x);返回值:x的自然指数值。

*/函数测试:#include <>#include <>void main(){float x,y;x=;y=exp(x); //y=while(1);}(29)fabs:函数定义:float fabs ( float val); /* number to take absolute value of */函数功能:取浮点val的绝对值。

返回值:浮点val的绝对值。

/*本实验测试标准库中的fabs函数函数定义:float fabs(float val);返回值:浮点val的绝对值。

*/函数测试:#include <>void main(){float x,y;x=;y=fabs(x); //y=while(1);}(30)floor:函数定义:float floor ( float val); /* number to calculate floor for */函数功能:取比val小的最大的整数。

返回值:比val小的最大的整数。

/*本实验测试标准库中的floor函数函数定义:float floor(float val);返回值:比val小的最大的整数。

*/函数测试:#include <>#include <>void main(){float x,y;x=;y=floor(x); //y=}(31)fmod:函数定义:float fmod ( float x, /* value to calculate modulo for */ float y); /* integer portion of modulo */函数功能:对x取y的模。

返回值:x取y的模。

/*本实验测试标准库中的fmod函数函数定义:float fmod(float x,float y);返回值:x取y的模。

*/函数测试:#include <>#include <>void main(){float x,y;x=;y=fmod(x,; //y=while(1);}(32)free:函数定义:void free ( void xdata *p); /* block to free */函数功能:用来释放先前由calloc、malloc或realloc开辟的内存空间。

返回值:无。

/*本实验测试标准库中的free函数函数定义:void free(void xdata *p);返回值:无*/函数测试:#include <>#include <>void main(){void xdata *buf;buf=malloc(1000);//在片外ram中开辟一块有1000个字节的空间。

if(buf!=NULL){free(buf);//把由malloc开屏的空间释放掉。

}while(1);}(33)getchar:函数定义:char getchar (void);函数功能:从串口读取一个字符。

返回值:从串口读到字符。

/*本实验测试标准库中的getchar函数函数定义:char getchar(void);返回值:从串口读到字符。

*/函数测试:#include <>#include <>void main(){char c;while((c=getchar())!=0x0a){P1=c; //如果收到的字符不是回车,则将收到字符输出到P1口}//注:在程序开始要去串口进行初始,确定波特率。

while(1);}(34)gets:函数定义:char *gets ( char *string, /* string to read */ int len); /* max characters to read */函数功能:从串口读取一行字符串,len为能够读取的最大字节数。

返回值:从串口读到的字符串的指针。

/*本实验测试标准输入输出库中的gets函数函数定义:char *gets(char *string,int len);返回值:从串口读到的字符串的指针。

*///函数测试:#include <>#include <>void main(){char buf[21];do{gets(buf,sizeof(buf)-1);printf("Input string \"%s\"",buf);}while(buf[0]!='\0');//注:在程序开始要去串口进行初始,确定波特率。

while(1);}(35)init_mempool:函数定义:void init_mempool ( void xdata *p, /* start of memory pool */ unsigned int size); /* length of memory pool */函数功能:用来初始化一个内容池,用calloc、free、malloc与realloc来进行管理。

返回值:无。

/*本实验测试标准库中的init_mempool函数函数定义:void init_mempool(void xdata *p,unsigned int size);返回值:无。

*///函数测试:#include <>#include <>unsigned char xdata malloc_mempool[0x1000];void main(){int i;void xdata *p;init_mempool(&malloc_mempool,sizeof(malloc_mempool));p=malloc(100);for(i=0;i<100;i++){((char *)p)[i]=i;}free(p);while(1);}(36)isalnum:函数定义:bit isalnum ( char c); /* character to test */函数功能:用来测试c是否是一个英文或数码字符('A'-'Z', 'a'-'z', or '0'-'9')。

返回值:如果c是一个英文或数码字符则返回1,否则为0。

/*本实验测试ctype库中的isalnum函数函数定义:bit isalnum(char c);返回值:如果c是一个英文或数码字符则返回1,否则为0。

*///函数测试:#include <>#include <>void main(){unsigned char c=';';unsigned char d='a';unsigned char e='A';unsigned char f='1';unsigned char result1,result2,result3,result4;result1=isalnum(c); //result1=0result2=isalnum(d); //result2=1result3=isalnum(e); //result3=1result4=isalnum(f); //result4=1while(1);}(37)isalpha:函数定义:bit isalpha ( char c); /* character to test */函数功能:用来测试c是否是一个英文字符('A'-'Z', 'a'-'z')。

返回值:如果c是一个英文字符则返回1,否则为0。

/*本实验测试ctype库中的isalpha函数函数定义:bit isalpha(char c);返回值:如果c是一个英文字符则返回1,否则为0。

*///函数测试:#include <>#include <>void main(){unsigned char c=';';unsigned char d='a';unsigned char e='A';unsigned char f='1';unsigned char result1,result2,result3,result4;result1=isalpha(c); //result1=0result2=isalpha(d); //result2=1result3=isalpha(e); //result3=1result4=isalpha(f); //result4=0while(1);}。