Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

MikroBasic FloatToStr function generates too much code

Status
Not open for further replies.

ameriq

Junior Member level 3
Joined
Oct 1, 2007
Messages
29
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,283
Location
Pakistan
Activity points
1,487
Yesterday I was working on a student tutorial for acquiring analog data and displaying it on standard LCD. I was using PIC16F819 and Mikrobasic Pro2009 compiler. I was surprised to get the message that there is not enough ROM on controller to hold the program. When I comment out the FloatToStr function the program is quite small.
When same program was written for MikroC pro 2009 the program compiled comfortably. Even better was PROTON Basic whose code just used 30% of memory.

My point here is to suggest improvements in displaying floating point data in MikroBasic for smaller controllers like 16F819.
 

Personally, I would avoid floating point functions with any small MCU unless there really is no alternative. Most often, the arithmetic can easily be done using integer functions and simply keeping track of the decimal point position, either inherently in the way you code (you just know where it is and code accordingly) or by actually having a variable for the position.

Unless you are doing some serious and extensive floating point manipulation, the above almost always saves a lot of memory for a small amount of extra complication and effort.

That said, it sounds like the MikroE compiler needs some work!
 

Well, After seeing your post i have come to conclude that, you are in need to display a floating point value in LCD. Displaying a floating point in LCD is little burden for newbies as like you and me. I have been working for more than a couple of days to over come this issue(printing float in LCD). Then, i wrote the code given below.

As i use proteus simulator, i am not aware of h/w. Please try this code and let us know what happens.
Code:
void pr(float a)                        //Function to print Float value
{
	float d2, d1;       //Data types for use.
	int i, j, k, l, m;    // ""          ""
	i=(int)a;            //Conversion of Float to int. (eg 1.25 to 1)
	lcd_putn(i);       //Print "i" once if it gets int value(print 1)
	lcd_puts(".");    //function to print '.' for decimal point
	k=i*100;          //This is to convert (1*100=100)
	a=a*100;         //This is to make decimal numbers to disappear (1.25*100=125.0000)
	l=(int)a;           //This is to copy and convert float a to decimal a (125.0000 to 125)
	m=l-k;             //This is to find the original value of decimal point (125-100=25). 
	if(m<=9)         //If suppose the obtained value is less than 10, we have to print '0' before printing the decimal value
	lcd_puts("0");
	lcd_putn(m);    //Time to print the obtained integer(25) which is the required decimal value.
	k,l,m,j,i=0;      //Clear all the data types used.
	d2=d1=0.0000;
	DelayMs(30);
}

This is the code that i used to print float values. I tried by myself to write this program. Please intimate me if you get any problem and also, suggest me if i need to modify this code.
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top