;Serial routines
Xmit_Byte Equ 0x20 ;holds byte to xmit
Rcv_Byte Equ 0x21 ;holds received byte
Bit_Cntr Equ 0x22 ;bit counter for RS232
Delay_Count Equ 0x23 ;delay loop counter
SER_INIT
BSF STATUS, RP0 ;select bank 1
BCF TRISB, 5 ;set B5 as an output
;BSF TRISB, 7 ;set B7 as an input
BCF STATUS, RP0 ;select bank 0
BSF PORTB, 5 ;set B5 high
RETURN
XMIT_RS232 MOVWF Xmit_Byte ;move W to Xmit_Byte
MOVLW 0x08 ;set 8 bits out
MOVWF Bit_Cntr
BCF PORTB, 5
CALL Bit_Delay
Ser_Loop RRF Xmit_Byte , f ;send one bit
BTFSS STATUS , C
BCF PORTB, 5
BTFSC STATUS , C
BSF PORTB, 5
CALL Bit_Delay
DECFSZ Bit_Cntr , f ;test if all done
GOTO Ser_Loop
BSF PORTB, 5
CALL Bit_Delay
RETURN
;Rcv_RS232 BTFSC PORTB, 7 ;wait for start bit
; GOTO Rcv_RS232
; CALL Start_Delay ;do half bit time delay
; BTFSC PORTB, 7 ;check still in start bit
; GOTO Rcv_RS232
; MOVLW 0x08 ;set up to read 8 bits
; MOVWF Bit_Cntr
; CLRF Rcv_Byte
;Next_RcvBit CALL Bit_Delay
; BTFSS PORTB, 7
; BCF STATUS , C
; BTFSC PORTB, 7
; BSF STATUS , C
; RRF Rcv_Byte , f
; DECFSZ Bit_Cntr , f ;test if all done
; GOTO Next_RcvBit
; CALL Bit_Delay
; MOVF Rcv_Byte, W
; RETURN
Start_Delay MOVLW 0x0C
MOVWF Delay_Count
Start_Wait NOP
DECFSZ Delay_Count , f
GOTO Start_Wait
RETURN
Bit_Delay MOVLW 0x18
MOVWF Delay_Count
Bit_Wait NOP
DECFSZ Delay_Count , f
GOTO Bit_Wait
RETURN