We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am testing simple 8051 program that polls for a character from serial port and output it out to the serial port again. In the main function, I do the following continously
u8_t xdata c; while(slipdev_char_poll(&c)) { slipdev_char_put(c); break; }
void slipdev_char_put(u8_t chr){ int delaycount; putchar(chr); for (delaycount=0;delaycount<1000;delaycount++){} return; } u8_t slipdev_char_poll(u8_t xdata *chr){ if (RI==1){ //Character is available *chr = SBUF; RI = 0; return 1; }else{ //Character not available return 0; } }
u8_t xdata c; while(slipdev_char_poll(&c)) { putchar(c); break; }
Why is there a break in the main while loop? It will only execute once. Might as well have an 'if' statement. Your delay loop could easily be optimized away by the compiler, especially as it has no side effects and changes only a local variable. See past threads for various ways to implement a delay.