原创 Freemodbus之工具函数

2007-9-24 09:35 3652 8 8 分类: MCU/ 嵌入式

Utilities<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />


工具





Detailed Description


详细描述


This module contains some utility functions which can be used by the application. It includes some special functions for working with bitfields backed by a character array buffer.


这个模块包括应用中使用的一些功能函数。这些功能函数包括一些特殊的通过字符数组缓冲方式对位域进行处理的功能



 


 


Functions


void 


xMBUtilSetBits (UCHAR *ucByteBuf, USHORT usBitOffset, UCHAR ucNBits, UCHAR ucValues)


UCHAR 


xMBUtilGetBits (UCHAR *ucByteBuf, USHORT usBitOffset, UCHAR ucNBits)





Function Documentation


函数文档




UCHAR xMBUtilGetBits



UCHAR * 


ucByteBuf,


 


 


USHORT 


usBitOffset,


 


 


UCHAR 


ucNBits


 



 



 



 


Function to read bits in a byte buffer.


在字节缓冲中读取位


This function is used to extract up bit values from an array. Up to eight bit values can be extracted in one step.


这个函数从一个字节中来获取一个位的值。一步最多可以获取8个位的值。


Parameters:


参数



 


ucByteBuf 


A buffer where the bit values are stored.


存储位的缓冲字节


 


usBitOffset 


The starting address of the bits to set. The first bit has the offset 0.


位的起始地址,第一个位的地址偏移量是0


 


ucNBits 


Number of bits to modify. The value must always be smaller than 8.


需要修改的位的数量。该值要小于8


 UCHAR ucBits[2] = {0, 0};

 UCHAR ucResult;

 

 

 ucResult = xMBUtilGetBits( ucBits, 3, 8 );


 




void xMBUtilSetBits



UCHAR * 


ucByteBuf,


 


 


USHORT 


usBitOffset,


 


 


UCHAR 


ucNBits,


 


 


UCHAR 


ucValues


 



 



 



 


Function to set bits in a byte buffer.


设置一个字节缓冲的位


This function allows the efficient use of an array to implement bitfields. The array used for storing the bits must always be a multiple of two bytes. Up to eight bits can be set or cleared in one operation.


这个函数可以实现有效处理位域的功能。存储位域的数值必须是两个字节。一次操作最多可处理8位。


Parameters:



 


ucByteBuf 


A buffer where the bit values are stored. Must be a multiple of 2 bytes. No length checking is performed and if usBitOffset / 8 is greater than the size of the buffer memory contents is overwritten.


位存储的缓冲区。必须是2个字节。


 


usBitOffset 


The starting address of the bits to set. The first bit has the offset 0.


位设置的起始地址,第一个位的偏移为0


 


ucNBits 


Number of bits to modify. The value must always be smaller than 8.


需要修改的位的数量。该值必须小于8


 


ucValues 


Thew new values for the bits. The value for the first bit starting at usBitOffset is the LSB of the value ucValues


位的新值。在usBitOffset中的第一位的值是ucValues的最低有效位。


 ucBits[2] = {0, 0};

 

 

 xMBUtilSetBits( ucBits, 4, 1, 1 );

 

 

 xMBUtilSetBits( ucBits, 7, 2, 0x01 );

 

 

 xMBUtilSetBits( ucBits, 8, 8, 0x5A);

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
8
关闭 站长推荐上一条 /3 下一条