Microchip Technology DV164139 Data Sheet

Page of 54
Low Pin Count USB Development Kit User’s Guide
DS41356B-page 36
© 2009 Microchip Technology Inc.
EXAMPLE 2-11: 
 RS-232 BUFFER CHECK
11. Next, the code that will check and then load the EUSART Transmit shift register 
(TXREG) with the contents of the RS-232 buffer will be entered. Copy and paste 
the contents of Example 2-12 into the section labeled:
/*******************************************************
ADD THE CODE THAT WILL CHECK 
IF THE EUSART TXREG IS EMPTY.
IF SO, BEGIN SENDING DATA 
FROM RS232 TRANSMISSION INTO
THE TXREG ONE BYTE AT A TIME
*******************************************************/
EXAMPLE 2-12: 
TXREG CHECK AND LOAD CODE
12. Finally, the code to check if the CDC class device is ready to send data into the 
USB transmit buffer will be entered. Copy and paste the contents of code in 
Example 2-13 into the section labeled:
/**********************************************************
ADD THE CODE THAT WILL CHECK 
IF THE CDC CLASS DEVICE IS 
READY TO LOAD THE USB BUFFER
*********************************************************/
// only check for new USB buffer if the old RS232 buffer is
// empty.
// Additional USB packets will be NAK'd
// until the buffer is free.  
if (RS232_Out_Data_Rdy == 0)  
{
LastRS232Out = getsUSBUSART(RS232_Out_Data,64); 
if(LastRS232Out > 0)
{
RS232_Out_Data_Rdy = 1;  // signal 
//buffer full
RS232cp = 0;// Reset the current position
}
}
if(RS232_Out_Data_Rdy && mTxRdyUSART())
{
putcUSART(RS232_Out_Data[RS232cp]);
++RS232cp;
if (RS232cp == LastRS232Out)
RS232_Out_Data_Rdy = 0;
}