Hi,All
This is a software serial's Technical data.
(Theorem of PIC) 1bit(Cycle) = (xtal/4)/baud
(In My Routine:Forward references) 1bit(Send)= 8n+16 (Cycle) 1bit(Recieve) = 8n+14 (Cycle)
n is a constant used in bwait2 routine.
(Example 1) xtal=8000000 baud=9600
1bit(Cycle) = (8000000/4)/9600 = 208.33
208.33 = 8*n+15 n = (208.33-15)/8 = 24.16
(Example 2) xtal=16000000 baud=9600
1bit(Cycle) = (16000000/4)/9600 = 416.66
416.66 = 8*n+15 n = (416.66-15)/8 = 50.20
(My Routine) ; *********** ; ; RS-232C Send 1byte ; ; Set W and Call (Return:W=0x09,Carry=1,Zero=1) ; ; ***********
movwf rxd movlw .10 movwf cn bcf STATUS,C btfsc STATUS,C ;; 1 bsf GPIO,TX ;; 1 btfss STATUS,C ;; 1 bcf GPIO,TX ;; 1 call bwait ;; 2+(8*n+6) = 8*n+8 rrf rxd,f ;; 1 decfsz cn,f ;; 1 goto $-7 ;; 2 total:1+1+1+1+8*n+8+1+1+2 = 8*n+16 (Cycle)
bwait: call bwait2 ;2 total:2+(4n+2)+(4n+2) = 8n+6 (Cycle) bwait2: movlw .256-n ;1 addlw 0x01 ;1 btfss STATUS,Z ;1 goto $-2 ;2 retlw 0x09 ;2 total:1+(1+1+2)n-1+2 = 4*n+2 (Cycle)
; *********** ; ; RS-232C Recieve 1byte (Return in W) ; ; ***********
btfsc GPIO,RX goto $-1 call bwait2 movwf cn rrf rxd,f ;; 1 call bwait ;; 2+(8*n+6) = 8*n+8 btfss GPIO,RX ;; 1 bcf STATUS,C ;; 1 decfsz cn,f ;; 1 goto $-5 ;; 2 total:1+8*n+8+1+1+1+2 = 8*n+14 (Cycle) movf rxd,w return
This is case AVR.
(Theorem of AVR)
1bit(Cycle) = xtal/baud
(In My Routine:Forward references) 1bit(Send)= 6n+23 (Cycle) 1bit(Recieve) = 6n+21 (Cycle)
1bit(Cycle) = 8000000/9600 = 833.33 833.33 = 6*n+22
n = (833.33-22)/6 = 135.16
(Example 2) xtal=9600000 baud=9600
1bit(Cycle) = 9600000/9600 = 1000 1000 = 6*n+22 n = (1000-22)/6 = 163
(My Routine) ; *********** ; ; RS-232C Send 1byte ; ; ***********
LDI cn,1+8+1 COM rxd RJMP PC+5 LSR rxd ;; 1 brcs PC+2 ;; 1 sbi PORTB,TX ;; 2.or.1 brcc PC+2 ;; 1 cbi PORTB,TX ;; 1.or.2 rcall bwait ;; 3+6*n+11 = 6*n+14 dec cn ;; 1 brne PC-7 ;; 2 Total:1+1+2+1+1+6*n+14+1+2 = 6*n+23 (Cycle) ret
; *********** ; ; RS-232C Recieve 1byte ; ; ***********
SBIC PINB,RX RJMP PC-1 LDI rxd,0x80 RCALL bwait2 RCALL bwait ;; 3+6*n+11 = 6*n+14 SBIC PINB,RX ;; 3.or.2 SEC ;; 1 ROR rxd ;; 1 BRCC PC-4 ;; 2 Total:6*n+14+3+1+1+2 = 6*n+21 (Cycle)
bwait: rcall bwait2 ;3+(3n+4)+(3n+4) = 6n+11 bwait2 ldi rs,n ;1 subi rs,1 ;1 brne PC-1 ;2/1 ret ;4 1+(1+2)n-1+4 = 3*n+4
Log in to post a comment.
Hi,All
This is a software serial's Technical data.
(Theorem of PIC)
1bit(Cycle) = (xtal/4)/baud
(In My Routine:Forward references)
1bit(Send)= 8n+16 (Cycle)
1bit(Recieve) = 8n+14 (Cycle)
n is a constant used in bwait2 routine.
(Example 1)
xtal=8000000
baud=9600
1bit(Cycle) = (8000000/4)/9600 = 208.33
208.33 = 8*n+15
n = (208.33-15)/8 = 24.16
(Example 2)
xtal=16000000
baud=9600
1bit(Cycle) = (16000000/4)/9600 = 416.66
416.66 = 8*n+15
n = (416.66-15)/8 = 50.20
(My Routine)
; ***********
;
; RS-232C Send 1byte
;
; Set W and Call (Return:W=0x09,Carry=1,Zero=1)
;
; ***********
bwait: call bwait2 ;2 total:2+(4n+2)+(4n+2) = 8n+6 (Cycle)
bwait2: movlw .256-n ;1
addlw 0x01 ;1
btfss STATUS,Z ;1
goto $-2 ;2
retlw 0x09 ;2 total:1+(1+1+2)n-1+2 = 4*n+2 (Cycle)
; ***********
;
; RS-232C Recieve 1byte (Return in W)
;
; ***********
This is case AVR.
(Theorem of AVR)
1bit(Cycle) = xtal/baud
(In My Routine:Forward references)
1bit(Send)= 6n+23 (Cycle)
1bit(Recieve) = 6n+21 (Cycle)
n is a constant used in bwait2 routine.
(Example 1)
xtal=8000000
baud=9600
1bit(Cycle) = 8000000/9600 = 833.33
833.33 = 6*n+22
n = (833.33-22)/6 = 135.16
(Example 2)
xtal=9600000
baud=9600
1bit(Cycle) = 9600000/9600 = 1000
1000 = 6*n+22
n = (1000-22)/6 = 163
(My Routine)
; ***********
;
; RS-232C Send 1byte
;
; ***********
; ***********
;
; RS-232C Recieve 1byte
;
; ***********
bwait: rcall bwait2 ;3+(3n+4)+(3n+4) = 6n+11
bwait2 ldi rs,n ;1
subi rs,1 ;1
brne PC-1 ;2/1
ret ;4 1+(1+2)n-1+4 = 3*n+4