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

I can't get familiar with PUTCHAR and PUTS

I've got a problem. I've posted it yesterday but it was probably lost in text.

static void Nastav_seriovy_kanal (void)
{
	SCON = 0x50;
	TMOD = TMOD | 0x20;
	TH1 = 0xF4;
	TL1 = 0xF4;
	ES = 1;
	TR1 = 1;
}

static void Preruseni_seriovy_kanal (void) interrupt 4
{
	if (RI == 1)
	{
	    RI = 0;
	    if(SBUF == 'A') putchar('Q');
	}
	if (TI == 1) TI = 0;
}
I'm also including stdio.h, and string.h(string.h is not necessary).

Does anyone have any idea why it doesn't work?

Parents Reply Children
  • It is a very bad idea to try to use these in an interrupt service routine!

    Well ... yeah.

    You can use them in an ISR, as long as you're aware that they are going to hog CPU cycles like crazy (they spinlock if the serial transmitter is busy) and that they're not reentrant.

    Also, I think there's some code putchar.c that could drop characters or enter an endless loop under certain rare circumstances. Something along the lines of

    do
    {
      RI = 0;
      while(!RI);
    } while(SBUF != XON)
    

    With some bad luck, RI goes to 1 at the beginning if the do loop, gets overwritten by a 0, and the while loop will run until the next character has been received.

    Certainly, the chances for this are minimal, but I don't see anything that would prevent the behavior.