View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 22, 2009 6:13 pm |
|
|
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
|
|
Posted: Sun Nov 22, 2009 6:23 pm |
|
|
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
|
|
Posted: Sun Nov 22, 2009 6:30 pm |
|
|
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.
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
|
|
Posted: Sun Nov 22, 2009 6:40 pm |
|
|
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:
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? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 22, 2009 6:42 pm |
|
|
What address are you typing ? Post it. |
|
|
nemero16
Joined: 21 Nov 2009 Posts: 19
|
|
Posted: Sun Nov 22, 2009 6:44 pm |
|
|
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
|
|
Posted: Sun Nov 22, 2009 6:57 pm |
|
|
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
|
|
Posted: Sun Nov 22, 2009 6:58 pm |
|
|
okok I'll wait... thanks for your interest! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 24, 2009 1:07 am |
|
|
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
|
|
Posted: Tue Nov 24, 2009 12:48 pm |
|
|
ok!! now it works perfectly!! thanks!!! |
|
|
Sebastian
Joined: 01 Dec 2003 Posts: 21 Location: Milan Italy
|
|
Posted: Wed Mar 31, 2010 6:55 am |
|
|
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 ??
Thanks in advance |
|
|
wulffert
Joined: 17 Sep 2003 Posts: 6 Location: New York, NY
|
|
Posted: Sat Apr 03, 2010 11:13 am |
|
|
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 |
|
|
|