??? 09/27/09 02:50 Read: times |
#169187 - Re: pseudo code Responding to: ???'s previous message |
Hi Erik. I know it's too much to ask you again to write pieces of codes from the charts you have suggested. But it's great help if you can do for me.
I have tried some of these, but could not get it works. May be I did make it over complicated: RECEIVE: char Com_getchar (void) { if (Com_rbuflen () == 0) //If the receive buffer is empty, return an error value. return (-1); else if (Com_rbuflen () >= RBUF_SIZE) //If the receive buffer is overflow, return an error value. { r_in = 0; r_out = 0; //Reset and clear the receive buffer return (-1); } //Return the byte pointed by r_out in rbuf, then update the pointer r_out return (rbuf [(r_out++) & (RBUF_SIZE - 1)]); } Thanks, Ralf TRANSMIT: //Note: There should be a short delay after a packet transmission to avoid the transmit buffer overflow // The short delay should be inserted after the buffer is close to be full char Com_putchar(unsigned char c) //For use with the serial interrupt enabled, i.e., ES = 1; { //If the buffer is full, return an error value. if (Com_tbuflen () >= TBUF_SIZE) return (-1); //Add the data to the transmit buffer. If the transmit interrupt is disabled, then enable it. tbuf [t_in & (TBUF_SIZE - 1)] = c; t_in++; return (0); } unsigned char Com_tbuflen (void) { if (t_in - t_out >= 0) return (t_in - t_out); else return (t_in - t_out + 256); } |