This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

sprintf(s,"floatvalue = %f",12.345) gives wrong value

TOOL: RVMDK V3.02a, with RealView V3.0 compiler.

I use uC/OS-II in this program.
Please mail to me for a complete example.
huawdg@pub.wx.jsinfo.net

Code in system_task.c:

#include <LPC22xx.H>

#include    "includes.h"
#include    "generictype.h"
#include        "rt_locale.h"
#include        "locale.h"

void IRQ_Exception(void)
{
    VICVectAddr=0;
}

void timer0_Exception(void)
{
    T0IR = 0x01;

    OSTimeTick();

    VICVectAddr=0;  //interrupt routine finish
}


void TaskIdleHook(void)
{
}

void DAbt_Handler(void) {}
void PAbt_Handler(void) {}
void Undef_Handler(void){}
void FIQ_Handler(void) {}

extern void IRQ_Handler(void);
extern void timer0_Handler(void);


#define SIZE_TASKSTART_STK  800
static  OS_STK  TaskStartStk[SIZE_TASKSTART_STK];

//timer0: 10ms
void timer0_Init(void)
{
    T0IR = 0xffffffff;
    T0TC = 0;
    T0TCR = 0x01;
    T0PR = 0;
    T0MCR = 0x03;
    T0MR0 = 110592;
}


void VICInit(void)
{
    VICIntEnClr = 0xffffffff;
    VICDefVectAddr = (unsigned long)IRQ_Handler;

    VICVectAddr1 = (unsigned long)timer0_Handler;
    VICVectCntl1 = (0x20 | VICINT_NUM_TIMER0);
    VICIntEnable = 1 << VICINT_NUM_TIMER0;
}


void  task_Start(void *pdata)
{
     char s[100];

    VICInit();
    timer0_Init();

    sprintf(s,"float=%f",12.345);       //wrong result
    sprintf(s,"float=%f",8871.5678);    //wrong result

    while(1);
}



int main(void)
{

        setlocale(LC_ALL,"C");
    VICIntEnClr = 0xffffffff;

    OSInit();
    OSTaskCreate(task_Start, (void *)0, &TaskStartStk[SIZE_TASKSTART_STK - 1], 5);

    OSStart();
    return 0;
}
void _sys_exit(int return_code) {
label:  goto label;  /* endless loop */
}

0