資源描述:
《無線數(shù)據(jù)傳輸系統(tǒng)》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、無線數(shù)據(jù)傳輸系統(tǒng)作者:高涵,竇振中單片機收發(fā)程序清單:staticcharcodecodebuf[]=//要發(fā)送的字符"Thisprogramisademooftheserialcommunicationquomodo";#include#include#include#defineTRUE1#defineFALSE0#defineINBUF_LEN30//數(shù)據(jù)長度unsignedcharinbuf1[INBUF_LEN];sbitP2_0=P2^0;bitread_flag;u
2、nsignedcharchecksum,count3;unsignedchart;voidReceive_prepare();voidSend_prepare();voiddelay();/****************************************TMOD{GATE1C/~TM1M0GATE0C/~TM1M0}TCON{TF1TR1TF0TR0IE1IT1IE0IT0}IE{EA-ET2ESET1EX1ET0EX0}****************************************/voidinit_s
3、erialcomm(void){SCON=0x50;//SCON:serailmode1,8-bitUART,enableucvrTMOD
4、=0x20;//TMOD:timer1,mode2,8-bitreloadPCON
5、=0x80;//SMOD=1;TH1=0xFA;//Baud:9600fosc=11.0592MHzIE
6、=0x90;//EnableSerialInterruptTR1=1;//timer1run//TI=1;2}//向串口發(fā)送一個字符voidsend_char_com(unsignedcharch){SBUF=ch
7、;while(TI==0);TI=0;}//向串口發(fā)送一個字符串,strlen為該字符串長度voidsend_string_com(unsignedchar*str,unsignedintstrlen){unsignedintk=0;do{send_char_com(*(str+k));k++;}while(k8、chari;P2_0=TRUE;//置PTR2000為發(fā)送狀態(tài)read_flag=FALSE;2init_serialcomm();//初始化串口t=0;//清發(fā)送字符個數(shù)while(t<40){for(i=0;i9、com(inbuf1,INBUF_LEN);}}voidReceive_prepare(){P2_0=FALSE;delay();}voidSend_prepare(){P2_0=TRUE;delay();}voiddelay(){unsignedchari,j;for(i=0;i<250;i++){for(j=0;j<10;j++);};}2