RS232 routine for 14-bit PIC cores. TX only, fixed 115200 bps, 3.6864MHz XTAL, no parity.



Note : Tested only in a PIC6F628A. Free for personal use. If you use
it, please mention my name, or at least where you found this.



;TX_115k2
;C. Blondin (Fenugrec), 16/12/2006
;
;sends the byte in W through RB6,
;but it should work with any pin & any port
;(you can change the relevant bitmasks)
;uses a shadow reg, assumes no interrupts during execution.
;also needs two GPRs : count and TXbyte.
;STATUS is modified.

;1 bit @ 115200bps gives 8.68 us / bit;
;1 TCy @ 3.6864 MHz gives 1.085 us;
;total of 8 instructions / bit for the sending
;loop.

TX_115k2
    movwf   TXbyte
    bcf     STATUS,C    ;prepare startbit
    movlw   09          ;startbit + 8 bits
    movwf   count
    movf    sPORTB,W
_TX_shiftloop
    andlw   b'10111111' ;RB6 = 0    ;1
    btfsc   STATUS,C                ;1
    iorlw   b'01000000' ;else 1     ;1
    movwf   PORTB                   ;1	X
    rrf	    TXbyte,F    ;LSb first  ;1
    decfsz  count,F                 ;1
    goto    _TX_shiftloop           ;2

    iorlw   b'01000000'             ;1
    movwf   sPORTB                  ;1
    goto    $+1  ;lastbit = 8TCy    ;2
    movwf   PORTB    ;set RB6 high  ;1  _/
    return