CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

itol("100000") = 34464...... Why?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
williankleber



Joined: 17 Sep 2012
Posts: 4
Location: Brasil

View user's profile Send private message Visit poster's website

itol("100000") = 34464...... Why?
PostPosted: Mon Sep 17, 2012 2:21 pm     Reply with quote

Code:
      int16 k;
      char u[] = "100000";
      k = atol(u);


At the end of this code, the variable "K" takes the value 34464.

I'm using PICC PCW and the PIC is 18F4520.

I will use this algorithm to convert one string with binary sequence, in a binary type.

I thank all for the attention Very Happy
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Sep 17, 2012 2:25 pm     Reply with quote

What's the largest number an int16 can hold?

and answer that question for unsigned and signed.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
williankleber



Joined: 17 Sep 2012
Posts: 4
Location: Brasil

View user's profile Send private message Visit poster's website

PostPosted: Mon Sep 17, 2012 2:34 pm     Reply with quote

I changed my code to
Code:
   while (1){
      unsigned int32 k;
      char u[] = "100000";
      printf(lcd_putc,"\fu = %s",u);
      delay_ms(2000);
      k = atol(u);
      printf(lcd_putc,"\fk = %lu",k);
      delay_ms(2000);


and the problem continues,

The number 100000 should fit into a INT32 variable. Does this has to do with processing of 16bit PIC?
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Sep 17, 2012 2:41 pm     Reply with quote

williankleber wrote:
I changed my code to
Code:
   while (1){
      unsigned int32 k;
      char u[] = "100000";
      printf(lcd_putc,"\fu = %s",u);
      delay_ms(2000);
      k = atol(u);
      printf(lcd_putc,"\fk = %lu",k);
      delay_ms(2000);


and the problem continues,

The number 100000 should fit into a INT32 variable. Does this has to do with processing of 16bit PIC?



The PIC18's are 8bit CPUs (just so you know) and being 16 or 32 bits doesn't matter as the compiler does the work for that. I do 16/32bit math all the time on PIC18's.


So at this point, you should post a small compilable example (and your compiler version) as the second sticky-post to this forum describes.

Also, you're not using Proteus, are you?

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Sep 17, 2012 2:53 pm     Reply with quote

Better yet -- look at the CCS manual (.CHM) again for atol

And look closely at the other items listed on the same help page.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
williankleber



Joined: 17 Sep 2012
Posts: 4
Location: Brasil

View user's profile Send private message Visit poster's website

PostPosted: Mon Sep 17, 2012 2:56 pm     Reply with quote

This is my code:
Code:
#include <18F4520.h>
#use delay(clock=4000000)
#include <stdio.h>
#include <stdlib.h>
#include "lcd.c"
#include <math.h>
void main(){
   lcd_init();
   while (1){
      unsigned int32 k;
      char u[] = "100000";
      printf(lcd_putc,"\fu = %s",u);
      delay_ms(2000);
      k = atol(u);
      printf(lcd_putc,"\fk = %lu",k);
      delay_ms(2000);
   }
}


My compiler version is 4.074
And really, I'm using proteus for simulation. Does that is causing the problem?

I'll mount the circuit on a board, soon put the result.

Thank you very much bkamen, is helping me a lot...
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Sep 17, 2012 3:10 pm     Reply with quote

williankleber wrote:
This is my code:

My compiler version is 4.074
And really, I'm using proteus for simulation. Does that is causing the problem?




In this case, Proteus is not the problem. Look at the CCS PICC compiler manual again.

Just keep in mind that in the future -- Proteus can be a problem in general for emulating PIC code. There's enough features in a PIC that proteus incorrectly emulates nullifying using proteus at all.

Cheers,

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Sep 17, 2012 3:11 pm     Reply with quote

Quote:
This is my code

You still didn't change your code to use atoi32()...
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Sep 17, 2012 5:13 pm     Reply with quote

FvM wrote:
Quote:
This is my code

You still didn't change your code to use atoi32()...




Boooo! I told him that! (via "look at the manual") hahaha...

Razz
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
williankleber



Joined: 17 Sep 2012
Posts: 4
Location: Brasil

View user's profile Send private message Visit poster's website

Fixed...
PostPosted: Tue Sep 18, 2012 7:57 am     Reply with quote

solved using atoi32()...
Follow the hint of bkamen, and found all the documentation in the HELP Files of PICC.


Quote:
Posted: Mon Sep 17, 2012 6:11 pm Post subject:

Quote:
This is my code


You still didn't change your code to use atoi32()...

Sorry FvM and bkamen, I posted the same instant that the bkamen, for this reason the code had not yet been changed...

anyway, thanks to all for help.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group