View previous topic :: View next topic |
Author |
Message |
Sebastian
Joined: 01 Dec 2003 Posts: 21 Location: Milan Italy
|
About input.c file |
Posted: Thu Apr 01, 2010 7:23 am |
|
|
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 ??
Thanks in advance |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 01, 2010 12:18 pm |
|
|
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
|
|
Posted: Fri Apr 02, 2010 3:42 am |
|
|
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
|
|
Posted: Fri Apr 02, 2010 9:37 am |
|
|
Quote: | The character of enter is 0x13 |
Wrong. It's 0x0D. |
|
|
|