⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tstfloat.c

📁 The code is for Auxiliary IO module which supports 16 inputs and 16 outputs and Modbus protocol
💻 C
字号:
#include <Stdio.h>

idata union test_data 
{
unsigned char dchar[5];
unsigned int  dint[2];
float  dfloat[1];
};
union test_data a;

unsigned char decnt;
volatile float test;
bit zerf = 0;

void Process_data();


main()
{
a.dfloat[0]  =77.77;
Process_data();
while(1)
{
}
} 

// 
// when test = 1500 and zerf = 0 , it is suppose to display 15.00, 
// when test = 15 and zerf = 1 , it is suppose to display 0.015, 
//


void Process_Data()
{
unsigned int test1;
if((a.dfloat[0] <= 9999) && (a.dfloat[0] >= 0))
{
	test = a.dfloat[0];
 	if(test == 0)
 	{  
	decnt = 0;  // decnt = 0, no decimal
	test = (int)(test);
 	}
 	
  	else if((test >= 0) && (test < 10))
	{ 
	if(test < 1)
	  zerf = 1;  
	decnt = 3;
   	test = (int)(test * 1000);
	}
	else if((test >= 10) && (test < 100))
	{  
	decnt = 2;
   	test= ((test * 100)/1);
	test1 = (unsigned int)test;
	}
	else if((test >= 100) && (test < 1000))
	{  
	decnt = 1;
   	test= (test * 10);
	}
	else if((test >= 1000) && (test < 9999))
	{  
	decnt = 0;
   	test= (test);
	}
}
else
{
	//default value
	test = 0;
	decnt = 0;
}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -