Serial communication with 8051

Thread Starter

PY01A0080

Joined Mar 7, 2013
42
Hi,
i try to connect two 8051.
When Led at P1.0 glows in the transmitter 8051, then the Led at port 2 must glow too.

The problem is when i run the code, all port in the two 8051 are high.
I changed the code for transmitting letter from 8051 to lcd display.

so my code is here:

Transmission code in the first 8051:
Rich (BB code):
 org 0000h 
mov tmod,#29h; Mode1=1 Timer0=1
mov th1,#0fdh; th1 value for 9600
mov scon,#50h; SM1=1 and RET=1
setb tr1; start of the timer1


loop:mov p0,#01h; make p1 as input port
mov a,p1
acall send
sjmp loop

send:
mov sbuf,a
Here:jnb ti,here
clr ti
ret

delay:mov r0,#10h
l1: mov th0,#76
mov tl0,#01h
setb tr0
jnb tf0,$
clr tf0
djnz r0,l1
ret
end
Reception code in the second 8051:
Rich (BB code):
 org 0000h 									 
 mov tmod,#20h			  ;Timer 1 in Auto Reload mode
 mov th1,#0fdh			  ; Set serial baud rate
 mov scon,#50h			  ; Serial comm with 8bit variable baud rate and Reception enable
 setb tr1
 mov a,sbuf
 mov p2,a
 clr Ri
 reti
 end
any help is welcome
Thank you
PY01A0080
 

MrChips

Joined Oct 2, 2009
30,806
You have some serious problems in the receiver code.

reti means return from interrupt.
You have not initialized the code to handle interrupts.

Your program does not end properly.
 

absf

Joined Dec 29, 2010
1,968
Your transmission code also puzzled me...

How does putting '01h' onto 'P0' makes 'P1' an input port?

What is the purpose of 'delay' subroutine defined in the code but it was not called?
 

Thread Starter

PY01A0080

Joined Mar 7, 2013
42
For 01h i replaced by 0FFh
Rich (BB code):
loop:mov p0,#0FFh
For delay, i just wanted to put after loop
loop:mov p0,#01h; make p1 as input port
Rich (BB code):
mov a,p1
acall send
sjmp loop
acall delay
for reti, i just take this from an example but i don't know yet very well the interrupt.
thank your
 

Thread Starter

PY01A0080

Joined Mar 7, 2013
42
Hi absf,

i worked out my problem and i fixed it.
here the new code

Rich (BB code):
 org 0000h 
mov tmod,#29h; Mode1=1 Timer0=1
mov th1,#0fdh; th1 value for 9600
mov scon,#50h; SM1=1 and REN=1
setb tr1; start of the timer1


loop:
mov p1,#01h
mov a,p1
acall send
;acall delay

Loop2: rl a
mov p1,a
lcall send
lcall delay
jnb p1.7,Loop2
sjmp loop 

send:
mov sbuf,a
Here:jnb ti,Here
clr ti
acall delay
ret


delay:mov r0,#10h
l1: mov th0,#76
mov tl0,#01h
setb tr0
jnb tf0,$
clr tf0
djnz r0,l1
ret
end

Rich (BB code):
org 0000h 									 
 mov tmod,#20h			 
 mov th1,#0fdh			  
 mov scon,#50h			  
 setb tr1

 
 H:jnb ri,H

 mov a,sbuf
 mov p2,a
 clr ri
 sjmp H
 end
and it's working now
i made other mistake in the proteus, i just reversed the two microprocessors

Thank you
 
Top