BTW, the code is posted to be freely used, so use GPL, GPL2, BSD or the
licence you want to use, not a problem.
Olgierd
El mié, 05-07-2006 a las 15:30 -0400, Olgierd Eysymontt escribió:
> Hi, as I got no answer to the problem of printing floats in pic16 port,
> I made a small routine to print numbers in the form DDDDD.MMMMMMM to 8
> decimal places, it's very simple, but can be useful to somebody else.
>
> The usart_send_2 routine is used to send chars to the serial port, so
> can be implemented by the user in different ways.
>
> Olgierd
>
> ----------------------
> // code
>
>
> /**
> Converts a float number into a string considering 'left_min_zeros'
> numbers before the decimal place and 'decimals' decimals
>
> */
> void send_float(float val, unsigned char decimals , unsigned char
> left_min_zeros){
> unsigned char i,j;
> union float_long fl1;
> unsigned char sign,et;
> char exp;
> char int_part[10],dec_part[10];
>
> unsigned long mantissa,mint,mflot,sum_dec,mask,comp;
>
> //Lookup Table of 1e8/2^i for calculation of decimal valued
> unsigned long dec_vals[23]={
> 50000000 ,
> 25000000 ,
> 12500000 ,
> 6250000 ,
> 3125000 ,
> 1562500 ,
> 781250 ,
> 390625 ,
> 195312 ,
> 97656 ,
> 48828 ,
> 24414 ,
> 12207 ,
> 6103 ,
> 3051 ,
> 1525 ,
> 762 ,
> 381 ,
> 190 ,
> 95 ,
> 47 ,
> 23 ,
> 12 };
>
>
> fl1.f = val;
>
> sign=SIGN(fl1.l);
> exp = EXP (fl1.l) - 127;
> mantissa=MANT(fl1.l);
>
>
> mint=mantissa;
> for(i=0;i<23-exp;i++){
> mint=mint >> 1;
> }
> et=9+exp;
> mflot = ((mantissa << et) >> 9);
>
> // now do an arithemtic sum of decimals values
> sum_dec=0;
> for(i=0;i<23;i++){
> mask=1ul<<i;
> comp=mask & mflot;
>
> if (comp != 0ul ){
> sum_dec=sum_dec+dec_vals[22-i];
> }
> }
> // now I print the number
> ltoa(mint, int_part, 10);
> ltoa(sum_dec, dec_part, 10);
>
> if (sign==1)
> usart_send_2('-');
> else
> usart_send_2(' ');
>
> // check the sizes, reuse the exp variable
> exp = left_min_zeros-strlen(int_part);
> // do i have to add zeros a beginning
> if(exp > 0)
> for(i=0;i<exp;i++)
> usart_send_2('0');
> // send the integer part
> send_uint(mint);
> usart_send_2('.');
>
> // check the zeros of decimal part, reuse the exp variable
> exp = 8-strlen(dec_part);
> if(exp > 0)
> for(i=0;i<exp;i++)
> usart_send_2('0');
> // send the decimal part
> for(i=0;i<decimals-exp;i++)
> usart_send_2(dec_part[i]);
>
>
> }
>
>
>
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Sdcc-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sdcc-user
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user