www.pudn.com > DDS485.rar > bcdhex.c


#include<stdio.h>
#include<reg932.h>
#include<define.h>

//-----***-16近制数据转化为BCD-***-----//
unsigned char HexToBcd(unsigned char Bytedata)
{
unsigned char ii,Byte; /*定义减数i,被减数j,相减蚀锡k,余数h*/
ii=0;
while(Bytedata>=0x0a)
{
Bytedata=Bytedata-0x0a;
ii=ii+1;
}
Byte=16*ii+Bytedata;
return Byte;
}
//-----***-BCD数据转化为16近制-***-----//
unsigned char BcdToHex(unsigned char Bytedata)
{
unsigned char i,j,Byte; /*定义减数i,被减数j,相减蚀锡k,余数h*/
i=Bytedata &amt; 0xf0;
j=Bytedata &amt; 0x0f;
Byte=10*(i>>4)+j;
return Byte;
}
//-----***-接受的数据减去0x33-***-----//
void DataDeal(void)
{
unsigned char i;
for(i=10;i<InceptBuf[9]+10;i++)
{
InceptBuf[i]=InceptBuf[i]-0x33;
InceptBuf[InceptBuf[9]+10]=InceptBuf[InceptBuf[9]+10]-0x33;//校验和根据数据长度连续减0x33;
}
}