This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

problem with printf()

Hello,
I want to ask a little bit help.
I want to use the printf instruction with the Noice debugger.

I can printf char or float fine but when I try to printf int or long I get a totally different numbers throu the serial port.

eg. WORKS
void main (void)
{
unsigned char f;
for (f=0;f<=255;++f)
printf( %bu \n",f);
}

but DOESN'T WORK

void main (void)
{
unsigned int f;
for (f=0;f<=255;++f)
printf( %u \n",f);
}
Thanks for any advice
Cheer George

Parents Reply Children
  • Hello,

    for (c=0; c<= (unsigned int)33000, ++c)

    I haven't tried yet but I'll tomorrow.

    I put the "unsigned int" to the printf function but it didn't wok.

    I tried the following program
    unsigned int i;
    for (i=0; i<=10; ++i)
    printf("%u \n",i)
    and the result was
    04
    65536
    1310724
    1966084
    2621444
    3276804
    3932164
    5242884
    5898244
    6553604
    and so on

    it seems to me the last digit is usually 4 isn't it the lenght of the string that produces the printf?

    If I tried
    printf("%x \n",i);
    the result was
    04
    100004
    200004
    300004
    400004
    and so on.

    if I use the unsigned long instead of int the result is
    14
    24
    34
    44
    54
    64
    and so on.

    I don't know why but my system is unstable.
    the above programs works if the off-chip code start at 4003h
    but I changed to 4100h the or shomewhere 5000h it doesn't work or if works gives a different results.
    My off chip code memory is from 4000 to 7fff.
    May I ask you to contact me the keilc51@freemail.hu it would be easier for me to contact you.

    Thanks
    George



  • Considering that
    1. C51 passes parameters in fixed memory locations, and
    2. C51 stores multibyte values in big-endian order (high-order byte first)

    If

    unsigned int i;
    printf("%x \n",i);
    gives you
    100004
    200004
    300004
    400004
    and so on

    it sounds like your parameters are getting scrambled!
    The low nibble 1, 2, 3, 4, ... values of i seem to be appearing where the code expects to find the high nibble; because it's expecting an int, it then just reads on in memory, printing junk!

    Maybe you have a memory addressing problem?


  • Memory addressing problem??
    I don't know.
    I didn't mentioned but I allways modify the hex file before I download it.
    The reason is there are a strange line in the hex record.
    03000002xxxx
    it'means c51 put a jump instruction to start routin at location 0.
    Because my system has no writeable RAM at 0 it can't download the program.
    So I change that line
    03400002xxxxxxx
    which means load the jump instruction at the first read/witeable location.
    Everithing is in the correct address att the hex file and I do not change the others so I don't think that I made
    the memory addressing problem.
    What is your oppinion?

    I tried to work with Keil monitor51 but it also has some problem. I put ask to the list but I have no answer yet.
    Can you give me an advice where can I find good and working downloader or simple simulator program.

    Cheer George