Mike Harrison says:
While we're on the subject of neat little routines etc...This code sends a byte at 115.2Kbaud
With a 4.096MHZ xtal, error is about 1.25% (near enough),
with 4.000MHz, 4.55% (marginal).Data is non-inverted (i.e can be fed straight to PC)
txbyte movwf temp movlw d'10' ; 1 start + 8 data + 1 stop movwf cnt bcf status,c ;start bit movf portb,w txloop andlw 0ff-(1<<seroutbit) skpc iorlw 1<<seroutbit movwf portb sec rrf temp ; carry shifted in as stop bit decfsz cnt goto txloop returnIncidentally It's also possible to do 115K2 bit-bashed reception at 4.096MHz, by generating an INT interrupt off the startbit edge, and grabbbing all the data bits within the int code. Context save/restore overheads mean there's only a couple of cycles available to the foreground task if data is streaming in continuously!