If you have control over the PC application, then have it ping the data logger (sending an occasional byte) until the logger responds.
On the PIC side, simply test RCIF on occasion to determine if the PC has been connected, the ping byte has been received, and the RCREG holds something.
The USART can handle all this in the background, and your main code can do whatever until the PC is connected.
Code:Y VAR byte ' Inbound data recovered from RCREG RCIF VAR PIR1.5 ' USART received character interrupt flag bit CREN VAR RCSTA.4 ' USART continuous receive enable bit OERR VAR RCSTA.1 ' USART over-run bit INTCON = 0 ' Disable interrupts (just using flags) ADCON1 = 7 ' A/D off TRISB.0 = 0 ' Set RB0 to output PORTB.0 = 0 ' LED off (indicates data was in RCREG) Main: IF RCIF THEN Have_Data ' If RCIF=1 there's data in RCREG HIGH 1 ' so jump to Have_Data and send your EEPROM PAUSE 1000 ' contents LOW 1 PAUSE 1000 ' Long pauses show how RCREG receives data GOTO Main ' in the background Have_Data: ' Send your EEPROM data here PORTB.0 = PORTB.0 ^ 1 ' Toggle RB0 to indicate data rcvd WHILE RCIF ' Empty RCREG by reading it Y = RCREG WEND ' If OERR = 1 then the over-run bit is set and we need to clear it ' to re-enable receive. If not, then carry on IF !OERR THEN Main ' If no over-run condition, return to Main CREN = 0 ' Over-run condition. Disable receive CREN = 1 ' Re-enable & clear OERR flag GOTO Main




Bookmarks