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


#include  
#include  
#include  
#include  
 
//-----***-发送一个字节-***-----// 
void SentByte(unsigned char Byte) 
{ 
    unsigned char i,k,ii,jj; 
    bit j,kk; 
    j=0; 
    k=Byte; 
    ii=Byte; 
    ES=0; 
    for(i=0;i<8;i++) 
    { 
       if(k&0x80) 
       {		 
           j=~j;      
       } 
       k<<=1;	 
    } 
    if(j) 
    { 
         kk=1; 
         TB8=1; 
    } 
    else 
    { 
         kk=0; 
         TB8=0; 
    } 
    if(InfSendFg)		 
    { 
        HwTxd=0;//--------------------------------------------------------起始位 
        Delay(55); 
        for(jj=0;jj<8;jj++)//---------------------------------------------8个数据位 
        { 
             if(ii&0x01) 
          	 { 
          	 	  HwTxd=1; 
          	 } 
          	 else 
          	 { 
          		  HwTxd=0; 
          	 } 
             ii >>=1; 
             Delay(55); 
        } 
        if(kk) 
        { 
            HwTxd=1;//----------------------------------------------------校验 
            Delay(55); 
        } 
        else 
        { 
            HwTxd=0;//----------------------------------------------------校验 
            Delay(55); 
        } 
        HwTxd=1;//--------------------------------------------------------结束 
        Delay(55); 
        AUXR1=0x00; 
    } 
    else 
    { 
       	SBUF=Byte;//------------------------------------------------------发送数据 
       	while(TI!=1);//---------------------------------------------------等待发送完毕 
       	TI=0; 
    } 
    ES=1; 
} 
//-----***-填充发送数据缓冲区-***-----// 
void SendFull(void) 
{ 
	unsigned char i,CheckSum;	 
	WDT(); 
	CheckSum=0;	 
	InceptBuf[0]=0x68; 
	RamCopy(&InceptBuf[1],MeterAdd,6);//------------------------------提取表地址 
	if(NullityFg) 
    { 
        NullityFg=0; 
        InceptBuf[8]=InceptBuf[8]|0xc0; 
    } 
    else 
    { 
        InceptBuf[8]=InceptBuf[8]|0x80; 
    } 
    for(i=10;i<(InceptBuf[9]+11);i++) 
    { 
        InceptBuf[i]=InceptBuf[i]+0x33; 
    } 
	InceptBuf[InceptBuf[9]+10]=EleChk(InceptBuf,(InceptBuf[9]+10)); 
	InceptBuf[InceptBuf[9]+11]=0x16; 
	WDT(); 
	SentByte(0xfe); 
	SentByte(0xfe); 
	SentByte(0xfe); 
	for(i=0;i