欢迎来到天天文库
浏览记录
ID:55707415
大小:16.00 KB
页数:2页
时间:2020-05-26
《曼切斯特编解码51程序.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、#include"Manchester.h"/*******************************************************************************程序说明基于单片机的曼彻斯特编码程序,功能是将一个8位的数据(一个字节)进行曼彻斯特编码曼彻斯特编码的原则是:电平从高到低跳变表示'1',电平从低到高跳变表示'0'*******************************************************************************//*****************
2、**************************************************************曼彻斯特编码函数参数DataIn:将要进行编码的单字节数据返回值manchesterOut:编码后返回的与参数对应的曼彻斯特编码值*******************************************************************************/unsignedintCharToManchester(unsignedcharEncode_Data){uintManchesterOut=0;uc
3、hari=0;for(i=0;i<8;i++){if((Encode_Data&0x80)==0x80)//说明该位为1{ManchesterOut=ManchesterOut+1;//写1ManchesterOut=ManchesterOut<<1;//左移一位,相当于在最低位写0if(i<7){ManchesterOut<<=1;//移位准备编码下一位Encode_Data<<=1;//待编码数据左移1位,为下一位数据编码做准备}}elseif((Encode_Data&0x80)==0)//说明该位为0{ManchesterOut<<=1;//不写1移
4、位相当于写0ManchesterOut+=1;//写1if(i<7){ManchesterOut<<=1;//移位准备编码下一位Encode_Data<<=1;//待编码数据左移1位,为下一位数据编码做准备}}}returnManchesterOut;//返回编码后的16位值}/*******************************************************************************曼彻斯特译码函数参数Manchester_In:将要进行编码的单字节数据返回值Decode_Data:译码后返回的与参数对应的
5、值*******************************************************************************/ucharManchesterToChar(uintManchester_In){ucharDecode_Data=0;ucharj=0;ucharerror=0;for(j=0;j<8;j++){if((Manchester_In&0xc000)==0x8000)//说明该位为10{Decode_Data=Decode_Data+1;if(j<7){Decode_Data<<=1;//移位准备译码
6、下一位Manchester_In<<=2;//待译码数据左移2位,为下一位数据译码做准备}}elseif((Manchester_In&0xc000)==0x4000)//说明该位为01{//Decode_Data=Decode_Data<<1;//直接左移1位代表写0if(j<7){Decode_Data<<=1;//移位准备译码下一位Manchester_In<<=2;//待译码数据左移2位,为下一位数据译码做准备}}else{error=1;break;}}
此文档下载收益归作者所有