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); } } } } } } }
The ring buffer is ,256 bytes for transmitting while 256 bytes for receiving,and others to variables.I try changing getchar() to _getkey(),after first transmitting (prefix+234bytes),pc could receive some of prefix('@','cCmd') and 234bytes' message ,and the second time just received 6 bytes' prefix('AA','55','@','cCmd','cCmdComplex','cCmdLen');the thirst time's just like the first's,and the fourth's likes the second's ,such revolve.But everytime just transmit the same thing ,prefix + 234 bytes' message. I long for that you teach me how to resolve data in the ring buffer like these. Thank you very much. Best regards, Nantiangumo.
Now,I found that the main_loop would stop excuting when program runing in _getkey() while UART hadn't income data, in others words,the program would poll RI untill the data coming . If i want communicating with ISR_driven and running others program when serial has no incoming data,how can i do? Thanks a lot!
"the main_loop would stop excuting when program runing in _getkey() while UART hadn't income data" That's the way the SIO example works - it's just doing what it says on the tin! If this is not the behaviour you require, you will have to change it to your requirements. Me, I created a rx_available() function to check if any received character(s) are available, then I call getchar() only if there's something to get. "the program would poll RI untill the data coming " Not if you're doing interrupt-driven serial IO! If your program really is doing this, it might explain your problem... "If i want communicating with ISR_driven and running others program when serial has no incoming data,how can i do?" See above.
"it's just doing what it says on the tin!" See: http://www.keil.com/support/man/docs/c51/c51__getkey.htm Which is consistent with Keil's other products: http://www.keil.com/support/man/docs/ca/ca__getkey.htm http://www.keil.com/support/man/docs/c166/c166__getkey.htm
Well, the _getkey routine is included in the main.c file as follows:
/*------------------------------------------------------------------------------ _getkey waits until a character is received from the serial port. This may not be the exact desired operation (for example if the buffer is empty, this function hangs waiting for a character to be received). ------------------------------------------------------------------------------*/ char _getkey (void) { int k; do { k = com_getchar (); } while (k == -1); return ((unsigned char) k); }