Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interfacing RSW-434 TSW-434 With 8051

Status
Not open for further replies.
Re: 8051 rf transmitter code

AOA. I am making a same project but in C language and i am sending a ASCII from 8051 (8051 to tlp-434) and at receiver side rlp-434 receives the data and send it to another 8051 and 8051 shows its on port0...... but there is some noise so that port0 not show the correct one can anyone tell how to filter the receiving data using c program.....?
 

Re: 8051 rf transmitter code

quickly looking at the schematic, I saw that you need to tie EA (Pin31 on the microcontroller) to VCC on both receiver and transmitter.

The reset circuit should have a 10uF capacitor and an 8.2K resistor. I could not tell the values from your schematic.

The capacitor values for the crystal should be 33pF (or less) not 33uF.

You should read this:
https://www.sparkfun.com/datasheets/RF/KLP_Walkthrough.pdf

To test whether or not your serial routines are working, have the transmitter send data to the PC use the attached terminal program. You will need a maxim 232 driver in your circuit connected to the TX and RX lines of the microcontroller.

here is a small routine you can use:
Code:
;*********************************************
;UART Test code
$mod51
;this one uses UART hardware to TX @2400 Baud
;timing is adapted for 11.0592 MHz crystal
;****************************************************
org	00000h
Reset:
	sjmp	Start			;reset vector
Start:
	MOV   SP,#70h           ; Start stack near top of '51 RAM. 
	mov	a,#0FFh		; clear Ports
	mov	p1,a			;
	mov	p3,a			;

;------Initialize Uart------------
	MOV SCON,#01010000B 	;(50H) Mode 1/Rec en
					; bit 4 = REN receive enable				
					; bit 6 = mode 1. -  8 bit uart variable baud rate
;;	MOV TH1,#0E8H 		; Reload value for 1200 Bd @11.0592 MHz
	MOV TH1,#0F4H 		; Reload value for 2400 Bd @11.0592 MHz
;;	MOV TH1,#0FAH 		; Reload value for 4800 Bd @11.0592 MHz
	MOV TMOD,#00100000B	; (21H) Gate1/Timer/Mode 2 / Gate0/Timer/Mode 1
					; bit 5 = 8 bit auto reload for timer 1 (Mode2)
	setb	TR1			; start timer 1	
;----------------------------------------------	
Main:  	
	clr	a
Main1:
	lcall	transmit
	inc	acc
	acall	Time1mS
	sjmp	Main1
;----------------------------------------------	
Time1mS:
	MOV   R2,#2
      MOV   R1,#221
tim1mS:
	DJNZ  R1,$
      DJNZ  R2,tim1mS
      RET
;----------------------------------------------
transmit:
	MOV SBUF,A
	JNB TI,$
	CLR TI
	ret
;----------------------------------------------
end

use the attached terminal program and set the input to hex (not ascii)
connect at 2400 baud and you will see it works.

then you can test the receiving code. All you have to do is type in a character in the terminal and press send, this code will return the value you sent back to the terminal.

Code:
;*********************************************
;UART Test receiver code
$mod51
;this one uses hardware uart to receive @2400 Baud
;timing is adapted for 11.0592 MHz clock
;
;port 3 pinouts
;----------------------------------------------------
org	00000h
Reset:
	sjmp	Start			; reset vector
Start:
	MOV   SP,#070h          ; Set up stack pointer
	mov	a,#0FFh		; clear Ports
	mov	p1,a			;
	mov	p3,a			;
;------Initialize Uart------------
	MOV SCON,#01010000B 	;(50H) Mode 1/Rec en
					; bit 4 = REN receive enable				
					; bit 6 = mode 1. -  8 bit uart variable baud rate
;;	MOV TH1,#0E8H 		; Reload value for 1200 Bd @11.0592 MHz
	MOV TH1,#0F4H 		; Reload value for 2400 Bd @11.0592 MHz
;;	MOV TH1,#0FAH 		; Reload value for 4800 Bd @11.0592 MHz
	MOV TMOD,#00100000B	; (21H) Gate1/Timer/Mode 2 / Gate0/Timer/Mode 1
					; bit 5 = 8 bit auto reload for timer 1 (Mode2)
	setb	TR1			; start timer 1	
;----------------------------------------------	
Main:
	lcall	receive		;receive data from terminal	
	lcall	transmit		;echo it back to terminal
	sjmp	Main
;----------------------------------------------	
; Receive a character and return in ACC
receive:
	JNB RI,$		;wait here for receive int
	MOV A,SBUF		;get data
	CLR RI		;clear receive int
	ret
;----------------------------------------------
;Transmit a character from ACC
transmit:
	MOV SBUF,A
	JNB TI,$
	CLR TI
	ret
;----------------------------------------------	
end

If that works, then you know your hardware is perfect. Then just change the TX & RX lines back to the RF modules and test the same code.

Remember the receiver ALWAYS receives data, no matter what it is, noise, etc.

In my code I filtered out the incoming data like this:

Code:
Main1:
	lcall	receive			;receive data from uart
	cjne	a,#099h,Main1	  ;compare received byte with 99h
						;if its different, restart
	mov	08h,a			;save first byte received

;we are here because first received byte compares to 0x99
	lcall	receive			;get second byte
;-------------
	cjne	a,#088h,Main1		;compare received byte with 88h
        mov	09h,a			;save second byte received

;next the program gets two more bytes (total 4 bytes)
;then xor first three bytes together
;then compare last byte with xor value of 3 first bytes
;not the same? go back to Main1
;this way you are SURE that your receiving code won't pick up garbage bytes.
;I mean it always will, but you must ignore the garbage.

Let me know how it goes.

Dear sir,
i have tried as per your suggestions, i have used linear data pin of receiver itself to microcontroller, i am not receiving any data. could you please send me schematic and as well as embedded C-code for 8051. really i want to try with this. pleasee do send it to oyaramana@yahoo.com as well.
please support me

thanks,
ramana
 

Re: 8051 rf transmitter code

quickly looking at the schematic, I saw that you need to tie EA (Pin31 on the microcontroller) to VCC on both receiver and transmitter.

The reset circuit should have a 10uF capacitor and an 8.2K resistor. I could not tell the values from your schematic.

The capacitor values for the crystal should be 33pF (or less) not 33uF.

You should read this:
https://www.sparkfun.com/datasheets/RF/KLP_Walkthrough.pdf

To test whether or not your serial routines are working, have the transmitter send data to the PC use the attached terminal program. You will need a maxim 232 driver in your circuit connected to the TX and RX lines of the microcontroller.

here is a small routine you can use:
Code:
;*********************************************
;UART Test code
$mod51
;this one uses UART hardware to TX @2400 Baud
;timing is adapted for 11.0592 MHz crystal
;****************************************************
org	00000h
Reset:
	sjmp	Start			;reset vector
Start:
	MOV   SP,#70h           ; Start stack near top of '51 RAM. 
	mov	a,#0FFh		; clear Ports
	mov	p1,a			;
	mov	p3,a			;

;------Initialize Uart------------
	MOV SCON,#01010000B 	;(50H) Mode 1/Rec en
					; bit 4 = REN receive enable				
					; bit 6 = mode 1. -  8 bit uart variable baud rate
;;	MOV TH1,#0E8H 		; Reload value for 1200 Bd @11.0592 MHz
	MOV TH1,#0F4H 		; Reload value for 2400 Bd @11.0592 MHz
;;	MOV TH1,#0FAH 		; Reload value for 4800 Bd @11.0592 MHz
	MOV TMOD,#00100000B	; (21H) Gate1/Timer/Mode 2 / Gate0/Timer/Mode 1
					; bit 5 = 8 bit auto reload for timer 1 (Mode2)
	setb	TR1			; start timer 1	
;----------------------------------------------	
Main:  	
	clr	a
Main1:
	lcall	transmit
	inc	acc
	acall	Time1mS
	sjmp	Main1
;----------------------------------------------	
Time1mS:
	MOV   R2,#2
      MOV   R1,#221
tim1mS:
	DJNZ  R1,$
      DJNZ  R2,tim1mS
      RET
;----------------------------------------------
transmit:
	MOV SBUF,A
	JNB TI,$
	CLR TI
	ret
;----------------------------------------------
end

use the attached terminal program and set the input to hex (not ascii)
connect at 2400 baud and you will see it works.

then you can test the receiving code. All you have to do is type in a character in the terminal and press send, this code will return the value you sent back to the terminal.

Code:
;*********************************************
;UART Test receiver code
$mod51
;this one uses hardware uart to receive @2400 Baud
;timing is adapted for 11.0592 MHz clock
;
;port 3 pinouts
;----------------------------------------------------
org	00000h
Reset:
	sjmp	Start			; reset vector
Start:
	MOV   SP,#070h          ; Set up stack pointer
	mov	a,#0FFh		; clear Ports
	mov	p1,a			;
	mov	p3,a			;
;------Initialize Uart------------
	MOV SCON,#01010000B 	;(50H) Mode 1/Rec en
					; bit 4 = REN receive enable				
					; bit 6 = mode 1. -  8 bit uart variable baud rate
;;	MOV TH1,#0E8H 		; Reload value for 1200 Bd @11.0592 MHz
	MOV TH1,#0F4H 		; Reload value for 2400 Bd @11.0592 MHz
;;	MOV TH1,#0FAH 		; Reload value for 4800 Bd @11.0592 MHz
	MOV TMOD,#00100000B	; (21H) Gate1/Timer/Mode 2 / Gate0/Timer/Mode 1
					; bit 5 = 8 bit auto reload for timer 1 (Mode2)
	setb	TR1			; start timer 1	
;----------------------------------------------	
Main:
	lcall	receive		;receive data from terminal	
	lcall	transmit		;echo it back to terminal
	sjmp	Main
;----------------------------------------------	
; Receive a character and return in ACC
receive:
	JNB RI,$		;wait here for receive int
	MOV A,SBUF		;get data
	CLR RI		;clear receive int
	ret
;----------------------------------------------
;Transmit a character from ACC
transmit:
	MOV SBUF,A
	JNB TI,$
	CLR TI
	ret
;----------------------------------------------	
end

If that works, then you know your hardware is perfect. Then just change the TX & RX lines back to the RF modules and test the same code.

Remember the receiver ALWAYS receives data, no matter what it is, noise, etc.

In my code I filtered out the incoming data like this:

Code:
Main1:
	lcall	receive			;receive data from uart
	cjne	a,#099h,Main1	  ;compare received byte with 99h
						;if its different, restart
	mov	08h,a			;save first byte received

;we are here because first received byte compares to 0x99
	lcall	receive			;get second byte
;-------------
	cjne	a,#088h,Main1		;compare received byte with 88h
        mov	09h,a			;save second byte received

;next the program gets two more bytes (total 4 bytes)
;then xor first three bytes together
;then compare last byte with xor value of 3 first bytes
;not the same? go back to Main1
;this way you are SURE that your receiving code won't pick up garbage bytes.
;I mean it always will, but you must ignore the garbage.

Let me know how it goes.


Can you let me know the third and fourth byte to be checked. Or are they the data bytes. I checked random data for 3rd and 4th byte but I'm not able to verify the authenticity of the data recieved.
 

Re: 8051 rf transmitter code

Can you let me know the third and fourth byte to be checked. Or are they the data bytes. I checked random data for 3rd and 4th byte but I'm not able to verify the authenticity of the data recieved.

i don't know what you mean. You can send any packet to the receiver, any length.

No matter what you do, it will never be 100% reliable. You will need some kind of encoding (or an encoder chip is easier).
 

What I mean to say is with reference to the following algorithm posted:

Main1:
lcall receive ;receive data from uart
cjne a,#099h,Main1 ;compare received byte with 99h
;if its different, restart
mov 08h,a ;save first byte received

;we are here because first received byte compares to 0x99
lcall receive ;get second byte
;-------------
cjne a,#088h,Main1 ;compare received byte with 88h
mov 09h,a ;save second byte received

;next the program gets two more bytes (total 4 bytes)
;then xor first three bytes together
;then compare last byte with xor value of 3 first bytes
;not the same? go back to Main1
;this way you are SURE that your receiving code won't pick up garbage bytes.
;I mean it always will, but you must ignore the garbage.




Here in this algorithm, it is stated that the program gets two more bytes (total 4 bytes).
My doubt is what are these bytes?
 

it is stated that the program gets two more bytes (total 4 bytes).
My doubt is what are these bytes?
They are whatever you want them to be. That is, the receiver must match what the transmitter sends.

Look at post # 16. Another guy did the same thing you are trying to do. Read the entire thread on 8052.com before attempting to do this.
Download the code here:
**broken link removed**
 
Last edited:

They are whatever you want them to be. That is, the receiver must match what the transmitter sends.

Look at post # 16. Another guy did the same thing you are trying to do. Read the entire thread on 8052.com before attempting to do this.
Download the code here:
**broken link removed**


Taking an example with reference to the algorithm specified, I find that the xor value of first three bytes do not match the 4th byte. Please help if I'm wrong somewhere:


BYTE 1 99H
1 0 0 1 1 0 0 1

BYTE 2 88H
1 0 0 0 1 0 0 0

BYTE 3 37H
0 0 1 1 0 1 1 1

BYTE 4 B2H
1 0 1 1 0 0 1 0

XOR OF BYTE 1, BYTE 2 & BYTE 3 26H
0 0 1 0 0 1 1 0
 

if you are going by the example code from 8052.com, the fourth byte would be 26h, (not B2h) which would then work correctly.
 

hey cud you plzz tell me if it is necessary to use max232 ic to interface mcu with a tx rx pair...
 

hey cud you plzz tell me if it is necessary to use max232 ic to interface mcu with a tx rx pair...

NO, MAX232 is for RS232 voltage levels. The RF modules usually work with TTL voltages. It really depends on the RF module.

You can (theoretically) connect the mcu directly to the TX/RX pair. Again, it depends on the RF module. You should look at the datasheet of both the MCU and the RF module.

You want to compare input low voltages, input high voltages minimum and maximum for both RF modules and MCU. They must be within range or it won't work (without another IC to adjust levels).

I believe the code mentioned above from the 8052.com website uses an inverter to connect the 89C mcu to the RF module.
 
Last edited:

can anyone give me program...
i am using keypad at transmitter side and lcd at receiver .
if i press 1 on keypad ,it will display on receiver side LCD .
i am using encoder HT12E and decoder HT12D.
i have made program but not working properly .
when i press 1 it saw alpha ,for 2=ohm and wise versa .
i have tested on 4 led module .means when i press 1 first led will glow, for 2 second led will glow, for 3 first and second led will glow ........for 8 forth led will glow.it means hardware is working properly .
what to do can any one help me.can any one write program for me....please help me.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top