Here's the code I use in my dev cart to do 57.6kbps software-based serial through a MAX232 connected to the second controller port:
; write a to 57.6kbps serial; modified: p, atemp: equ $10serial_write: sta temp sec ; stop bit = 1 dc.b $A9 ; lda #$18 start bit = 0 ; 31 cycles/iterwrite_loop: clc ; 2 sta $4016 ; 4 lda temp ; 3 pha ; 3 pla ; 4 pha ; 3 pla ; 4 ror temp ; 5 bne write_loop ; 3 bcs write_loop rts; wait for and read byte from 57.6kbps serial into a; modified: p, aserial_read: lda #$01 ; 2wait_start: bit $4017 ; 4 beq wait_start ; 3 lda #$80 ; 2 8 iterations sta temp ; 3 ; 30 cycles/iterread_loop: lda $4017 ; 4 lsr a ; 2 ror temp ; 5 pha ; 3 pla ; 4 pha ; 3 pla ; 4 nop ; 2 bcc read_loop ; 3 ; -1 nop ; 2 last bit lda $4017 ; 4 lsr a ; 2 lda temp ; 3 ror a ; 2 eor #$FF ; 3 ; max 30 cycles until next read rts