
;receiver code for RLP434A module
$mod51
;
;port 3 pinouts
Ser_RX	equ	p3.0	;Serial RX from RF Module
Ser_TX	equ	p3.1	;Serial TX to Max232
LED 		equ	p3.5	;

count1	equ	11h	;
count		equ	10h	;
;----------------------------------------------------
org	00000h
Reset:
	sjmp	Start			; 
Start:
	MOV   SP,#07h          	; 
	mov	a,#0FFh		; 
	mov	p1,a			;
	mov	p3,a			;
;----------------------------------------------	
Main:	
	lcall	receive		;receive data from RF module
	lcall	transmit		;send it to Uart @ 2400 baud
	sjmp	Main	
;----------------------------------------------
; The serial baud rate is determined by the 
; processor crystal, and
; this constant which is calculated as: 
;(((crystal/baud)/12) -5) / 2
; (((11059200/2400)/12) -5) / 2
BITTIM	equ	189		;2400 Baud (@ 11.0592MHZ)
;----------------------------------------------	
;* "Bit-bang" serial I/O functions for the 8051.
;* Dave Dunfield - May 17, 1994
;----------------------------------------------	
receive:
	JB	SER_RX,$		;Wait for start bit
	MOV	R2,#BITTIM/2	;Wait 1/2 bit-time
	DJNZ	R2,$			;To sample in middle
	JB	SER_RX,receive	;Insure valid
	MOV	R3,#8			;Read 8 bits
receive1:
	MOV	R2,#BITTIM		;Wait full bit-time
	DJNZ	R2,$			;For DATA bit
	MOV	C,SER_RX		;Read bit
	RRC	A			;Shift it into ACC
	DJNZ	R3,receive1		;read 8 bits
      CLR  	C			;
	RET				;go home
;----------------------------------------------	
;Transmit character in A via PC TXD line
transmit:
	CLR	SER_TX	;Drop line for start bit
	MOV	R2,#BITTIM	;Wait full bit-time
	DJNZ	R2,$		;For START bit	
	MOV	R3,#8		;Send 8 bits
OutChar1:
	RRC	A		;Move next bit into carry
	MOV	SER_TX,C	;Write next bit
	MOV	R2,#BITTIM	;Wait full bit-time
	DJNZ	R2,$		;For DATA bit
	DJNZ	R3,OutChar1	;write 8 bits
	SETB	SER_TX	;Set line high
	RRC	A		;Restore ACC contents
	MOV	R2,#BITTIM	;Wait full bit-time
	DJNZ	R2,$		;For STOP bit
	RET			;
;----------------------------------------------
END
