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

📄 calculator.h

📁 Thermostat Project using DS18B20 and P89V51RD2 Microcontroller. Compiler used is SDCC. Schematic Inc
💻 H
字号:
//Floating point functions library.
//Some functions were available from the SDCC Library itself.
//Only one function needed to be added to make a complete floating point library.
//Author: Anurag Chugh (anurag@ucmicrosys.com)

#ifndef __p89v51rd2_h__
	#include <p89v51rd2.h>
	#define __p89v51rd2_h__
#endif

#include<float.h>
#include<math.h>
#include<stdlib.h>


//Function to convert from float to string was missing from SDCC's library.
//So the following function has been used.
//It has been taken from svicent's post at
//http://www.edaboard.com/ftopic118087.html

const float ROUND[6]={0.49,0.05,0.005,0.0005,0.00005,0.000005};

void ftoa(float fnum, unsigned char decimals, unsigned char *str)
{
	float scale;
	unsigned char u1,u2;
	
	if (fnum<0.0)
	{
		fnum=-fnum;
		*str++='-';
	}

	if (decimals>5)
		decimals=5;

	fnum += ROUND[decimals];
	u1=0;
	scale=1.0;
	
	while (fnum>=scale)
	{
		scale *= 10.0;
		++u1;
	}

	if (u1==0)
		*str++='0';
	else
		while (u1--)
		{
			scale=floorf(0.5+scale/10.0);
			u2=(unsigned char)(fnum/scale);
			*str++=u2+'0';
			fnum -= scale*u2;
		}
	
	if (decimals==0)
	{
		*str=0;
		return;
	}

	*str++='.';
	
	while (decimals--)
	{
		fnum *= 10.0;
		u2=(unsigned char) fnum;
		*str++ = u2+'0';
		fnum -= u2;
	}
	
	*str=0;
}

⌨️ 快捷键说明

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