;=================================================================
; SOFTWARE USART ROUTINE FOR 9600 BAUD
; tested, using MPLAB SIM, at 03/10/201 to be 3.626mS for all 4-bytes
;=================================================================
RXD_RS232:
; we neeed to receive 4-bytes at FSR0 = 0x0020 -> 0x0023
lfsr 0,0x0020
movlw .4
movwf ByteCounter
ReceiveNextByte:
movlw .8
movwf CounterA ; 8-data bits
ReceiveWait:
movf SoftRS232Port,w ; CHECK FOR A START BIT (LOW)
btfsc RXD2 ; currently PORTA:0
bra $-4 ; -//-
call Delay052 ; wait until centre of start bit
; we should be at the centre of the start bit by now
ReceiveBit:
bcf STATUS,C
rrcf RCVREG,F
movf SoftRS232Port,w
btfsc RXD2
bsf RCVREG,7
call Delay104 ; ONE PERIOD = 104uS
decfsz CounterA,F
bra ReceiveBit
movf RCVREG,w
decfsz ByteCounter,F
bra RXD_RS232_Next
return ; data now at 0x0020 -> 0x0023
RXD_RS232_Next:
; save incoming byte in RAM at 0x0020 -> 0x0023
movff WREG,POSTINC0
bra ReceiveNextByte
;====================================================================
; Originally coded for 10MHz, recoded for 14.7456MHz (0.27uS/instruction)
; DELAY ROUTINES 9600 BAUD HAS:
; 104uSEC PERIOD (1/9600)
; HALF PERIOD IS 52uSEC (to centre of start bit)
; 1.25 PERIOD IS 130uSEC
;====================================================================
Delay104: movlw .94 ; was 0x3E = .62
movwf DelayCounter ;ADJUST FOR 9600 HZ
D104: NOP
DECFSZ DelayCounter,F
GOTO D104
NOP
NOP
RETURN
Delay052:
movlw .62 ; was 0x27 = .39
movwf DelayCounter
D052: DECFSZ DelayCounter,F
GOTO D052
NOP
NOP
RETURN