相關(guān)-單片機(jī)學(xué)習(xí)picc庫函數(shù)詳解_第1頁
相關(guān)-單片機(jī)學(xué)習(xí)picc庫函數(shù)詳解_第2頁
相關(guān)-單片機(jī)學(xué)習(xí)picc庫函數(shù)詳解_第3頁
相關(guān)-單片機(jī)學(xué)習(xí)picc庫函數(shù)詳解_第4頁
相關(guān)-單片機(jī)學(xué)習(xí)picc庫函數(shù)詳解_第5頁
已閱讀5頁,還剩37頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

PICCPICC提要:C語言定義以及定義函數(shù)的頭文件。ABS函提#include<stdlib.h>intabs(intj)描abs(j例#include<stdio.h>#include<stdlib.h>main{inta=-printf("Theabsolutevalueof%dis}jACOS函提#include<math.h>doubleacos(doublef)描例#include<math.h>#includemain{floatfor(i=-1.0,i<1.0;i+=0.1){a=acos(i)*180.0/3.141592;printf("acos(%f)=%f}}參sin(),cos(),tan(),asin(),atan(),atan2(0。ASCTIME函提#includechar*asctime(structtm*描asctime()t從上structtm結(jié)構(gòu)體中獲得時(shí)間,返回描述當(dāng)前日期和時(shí)SunSep1601:03:52當(dāng)前時(shí)間,通過localtime()函數(shù)將其轉(zhuǎn)換成一個(gè)structtm指針,最后轉(zhuǎn)換成ASCII碼并打印出來。其中,time()函數(shù)需要用戶提供(參閱time()函數(shù)。例#include<stdio.h>#include<time.h>main{time_tclock;structtm*tp;

tp=}參ctime(),gmtime(),localtime(),time(注意:由于編譯器不提供time()例行程序,故在本例程中它需要由用戶提供。參照time()函structtminttm_sec;inttm_min;inttm_hour;inttm_mday;inttm_mon;inttm_year;inttm_wday;inttm_yday;inttm_isdst;ASIN函提#include<math.h>doubleasin(doublef)描asin()函數(shù)是sin()的反函數(shù)。它的函數(shù)參數(shù)在[-1,1]區(qū)間內(nèi),返回一個(gè)用弧度表示例#include<math.h>#include<stdio.h>main{floatfor(i=-1.0;i<1.0;i+=0.1){a=asin(i)*180.0/3.141592;printf("asin(%f)=%f}}參sin(),cos(),tan(),acos(),atan(),atan2(ATAN函提#include<math.h>doubleatan(doublex)描例#include<stdio.h>#include<math.h>main{}參sin(),cos(),tan(),asin(),acos(),atan2(ATAN2函提#includedoubleatan2(doubley,double描例#include<stdio.h>#include<math.h>main{}參sin(),cos(),tan(),asin(),acos(),atan(提#includedoubleatof(constchar*描例#include<stdlib.h>#include<stdio.h>main{charbuf[80];doublei;i=printf("Read%s:convertedto}參atoi(),atol(ATOI函提#includeintatoi(constchar*描atoi()函數(shù)掃描傳遞過來的字符串,跳過開頭的空格并其符號;然后將一個(gè)十例#include<stdlib.h>#include<stdio.h>main{charbuf[80];inti;i=printf("Read%s:convertedto}參xtoi(),atof(),atol(ATOL函提#includelongatol(constchar*描atol()函數(shù)掃描傳遞過來的字符串,并跳過字符串開頭的空格;然后將十進(jìn)制數(shù)的例#include<stdlib.h>#include<stdio.h>main{charbuf[80];longi;i=printf("Read%s:convertedto}參atoi(),atof(CEIL函提#include<math.h>doubleceil(doublef)描ff例#include<stdio.h>#include<math.h>main{doublej;printf("Theceilingof%lfis}COS函提#include<math.h>doublecos(doublef)描例#include<math.h>#include<stdio.h>#defineC3.141592/180.0main{doublefor(i=0;i<=180.0;i+=printf("sin(%3.0f)=%f,cos=}參sin(),tan(),asin(),acos(),atan(),atan2(COSH、SINH、TANH函提#includedoublecosh(doublef)doublesinh(doublef)doubletanh(double描這些函數(shù)都是cos,sin和tan例#include<stdio.h>#include<math.h>main{}cosh(函數(shù)返回雙曲余弦值,sinh函數(shù)返回雙曲正弦值,tanhCTIME函提#includechar*ctime(time_t*描ctime函數(shù)將函數(shù)參數(shù)所指的時(shí)間轉(zhuǎn)換成字符串,其結(jié)構(gòu)與asctime函數(shù)所描述的例#include<stdio.h>#include<time.h>main{time_tclock;}參gmtime(),localtime(),asctime(),time(注意:由于編譯器不會提供time()程序,故它需要由用戶給定。參閱time()函數(shù)typedeflong提#include<pic.h>voidei(void)voiddi(void)描以下例程將說明ei()函數(shù)和di()函數(shù)在一個(gè)長整型變量時(shí)的應(yīng)用由于中斷服務(wù)程序?qū)⑿薷脑撟兞浚匀绻撟兞坎话凑毡纠痰慕Y(jié)構(gòu)編程,一旦在變量值的連續(xù)字期間出現(xiàn)中斷,則函數(shù)getticks()將返回錯(cuò)誤的值。例#include<pic.h>longcount;voidinterrupt{}long{longval;/*在count變量前中斷,保證的連續(xù)性*/di();val=count;ei();returnval;}DIV函提#includediv_tdiv(intnumer,int描)例#include<stdlib.h>#include<stdio.h>main{div_tx=printf("quotient=%d,remainder=}typedef{intquot;int}提

EEPROM_READ、EEPROM_WRITE函#includeunsignedchareeprom_read(unsignedcharvoideeprom_write(unsignedcharaddr,unsignedchar描這些函數(shù)允許片內(nèi)EEPROM(如果片內(nèi)有EEPROM。EEPROM不是可直接尋址的寄存器空間,當(dāng)需要EEPROM時(shí),就需要將一些特定的字節(jié)序列加載到EEPROM控制寄存器中。寫EEPROM是一個(gè)緩慢的過程。故eeprom_write()函數(shù)在寫入例#include<pic.h>main{unsignedchardata;unsignedcharaddress;address=data=}以確保寫入完畢。全局中斷使能位(GIE)在eeprom_write()程序中重新恢復(fù)(寫EEPROM時(shí)需要關(guān)閉EVAL_POLY函提#includedoubleeval_poly(doublex,constdouble*d,int描eval_poly(x和數(shù)組d中,y=x*x*d2+x*d1+例#include<stdio.h>#include<math.h>main{doubledoubled[3]={1.1,3.5,2.7};x=2.2;y=printf("Thepolynomialevaluatedat%fis}EXP函提#include<math.h>doubleexp(doublef)描)例#include#include<stdio.h>main{doublefor(f=0.0;f<=5;f+=printf("eto%1.0f=}參log(),log10(),pow(FABS函提#include<math.h>doublefabs(doublef)描例#include<stdio.h>#include<math.h>main{}參abs(FLOOR函提#include<math.h>doublefloor(doublef)描例#include<stdio.h>#include<math.h>main{printf("%f\n",floor(1.5));}FREXP函提#includedoublefrexp(doublef,int*描frexp(函數(shù)將一個(gè)浮點(diǎn)數(shù)分解成規(guī)格化小數(shù)和2pint單元中。本函數(shù)的返回值x或在區(qū)間(0.5,1.0)0;而且有例#include<math.h>#include<stdio.h>main{doublef;inti;f=frexp(23456.34,&i);printf("23456.34=%f*2^%d\n",f,i);}參ldexp(GET_CAL_DATA函提#includedoubleget_cal_data(constunsignedchar*描本函數(shù)從PIC14000標(biāo)定空間返回一個(gè)32例#include<pic.h>main{doubleunsignedcharxget_cal_data(KREF);/*獲得參考斜率(slopereferenceratio)*/y=TWDT;/*獲得WDT溢出時(shí)間*/}注意:本函數(shù)僅用于PICGMTIME函提#includestructtm*gmtime(time_t*描t所指的時(shí)間分解,并且存于結(jié)構(gòu)體中,精確度為秒。其中,t所指的時(shí)間必須自0時(shí)0分0秒起。本函數(shù)所用的結(jié)構(gòu)體被定義在time.h文件中,可例#include<stdio.h>#include<time.h>main{time_tclock;structtm*tp;tp=printf("It’s%dinLondon\n",tp- }參ctime(),asctime(),time(),localtime(注意:由于編譯器不會提供time()程序,故它需要由用戶給定。參閱time()函數(shù)typedeflongtime_t;structtm{inttm_sec;inttm_min;inttm_hour;intinttm_mon;inttm_year;inttm_wday;inttm_yday;inttm_isdst;ISALNUM,ISALPHA,ISDIGIT,ISLOWER等函提#include<ctype.h>intisalnum(charc)intisalpha(charc)intisascii(charc) trl(charc)intisdigit(charc)intislower(charc)intisprint(charc)intisgraph(charc)intispunct(charc)intisspace(charc)intisupper(charc)intisxdigit(charc)描isalnum(c) isalpha(c) isascii(c) trl(c) isdigit islower isprint isgraph ispunct(c) isspace(c) isupper(c) isxdigit 例#include<ctype.h>#includemain{charbuf[80];inti;i=0;buf[i]=printf("’%s’isthe}參toupper(),tolower(),toascii(提#include<conio.h>bitkbhit(void)描如果鍵盤上的字符被按下,函數(shù)返回1;否則返回0。通常,該字符可通過getch(函數(shù)。例#include<conio.h>main{inti;while(!kbhit()){cputs("I’mfor(i=0;i!=1000;i++)}}參getch(),getche( LDEXP函提#includedoubleldexp(doublef,int描ldexp()函數(shù)是frexp()fi的求和運(yùn)例#include<math.h>#include<stdio.h>main{doublef=printf("1.0*2^10=}參frexp(fiLDIV函提#includeldiv_tldiv(longnumber,long描Ldiv(函數(shù)與div(結(jié)構(gòu)體ldiv_t)例#include<stdlib.h>#include<stdio.h>main{ldiv_tlt=printf("Quotient=%ld,remainder=}參閱div()5.返回6.?dāng)?shù)據(jù)結(jié)typedefstruct{longquot/*商*/longrem/*余數(shù)}LOCALTIME函提#includestructtm*localtime(time_t*描間必須自0時(shí)0分0秒起,所用的結(jié)構(gòu)體被定義在time.h文件中。localtime()函數(shù)需要考慮全局整型變量time_zone中的內(nèi)容,因?yàn)樗斜镜貢r(shí)區(qū)位于以localtime()函數(shù)的返回值將與gmtime()的相同。例#include<stdio.h>#include<time.h>char*wday[]={main{time_tclock;structtm*tp;tp=}參ctime(),asctime(),time(注意:由于編譯器不會提供time()程序,故它需要由用戶給定。參閱time()函數(shù)typedeflongtime_t;structtm{inttm_sec;inttm_min;inttm_hour;inttm_mday;inttm_mon;inttm_year;inttm_wday;inttm_yday;inttm_isdst;LOG、LOG10函提#include<math.h>doublelog(doublef)doublelog10(doublef)描))例#include<math.h>#include<stdio.h>main{doublefor(f=1.0;f<=10.0;f+=1.0)printf("log(%1.0f)=%f\n",f,log(f));}參exp(),pow(提

MEMCHR函#include/*constvoid*memchr(constvoid*block,intval,size_t/*高級系列單片機(jī)void*memchr(constvoid*block,intval,size_t描例#include<string.h>#include<stdio.h>unsignedintary[]=main{char*cp=memchr(ary,0x89,sizeofary);printf("notfound\n");printf("Foundatoffset%u\n",cp-(char}參strchr(MEMCMP函提#includeintmemcmp(constvoid*s1,constvoid*s2,size_t描memcmp()函數(shù)的功能是比較兩塊長度為n的內(nèi)存中變量的大小,類似strncmp()函例3.3.#include<string.h>#include<stdio.h>#include<stdio.h>#include<string.h>main{intbuf[10],cow[10],i;buf[0]=1;buf[2]=cow[0]=cow[2]=buf[1]=cow[1]=i=memcmp(buf,cow,3*sizeof(int));if(i<0)printf("lessthan\n");elseif(i>0)printf("Greaterthan\n");}參strncpy(),strncmp(),strchr(),memset(),s1s2變量時(shí),函數(shù)返回值分別為-1,01。MEMCPY函提#include/*void*memcpy(void*d,constvoid*s,size_t/*farvoid*memcpy(farvoid*d,constvoid*s,size_t描memcpy()函數(shù)的功能是,將指針s指向的、內(nèi)存開始的n個(gè)字節(jié)到指針d指向制的是一定數(shù)量的字節(jié),而不是所有結(jié)束符前的數(shù)據(jù)。main{charmemset(buf,0,sizeofbuf);memcpy(buf,"apartialstring",10);printf("buf=’%s’\n",buf);}參strncpy(),strncmp(),strchr(),MEMMOVE函提#include/*void*memmove(void*s1,constvoid*s2,size_t/*farvoid*memmove(farvoid*s1,constvoid*s2,size_t描memmove()函數(shù)與memcpy()函數(shù)相似,但memmove()函數(shù)能對區(qū)進(jìn)行準(zhǔn)確的復(fù)參strncpy(),strncmp(),strchr(),MEMSET函提#include/**/void*memsetvoid*sintcsize_t/*farvoid*memset(farvoid*s,intc,size_t描main{charstrcpy(abuf,"Thisisastring");memset(abuf,’x’,5);printf("buf=’%s’\n",}4.strncpy(),strncmp(),strchr(),memcpy(),MODF函提#includedoublemodf(doublevalue,double*描0.17例#include<math.h>#include<stdio.h>main{doublei_val,f_val=modf(-3.17,}提

PERSIST_CHECK,PERSIST_VALIDATE函#includeintpersist_check(intflag)voidpersist_validate(void)描個(gè)。如果擬數(shù)據(jù)和都正確則回值為真非零。果都不確則返回零。在這種情況下,函數(shù)返回零并且重新檢測NVAM區(qū)域(通過調(diào)用per_ada()函數(shù)。函數(shù)被執(zhí)行的條件是標(biāo)志變量變量不為0。per_vaae函數(shù)應(yīng)在每次換為變量之調(diào)用。將重新立擬數(shù)據(jù)和算。例#include<sys.h>#include<stdio.h>persistentlongreset_count;main{printf("Resetcountinvalid-zeroed\n");printf("Resetnumber%ld\n",reset_count);reset_count++;/*updatecount*/persist_validate();/*andchecksum*/continue;/*sleepuntilnextreset},,(非零POW函提#includedoublepow(doublef,double描例#include<math.h>#include<stdio.h>main{doublefor(f=1.0;f<=10.0;f+=printf("pow(2,%1.0f)=%f\n",f,pow(2,}參log(),log10(),f的pPRINTF函 #includeunsignedcharprintf(constchar*fmt,描(staoutoxXud 例printf("Total4d23)輸出為’Total=23%’printf("Sizeis%lx",size)printf("Name=%.8s",’Nameprintf("xx%*d",3,’xx/*vprintf*/#includestdio.h>error(char*s,{va_listap;va_start(ap,s);printf("Error:");vprintf(s,ap);}main{inti;i=error("testing12%d",}有關(guān)PICCL的描述以及有關(guān)HPDPIC長整型格式在printf的菜單選項(xiàng)。RAND函提#include<stdlib.h>intrand(void)描每次被調(diào)用后,以隨機(jī)數(shù)據(jù)形式出現(xiàn)。這一運(yùn)算規(guī)則將產(chǎn)生一個(gè)從同一起點(diǎn)開始的確定例#include#include<stdio.h>#include<time.h>main{time_ttoc;inti;for(i=0;i!=10;i++)printf("%d\t",rand());}注意:例程中需要用戶自己提供m函數(shù),因?yàn)樗荒苡蓞R編器產(chǎn)生。更詳細(xì)的情況參見m()SIN函提#include<math.h>doublesin(doublef)描例程#include<math.h>#include<stdio.h>#defineC3.141592/180.0main{doublefor(i=0;i<=180.0;i+=printf("sin(%3.0f)=%f,cos=%f\n",i,sin(i*C),}參cos(),tan(),asin(),acos(),atan(),提

SPRINTF函#include/*unsignedcharsprintf(char*buf,constchar*fmt,/*unsignedcharsprintf(farchar*buf,constchar*fmt,描sprintf()printf()函數(shù)操作基本相同;只是輸出在不同的輸出終端,所有的字符buf緩沖器。字符串帶有空格結(jié)束符,buf緩沖器中的數(shù)據(jù)被返回。SQRT函提#include<math.h>doublesqrt(doublef)描例#include<math.h>#include<stdio.h>main{doublefor(i=0;i<=20.0;i+=printf("squarerootof%.1f=%f\n",i,}參見exp()SRAND函提#includevoidsrand(unsignedint描srand()rand()rand()函數(shù)例#include<stdlib.h>#include<stdio.h>#include<time.h>main{time_ttoc;inti;for(i=0;i!=10;i++)printf("%d\t",rand());}STRCAT函提#include/*char*strcat(char*s1,constchar*/*farchar*strcat(farchar*s1,constchar*描s2s1的后面。新的字符串以空格作為結(jié)束符。指s1指向的字符數(shù)組必須保證大于結(jié)果字符串。例#include<string.h>#include<stdio.h>main{charbuffer[256];char*s1,*s2;strcpy(buffer,"Startofline");s1=buffer;s2="...endofline";strcat(s1,s2);printf("Length=%d\n",strlen(buffer));printf("string=\"%s\"\n",buffer);}參strcpy(),strcmp(),strncat(),STRCHR,STRICHR函提#include/*constchar*strchr(constchar*s,intc)constchar*strichr(constchar*s,intc)/*char*strchr(constchar*s,intc)char*strichr(constchar*s,intc)描strchr()sc。如果找到了,則字符指針被返回;0。Strichr()strchr()函數(shù)作用相同。例#include<strings.h>#include<stdio.h>main{staticchartemp[]="Hereitis...";charc=’s’;printf("Character%cwasfoundinstring\n",c);printf("Nocharacterwasfoundin}參strrchr(),strlen(),提#includeintstrcmp(constchar*s1,constchar*s2)intstricmp(constchar*s1,constchar*s2)描strcmp()2s1表進(jìn)行的。Stricmp()strcmp()函數(shù)完全一樣。例#include<string.h>#include<stdio.h>main{intif((i=strcmp("ABC","ABc"))<0)printf("ABCislessthanABc\n");elseif(i>0)printf("ABCisgreaterthanABc\n");printf("ABCisequalto}參strlen(),strncmp(),strcpy(),注意:其它的C序表。返回值為正、零或負(fù),也就是說不一定是-11。STRCPY函提#include/*char*strcpy(char*s1,constchar*/*farchar*strcpy(farchar*s1,constchar*描s2s1指向的字符數(shù)組。目的數(shù)組必須足s2。例#include<string.h>#include<stdio.h>main{charbuffer[256];char*s1,*s2;strcpy(buffer,"Startofline");s1=buffer;s2="...endofline";strcat(s1,s2);printf("Length=%d\n",strlen(buffer));printf("string=\"%s\"\n",buffer);}參strncpy(),strlen(),strcat(),STRCSPN函提#includesize_tstrcspn(constchar*s1,constchar*描例#include<stdio.h>#include<string.h>main{staticcharset[]=printf("%d\n",strcspn("abcdevwxyz",set));printf("%d\n",strcspn("xxxbcadefs",set));printf("%d\n",strcspn("1234567890",set));}STRLEN函提#includesize_tstrlen(constchar*描例#include<string.h>#include<stdio.h>main{charbuffer[256];char*s1,*s2;strcpy(buffer,"Startofline");s1=buffer;s2="...endofline";strcat(s1,s2);printf("Length=%d\n",strlen(buffer));printf("string=\"%s\"\n",buffer);}STRNCAT函提#include/*char*strncat(char*s1,constchar*s2,size_t/*farchar*strncat(farchar*s1,constchar*s2,size_t描s2s1n個(gè)字符被拷貝,結(jié)果包含空s1指向的字符數(shù)組應(yīng)足夠大,以容納結(jié)果字符串。例#include<string.h>#include<stdio.h>main{charbuffer[256];char*s1,*s2;strcpy(buffer,"Startofline");s1=buffer;s2="...endofline";strncat(s1,s2,5);printf("Length=%d\n",strlen(buffer));printf("string=\"%s\"\n",buffer);}參strcpy(),strcmp(),strcat(),提

STRNCMP,STRNICMP函#includeintstrncmp(constchar*s1,constchar*s2,size_tn)intstrnicmp(constchar*s1,constchar*s2,size_tn)描例#include<stdio.h>#include<string.h>main{inti=strcmp("abcxyz","abcxyz");if(i==0)printf("Bothstringsareequal\n");elseif(i>0)printf("String2lessthanstring1\n");printf("String2isgreaterthanstring}參strlen(),strcmp(),strcpy(),STRNCPY函提#include/*char*strncpy(char*s1,constchar*s2,size_t/*farchar*strncpy(farchar*s1,constchar*s2,size_t描例#include<string.h>#include<stdio.h>main{charbuffer[256];char*s1,*s2;strncpy(buffer,"Startofline",6);s1=buffer;s2="...endofline";strcat(s1,s2);printf("Length=%d\n",strlen(buffer));printf("string=\"%s\"\n",buffer);}參strcpy(),strcat(),strlen(),STRPBRK函提#include/*constchar*strpbrk(constchar*s1,constchar*/*char*strpbrk(constchar*s1,constchar*描例#include<stdio.h>#include<string.h>main{char*str="Thisisastring.";while(str!=NULL){printf("%s\n",strstr=strpbrk(str+1,"aeiou"}}STRRCHR,STRRICHR函提#include/*中級和低級系列單片機(jī)*/constchar*strrchr(char*s,intc)constchar*strrichrchar*sintc)/*char*strrchr(char*s,intc)char*strrichr(char*s,intc)描c最后一次在字符串中出現(xiàn)時(shí)的指針。如果沒出現(xiàn),則返回值為空。strrichr()strrchr()函數(shù)完全一樣。例#include<stdio.h>#include<string.h>main{char*str="Thisisastring.";while(str!=NULL){printf("%s\n",strstr=strrchr(str+1,}}參strchr(),strlen(),strcmp(),strcpy(),STRSPN函提#includesize_tstrspn(constchar*s1,constchar*描例#include<stdio.h>#include<string.h>main{printf("%d\n",strspn("Thisisastring","This"));printf("%d\n",strspn("Thisisastring","this"));}STRSTR,STRISTR函提#include/*constchar*strstr(constchar*s1,constchar*s2)constchar*stristr(constchar*s1,constchar*s2)/*char*strstr(constchar*s1,constchar*s2)char*stristr(constchar*s1,constchar*s2)描strstr()函數(shù)返回字符數(shù)組s1中第一次出現(xiàn)字符數(shù)

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論