Hi, ATOI on HCS08 not working for me, help

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Hi, ATOI on HCS08 not working for me, help

跳至解决方案
2,886 次查看
gusnavarro
Contributor II

Hi, im new here, and Im doing a proyect which happens that i need to change a string to integer.

On C eclipse works fine however on Freescale doesnt do anything.

 

Pleace help

 

I create a new proyect apart just to see ATOI working properly. I was able to see that the variable "number" changes from 4 to cero, as if nothing got atoi and if I uncoment the atof line i geet the error Symbol strtod ... is undefined.

 

Please advice (version of  my codewarrior is V6.3 build 9279

This is the code:

 

#include <hidef.h> /* for EnableInterrupts macro */

#include "derivative.h" /* include peripheral declarations */

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

 

char y[] @0x0068 ="12";

char f[] @0x0070 ="143.343";

 

int number @0x0060 =4;

double flot;

 

void main(void) {

  

  EnableInterrupts; /* enable interrupts */

  /* include your code here */      

  for(;;) {

    __RESET_WATCHDOG(); /* feeds the dog */

      number=atoi((const char*)y);   /// also like this doesnt work : number=atoi(y);

  

     //flot = atof((const char*)f);

 

  } /* loop forever */

  /* please make sure that you never leave main */

}

标签 (1)
1 解答
2,618 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Gus,

You can use function atoi() directly in your application.

See attached example project for reference.


Have a great day,
Zhang Jun

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

在原帖中查看解决方案

10 回复数
2,619 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Gus,

You can use function atoi() directly in your application.

See attached example project for reference.


Have a great day,
Zhang Jun

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

2,618 次查看
gusnavarro
Contributor II

I have another doubt.

Your code works fine under MC9S08DZ60, but on the proyect im working on which happens to be 08QG8 doesnt work there

why is that ?


Greetings

0 项奖励
回复
2,618 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi

1. QG8 default project allocates 0x40 bytes RAM to stack. while atoi and atof is very memory consuming. so you need increase the stack size.

2. use atof, you need use floating support.

see attached demo code and screenshot.


Have a great day,
Zhang Jun

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

2,618 次查看
gusnavarro
Contributor II

Thanks a lot Zhang!

I owe you a beer ! :smileyhappy:

0 项奖励
回复
2,618 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

You are welcome !  :-)


Have a great day,
Zhang Jun

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

2,618 次查看
gusnavarro
Contributor II

Hi Jennie!
I have a new quetion for you :smileygrin:

0 项奖励
回复
2,618 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Gus,

please create a new thread for the new questions. I will check. thanks!


Have a great day,
Zhang Jun

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

2,618 次查看
gusnavarro
Contributor II

Thanks a lot Jennie :smileyhappy:

0 项奖励
回复
2,618 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

you are welcome! :-)


Have a great day,
Zhang Jun

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
2,618 次查看
gusnavarro
Contributor II

Thank you Zhang! now it works fine atoi ! thx a lot

By the way  , do you happen to know why im getting strtod in file main.c.o is undefined ? in case i want to use atof ?

0 项奖励
回复