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

About input.c file

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



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

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

About input.c file
PostPosted: Thu Apr 01, 2010 7:23 am     Reply with quote

Hi all

I'm trying to read and write a I2C serial eprom using EX_EXTEE program.
I have a question. 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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 01, 2010 12:18 pm     Reply with quote

It's the method used by CCS to detect if the user has pressed the Enter
key after typing only one hex character. The gethex() function is
normally used to get two "nibbles" (4-bit values) which make up a hex
byte, such as "AB" (0xAB). The user will type in an 'A', followed by
a 'B'. But what if the user only wants to enter "0B", and only types
in a 'B' (without the leading 0) and presses the Enter key? The CCS
routine will detect this. If the 2nd key pressed is the Enter key, the
gethex1() routine will return 0xdd. If that happens, the gethex()
routine only returns the first byte.

It provides a convenience for the user, so he doesn't always have to
type in two nibbles, for example 0B, or 05, or 09, etc., if he just wants
to enter a single hex digit. He can skip putting in the leading zero if
he wants to.
Sebastian



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

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

PostPosted: Fri Apr 02, 2010 3:42 am     Reply with quote

PCM programmer wrote:

But what if the user only wants to enter "0B", and only types
in a 'B' (without the leading 0) and presses the Enter key? The CCS
routine will detect this. If the 2nd key pressed is the Enter key, the
gethex1() routine will return 0xdd. If that happens, the gethex()
routine only returns the first byte.


Thanks PCM programmer
I've looked in the manual complier but I don't have find explanations about.
If I look more closely the code what is the right way to obtain 0xdd

The character of enter is 0x13 but if I apply the code
Code:

return((toupper(digit)-'A')+10);

the result it's wrong, in fact
return((toupper(digit)-0x41)+10) give me a bad result
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 02, 2010 9:37 am     Reply with quote

Quote:
The character of enter is 0x13

Wrong. It's 0x0D.
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