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

Why Hanging ???

Regards all,

This codes generates a hang on cpu .
Please kindly take this & guid me :

#include <w78e65.H>
#include <stdio.h>
main()
{
unsigned char i;
TMOD=0x20;
SCON=0x52;
TH1=0xfa;
TR1=1;
for(i=0;i<=255;i++)
{
printf("%bd",i);
P2=i;
}
}
/**************************************/

Parents
  • Stefan,

    I guess I had always imagined that it handled things via interrupt and a circular buffer or something of the like. In retrospect, I'm not sure how it would have been able to install an ISR via just including stdio.h. :)

    As far as living without it. I dunno. I've yet to design a product that didn't require my actually using the serial communications channel, so I'd typically just hook into the routines that I wrote, or find some other way to get debug data out.

    You'd be amazed what you can do with just a few spare pins tied to some inverters. :)

Reply
  • Stefan,

    I guess I had always imagined that it handled things via interrupt and a circular buffer or something of the like. In retrospect, I'm not sure how it would have been able to install an ISR via just including stdio.h. :)

    As far as living without it. I dunno. I've yet to design a product that didn't require my actually using the serial communications channel, so I'd typically just hook into the routines that I wrote, or find some other way to get debug data out.

    You'd be amazed what you can do with just a few spare pins tied to some inverters. :)

Children
  • printf()'s job is to format the data ready for output, the actual output is done by putchar() which is called by printf() once for each character. The default putchar() just does polled output via the UART - you can replace it with a function to send the output anywhere you like, eg an LCD. This makes things really flexible. If you wanted printf() to return to the caller before the data has all been transmitted you would need to implement your own buffer and replace putchar() with a function that stuffs a char into that buffer.

    One thing to be aware of is that the default putchar() translates 0x0a into 0x0d 0x0a sequences and also implements XON/XOFF which can throw up a few surprises if you're not expecting it.

    Naturally my code always works first time, but if I ever needed to debug something I'm sure I would use printf() a lot...