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
  • 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?


Reply
  • 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?


Children
  • 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