代码如下:
unsigned char32 Slave_adr[8];
unsigned char32 Slave_Send_adr[73];
void bit_set(int32 x,int y)
{ int32 temp;
temp=1;
temp=temp<<y;
x=x|temp;
}
void bit_clear(int32 x,int y)
{ int32 temp;
temp=1;
temp=temp<<y;
temp=~temp;
x=x&temp;
}
int1 bit_test(int32 x,int y)
{ int32 temp;
temp=1;
temp=temp1<<y;
temp=x&temp;
if(temp) return(1);
else return(0);
}
//输入参数:x为从机号码;
void Slave_Address_set_bit(unsigned char *buff)
{ unsigned char quotient_Value; //用来放商值;
unsigned char residue_Value; //用来放余数;
unsigned char x;
x=atoi(buff);
quotient_Value=x/32;
residue_Value=x%32;
bit_set(Slave_adr[quotient_Value],residue_Value); //更新Slave_adr[];
}
//输入参数:x为从机号码;
void Slave_Address_clear_bit(unsigned char *buff)
{ unsigned char quotient_Value; //用来放商值;
unsigned char residue_Value; //用来放余数;
unsigned char x;
x=atoi(buff);
quotient_Value=x/32;
residue_Value=x%32;
bit_clear(Slave_adr[quotient_Value],residue_Value); //更新Slave_adr[];
}
//输入参数:x为从机号码;
bit Slave_Address_test_bit(unsigned char *buff)
{ unsigned char quotient_Value; //用来放商值;
unsigned char residue_Value; //用来放余数;
unsigned char x;
x=atoi(buff);
bit temp_bit;
quotient_Value=x/32;
residue_Value=x%32;
temp_bit=bit_test(Slave_adr[quotient_Value],residue_Value);
return(temp_bit);
}
//函数功能:将Slave_adr[]中的数据转换为16进制ASCii码,保存到Slave_Send_adr[]中
void send()
{ signed char i;
unsigned char temp_array[5];
int temp;
memset(Slave_Send_adr,'\0',73);
for(i=7;i>=0;i--)
{ memset(temp_array,'\0',5);
temp=(int)(Slave_adr[i]>>4);
sprintf(temp_array,"%Lx",temp); //将高16位转换为16进制ASCii码;
strcat(Slave_Send_adr,temp_array);
temp=(int)Slave_adr[i];
sprintf(temp_array,"%Lx",temp); //将低16位转换为16进制ASCii码;
strcat(Slave_Send_adr,temp_array);
memset(temp_array,'\0',5);
strcpy(temp_array,";")
strcat(Slave_Send_adr,temp_array);
}
}
如果麻烦就只翻译
unsigned char32 Slave_adr[8];
unsigned char32 Slave_Send_adr[73];
和这三个函数
void bit_set(int32 x,int y)
void Slave_Address_set_bit(unsigned char *buff)
void send()
慕尼黑的夜晚无繁华
白板的微信
相关分类