I download intsio.zip and only changed some word in main.c as following:
void main (void) { com_initialize (); /* initialize interrupt driven serial I/O */ com_baudrate (38400); /* setup for 38400 baud */ printf ("Interrupt-driver Serial I/O Example\r\n\r\n"); while (1) { unsigned char c,cCmd,cCmdLen,i; c = getchar(); if (c == 0xaa) { c = getchar(); if (c == 0x55) { c = getchar(); if (c == '@') { c = getchar(); cCmd = c; c = getchar(); if ((c+cCmd) == 0xff) { cCmdLen = getchar(); for ( i = 0 ; i < cCmdLen ; i ++) { c = getchar(); printf("%c" ,c); } } } } } } }
Additionally,just doubly transmit and never miss bytes. Thanks.
It seems like you expect getchar() to echo the received character. (If not, the command prefix AA 55 40 etc would not appear.) In the command body, you also echo characters with printf(). (I'd suggest putchar() for less overhead.) This would cause the characters to be echoed of the command body to be output twice, once by getchar and once by printf. Is your serial output buffered, or at least synchronized with a delay loop watching TI? What if printf() writes to the SBUF before the byte written by the getchar() character has finished transmitting? Since both routines are writing the same value, you might see only one appear. I don't understand why the prefix to the command should ever be doubly echoed. You say this is correct, but I wouldn't expect that from the posted code. Only the bytes after the command length should be doubled.
"It seems like you expect getchar() to echo the received character." Yes, that is the documented behaviour of the standard Keil C51 implementation: http://www.keil.com/support/man/docs/c51/c51_getchar.htm