
_R485_Set:

;RS485_E.mbas,18 :: 		sub procedure R485_Set
;RS485_E.mbas,19 :: 		rts = 0    'set to receive (default)
	BCF        RC0_bit+0, 0
;RS485_E.mbas,20 :: 		rtz = 0
	BCF        TRISC0_bit+0, 0
;RS485_E.mbas,21 :: 		end sub
L_end_R485_Set:
	RETURN
; end of _R485_Set

_Uart_Begin:

;RS485_E.mbas,23 :: 		sub procedure  Uart_Begin()
;RS485_E.mbas,24 :: 		Uart1_init(9600)        'Set baudrate here
	BSF        BAUDCON+0, 3
	MOVLW      207
	MOVWF      SPBRG+0
	CLRF       SPBRG+1
	BSF        TXSTA+0, 2
	CALL       _UART1_Init+0
;RS485_E.mbas,26 :: 		R485_Set          'allows half duplex mode with portC.0 as switch pin
	CALL       _R485_Set+0
;RS485_E.mbas,28 :: 		end sub
L_end_Uart_Begin:
	RETURN
; end of _Uart_Begin

_uw:

;RS485_E.mbas,30 :: 		Sub procedure uw(dim in as char)   'Writes single character via RS485 half duplex
;RS485_E.mbas,32 :: 		rts = 1               'portc.5 = 1
	BSF        RC0_bit+0, 0
;RS485_E.mbas,34 :: 		uart1_write(in)
	MOVF       FARG_uw_in+0, 0
	MOVWF      FARG_UART1_Write_data_+0
	CALL       _UART1_Write+0
;RS485_E.mbas,36 :: 		do
L__uw3:
;RS485_E.mbas,37 :: 		loop until TXSTA.TRMT = 1 'wait for tx reg empty before switching port
	BTFSS      TXSTA+0, 1
	GOTO       L__uw3
;RS485_E.mbas,38 :: 		rts = 0                    'portc.5 = 0
	BCF        RC0_bit+0, 0
;RS485_E.mbas,40 :: 		end sub
L_end_uw:
	RETURN
; end of _uw
