oPossum 1,083 Posted May 28, 2011 Share Posted May 28, 2011 Uses software delay loop instead of timer [interrupt] for small code size. Minimum bit duration is 18 clock cycles. One cycle granularity. I think this code is optimal (can not be done with fewer instruction words or cycles). tx_char ; Char to tx in R14 ; R10, R11, R12, R15 trashed mov #65553 - 104, R10 ; Bit duration (18 minimum) mov #0x02, R15 ; Serial output bitmask mov #10, R12 ; 10 bit times (may be reduced to 9 at high bit rates) bic.b R15, &P1OUT ; Start bit or #0xFF00, R14 ; Stop bit(s) nop ; bit_loop mov R10, R11 ; Get bit duration bit_time nop ; 4 cycle loop add #4, R11 ; jnc bit_time ; rla R11 ; 0 to 3 cycle delay add R11, PC ; nop ; nop ; nop ; rrc R14 ; Get bit to tx jc bit_high ; If high... bic.b R15, &P1OUT ; Send zero bit dec R12 ; Dec bit count jmp bit_loop ; Next bit... bit_high bis.b R15, &P1OUT ; Send one bit dec R12 ; Dec bit count jnz bit_loop ; Next bit... ret ; Return when all bits sent babu and SirZusa 2 Quote Link to post Share on other sites
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.