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 CCS Technical Support

convert Decimal to Hex
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 22, 2009 6:13 pm     Reply with quote

It does lock up if you type in too many numbers. I think the CCS
routine is buggy in some way. It works if you type "125" (only 3 digits).
If you type "1234" then it locks up.
nemero16



Joined: 21 Nov 2009
Posts: 19

View user's profile Send private message

PostPosted: Sun Nov 22, 2009 6:23 pm     Reply with quote

then I also changed the library so input.c be included only 3 digits for the address like this:
Code:
signed int8 get_int() {
  char s[3];
  signed int8 i;

  get_string(s, 3);

  i=atoi(s);
  return(i);
}

Now to convert as I do? I for example I type the decimal value 124 then I have to convert to 7C and send it to address ... how can I do?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 22, 2009 6:30 pm     Reply with quote

Quote:

Then I also changed the library so input.c be included only 3 digits for the address.

According to ckielstra, the length parameter needs to include the
string terminator byte of 0x00. So to get 3 bytes of numbers, you
need to set the length to 4.
Code:
get_string(s, 4);

http://www.ccsinfo.com/forum/viewtopic.php?t=40633

Quote:

Now to convert as I do? I for example I type the decimal value 124 then
I have to convert to 7C and send it to address ...

Do it like this:
Code:
address = get_int();
nemero16



Joined: 21 Nov 2009
Posts: 19

View user's profile Send private message

PostPosted: Sun Nov 22, 2009 6:40 pm     Reply with quote

I changed this:
Code:

     if((cmd!='L') && (cmd!='S')){
     }
     else{
     printf("\n\rBlocco: ");
     address = get_int();}

and:
Code:
signed int8 get_int() {
  char s[3];
  signed int8 i;

  get_string(s, 4);

  i=atoi(s);
  return(i);
}

and:
Code:
 if(len<max) {


but the program always hangs after entering the 3 digit of address ... why? The address is set as follows:
unsigned int8 address;
What is the problem? Confused Confused
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 22, 2009 6:42 pm     Reply with quote

What address are you typing ? Post it.
nemero16



Joined: 21 Nov 2009
Posts: 19

View user's profile Send private message

PostPosted: Sun Nov 22, 2009 6:44 pm     Reply with quote

for example I want to write to 0A and to write to this address should I write 010 in decimal ... right?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 22, 2009 6:57 pm     Reply with quote

It still locks up on the 2nd pass. There's probably something wrong with
the get_string() routine. I don't have time to fix it now. I'll look at it later.
nemero16



Joined: 21 Nov 2009
Posts: 19

View user's profile Send private message

PostPosted: Sun Nov 22, 2009 6:58 pm     Reply with quote

okok I'll wait... thanks for your interest! Very Happy
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 24, 2009 1:07 am     Reply with quote

Quote:
signed int8 get_int() {
char s[3];
signed int8 i;

get_string(s, 4);

i=atoi(s);
return(i);
}

The 's' array is shorter than the length (4) that you are giving to
get_string(). The original code in input.c had them set to 5 and 5.
The 5 locations in the array, allow for the sign character (+ or -)
and the 3 digits, and the string terminator byte. The allowable
numbers that it can handle are in the range from -128 to 127. If you
need to get larger numbers, then you need to use the get_long() function.
nemero16



Joined: 21 Nov 2009
Posts: 19

View user's profile Send private message

PostPosted: Tue Nov 24, 2009 12:48 pm     Reply with quote

ok!! now it works perfectly!! Very Happy thanks!!!
Sebastian



Joined: 01 Dec 2003
Posts: 21
Location: Milan Italy

View user's profile Send private message Send e-mail

PostPosted: Wed Mar 31, 2010 6:55 am     Reply with quote

HI nemero16

I have a question. You have used the input.c file but I don't understand the second part of input of address where are returned the getc() parameter:
Code:

BYTE gethex1() {
   char digit;

   digit = getc();

   putc(digit);

   if(digit<='9')
     return(digit-'0');
   else
     return((toupper(digit)-'A')+10);
}

BYTE gethex() {
   unsigned int8 lo,hi;
   
   hi = gethex1();
   lo = gethex1();
   
   if(lo==0xdd)
     return(hi);
   else
     return( hi*16+lo );
}

What is the meaning of
Code:

 if(lo==0xdd)
     return(hi);
   else
     return( hi*16+lo );

gethex1() return max F =15 for hi but lo because ill must wait 0xdd ?? Shocked

Thanks in advance
wulffert



Joined: 17 Sep 2003
Posts: 6
Location: New York, NY

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sat Apr 03, 2010 11:13 am     Reply with quote

Stick to pre-canned libraries when you can, it will make your life easier. If you worried about code size, look at your listings and see if would be larger than your design can handle.
_________________
http://wulffert.com
http://towerlightmonitor.com
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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