How best to do this depends on how fast it changes, and how many characters you have to "throw away" to determine the correct baud rate.
Two methods that come to mind:
#1. Send a string of characters to the PIC (0x80) for example. Have the PIC sit in a loop and wait for the line to go TRUE (probably high, in your case). Then use PULSIN to measure the LOW period. Calculate the baud rate from that. You should have 7 low bits at 9600 (73uSec). Adjust the baud rate accordingly.
#2. Send a known string of 4 or 5 characters. Start with SERIN2 baud rate value about 10% low. Increment until you receive the correct string . Store that value as baudrate #1. Keep incrementing until the checksum no longer matches Store that value as baudrate #2. Take the average of baudrate #1 and baudrate #2 and use that.
Bookmarks