Serial communication with 8051

Discussion in 'Embedded Systems and Microcontrollers' started by PY01A0080, Mar 11, 2013.

  1. PY01A0080

    Thread Starter Member

    Mar 7, 2013
    42
    3
    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:
    Code ( (Unknown Language)):
    1.  org 0000h
    2. mov tmod,#29h; Mode1=1 Timer0=1
    3. mov th1,#0fdh; th1 value for 9600
    4. mov scon,#50h; SM1=1 and RET=1
    5. setb tr1; start of the timer1
    6.  
    7.  
    8. loop:mov p0,#01h; make p1 as input port
    9. mov a,p1
    10. acall send
    11. sjmp loop
    12.  
    13. send:
    14. mov sbuf,a
    15. Here:jnb ti,here
    16. clr ti
    17. ret
    18.  
    19. delay:mov r0,#10h
    20. l1: mov th0,#76
    21. mov tl0,#01h
    22. setb tr0
    23. jnb tf0,$
    24. clr tf0
    25. djnz r0,l1
    26. ret
    27. end
    Reception code in the second 8051:
    Code ( (Unknown Language)):
    1.  org 0000h                                   
    2.  mov tmod,#20h            ;Timer 1 in Auto Reload mode
    3.  mov th1,#0fdh            ; Set serial baud rate
    4.  mov scon,#50h            ; Serial comm with 8bit variable baud rate and Reception enable
    5.  setb tr1
    6.  mov a,sbuf
    7.  mov p2,a
    8.  clr Ri
    9.  reti
    10.  end
    any help is welcome
    Thank you
    PY01A0080
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,361
    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.
     
  3. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    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?
     
  4. PY01A0080

    Thread Starter Member

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

    Thread Starter Member

    Mar 7, 2013
    42
    3
    Hi absf,

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

    Code ( (Unknown Language)):
    1.  org 0000h
    2. mov tmod,#29h; Mode1=1 Timer0=1
    3. mov th1,#0fdh; th1 value for 9600
    4. mov scon,#50h; SM1=1 and REN=1
    5. setb tr1; start of the timer1
    6.  
    7.  
    8. loop:
    9. mov p1,#01h
    10. mov a,p1
    11. acall send
    12. ;acall delay
    13.  
    14. Loop2: rl a
    15. mov p1,a
    16. lcall send
    17. lcall delay
    18. jnb p1.7,Loop2
    19. sjmp loop
    20.  
    21. send:
    22. mov sbuf,a
    23. Here:jnb ti,Here
    24. clr ti
    25. acall delay
    26. ret
    27.  
    28.  
    29. delay:mov r0,#10h
    30. l1: mov th0,#76
    31. mov tl0,#01h
    32. setb tr0
    33. jnb tf0,$
    34. clr tf0
    35. djnz r0,l1
    36. ret
    37. end

    Code ( (Unknown Language)):
    1. org 0000h                                    
    2.  mov tmod,#20h           
    3.  mov th1,#0fdh           
    4.  mov scon,#50h           
    5.  setb tr1
    6.  
    7.  
    8.  H:jnb ri,H
    9.  
    10.  mov a,sbuf
    11.  mov p2,a
    12.  clr ri
    13.  sjmp H
    14.  end
    and it's working now
    i made other mistake in the proteus, i just reversed the two microprocessors

    Thank you
     
Loading...