📄 comfunc.c
字号:
#include "..\arm\os_cpu.h"
INT8U CvtBcdToStr(INT16U iIntData, INT8U nBufSize, INT8U *pStrBuf)
{
while (iIntData > 0 && nBufSize > 0) {
nBufSize--;
*(pStrBuf+nBufSize) = iIntData%16 + '0';
iIntData /= 16;
}
return nBufSize;
}
INT8U CvtIntToStr(INT16U iIntData, INT8U nBufSize, INT8U *pStrBuf)
{
while (iIntData > 0 && nBufSize > 0) {
nBufSize--;
*(pStrBuf+nBufSize) = iIntData%10 + '0';
iIntData /= 10;
}
return nBufSize;
}
void CvtFltToStr(float fFloat, INT8U nBufSize, INT8U *pStrBuf)
{
INT8U nLeftNum;
INT16U iIntPart;
nLeftNum = 0;
if (fFloat < 0) {
*pStrBuf++ = '-', nBufSize--;
fFloat = -fFloat; // 当浮点数为负数
}
if (fFloat >= 1) {
iIntPart = (INT16U) fFloat;
nLeftNum = CvtIntToStr(iIntPart, nBufSize, pStrBuf);
for (; nBufSize > nLeftNum; nBufSize--) {
*pStrBuf = *(pStrBuf + nLeftNum);
pStrBuf++;
}
fFloat -= iIntPart;
} else {
*pStrBuf++ = '0', nLeftNum = nBufSize - 1;
}
if (nLeftNum > 0) {
*pStrBuf++ = '.', nLeftNum--;
}
while (nLeftNum > 0) {
fFloat *= 10;
iIntPart = (INT16U)fFloat;
*pStrBuf++ = (INT8U)iIntPart + '0';
fFloat -= iIntPart, nLeftNum--;
}
}
INT16U SwapInt16(INT16U temp)
{
INT16U temp1;
temp1=(temp&0xff00)>>8;
temp =(temp&0x00ff)<<8;
return(temp+temp1);
}
INT32U SwapInt32(INT32U temp)
{
union W temp232,temp132;
temp232.Dword=temp;
temp132.Bytes[0] = temp232.Bytes[3];
temp132.Bytes[1] = temp232.Bytes[2];
temp132.Bytes[2] = temp232.Bytes[1];
temp132.Bytes[3] = temp232.Bytes[0];
return(temp132.Dword);
}
INT16U Char2ToInt16(INT8U * temp)
{
INT16U temp16;
temp16=((INT16U)(*temp))<<8;
temp++;
temp16=temp16+(INT16U)(*temp);
return(temp16);
}
INT32U Char4ToInt32(INT8U * temp)
{
INT32U temp32;
temp32=((INT32U)(*temp))<<24;
temp++;
temp32=temp32+(((INT32U)(*temp))<<16);
temp++;
temp32=temp32+(((INT32U)(*temp))<<8);
temp++;
temp32=temp32+(INT32U)(*temp);
return(temp32);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -