dak246
Member
I just want to get some opinions on whether or not this code will work for rs-232 communication (at 9600bps) to a PC. ( PIC external ocillator 20mhz )
The delay loop should delay for about 102.2uS, and after compensation for the time it takes to perform the diffrent number of instructions between bits it should come out to a delay in the range of 103.4uS-104.4uS. Will this range still allow it to work properly at 9600bps? Is there anything im missing or any ways I could optimize this? Thanks.
Code:
SendData
bcf PORTA,0 ;Send start bit
movwf TX_DATA
movlw 0x08
movwf BIT_CTR ;Set bit counter to 8
DataLoop
call Delay
btfss TX_DATA,0
bcf PORTA,0 ;Send a 0 bit
btfsc TX_DATA,0
bsf PORTA,0 ;Send a 1 bit
rrf TX_DATA,1
decfsz BIT_CTR,1 ;Decrement bit counter
goto DataLoop
call Delay
bsf PORTA,0 ;Send stop bit
return
;Should delay either 102.4uS or 102.2uS
Delay
movlw 0xA9
movwf COUNTER
Loop
decfsz COUNTER,1
goto Loop
return
The delay loop should delay for about 102.2uS, and after compensation for the time it takes to perform the diffrent number of instructions between bits it should come out to a delay in the range of 103.4uS-104.4uS. Will this range still allow it to work properly at 9600bps? Is there anything im missing or any ways I could optimize this? Thanks.