Good, no worries. If his code is too large, try figure out what function calls eat much memory by commenting out stuff and rebuilding. For example, use of int and long when you can get past with char, or functions which use software-multiplication/divison when you really don't need it. Another thing you can do is to open the listing window and look for subroutines like __div16x16 __mul16x16 etc. Try avoid using * / % operators or library functions which does use them to eliminate these subroutines. atoi() might actually use one of these subroutines. Maybe the buffers in jay's code can be reduced.Now I get it, ....I am getting "OK" and it is breaking the while(1). Silly me...Why did I not see that.
thanks @bwack
I'd like to add something I forgot regarding the atoi(). Once you have ascii to integer you might want to convert the integer back to decimal string for the lcd. There is a library function for that, but it uses modulo and division. If you have the memory space and time for it is fine (or you already use */% or atoi or similar), but I can give you mine which uses only addition and sub. It wont help though if you have a line somewhere which already calls multiplication or divison ( or modulo). This is a fast integer to five digit decimal string function and doesn't require much program memory. I don't remember what the techique is called. It sort of replaces division by n subroutine by calling subtraction n times instead. (For those who are coming from a google or other search, this is "fast" because we are here using a microcontroller which does not have mul and div instruction opcodes)
C:
void int2dec( unsigned short *array, unsigned int number,
unsigned short factor, unsigned int offset) {
unsigned short i=0;
while(number>=10000u) {
number=number-10000u;
i++;
}
array[0] = i+0x30;
i=0;
while(number>=1000u) {
number=number-1000u;
i++;
}
array[1] = i+0x30;
i=0;
while(number>=100u) {
number=number-100u;
i++;
}
array[2] = i+0x30;
i=0;
while(number>=10u) {
number=number-10u;
i++;
}
array[3] = i+0x30;
array[4] = number+0x30;
array[5]=0;
}
I can rewrite it for three decimal char. I might have a code for that already somewhere on the other computer, but I need to read now.
Hans
Last edited: