This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

problem in serial communication between pc and 89c52

hello sir/madam , i am doing project on serial communication between pc and 89c52.all the connections are correct. but the problem is with the receiving of the data in the hyperterminal. when i press some letters in hypeterminal some other letter will be displayed; i am not getting what is the and where is the fault.. could you suggest me some solutions.. thanking you

Parents Reply Children
  • code: ORG 0030h MOV SP,#07H CLR P0.0; CLR P0.1; CLR P0.2; CLR P0.4; CLR P0.6; CLR P0.7; ACALL DELAY;

    SETB P0.4 ;PULSE FOR ALE ACALL DELAY;

    CLR P0.4 ;
    MAIN:MOV TMOD,#20H;; MOV TH1,#0FDH; MOV SCON,#50H; SETB TR1;
    HERE:JNB RI,HERE; MOV A,SBUF; MOV R7,A MOV R2,#30H MOV R1,#0AH MOV R0,#39H
    BACK:CJNE A,00H,LOOP CLR C SUBB A,R2 MOV R3,A SJMP END1
    LOOP:DEC R0 DJNZ R1,BACK MOV R0,#39H MOV R4,#06H MOV R5,#46H MOV R6,#37H
    BACK1:CJNE A,05H,LOOP1 CLR C SUBB A,R6 MOV R3,A SJMP END1
    LOOP1:DEC R5 DJNZ R4,BACK1 MOV R5,#46H CLR C MOV 08H,A SUBB A,R7 JZ MAIN MOV A,08H
    END1: NOP
    MAIN1:CLR RI SETB TR1
    HERE1:JNB RI,HERE1 MOV A, SBUF MOV R7,A MOV R2,#30H MOV R1,#0AH MOV R0,#39H
    BACK2:CJNE A,00H,LOOP2 CLR C SUBB A,R2 MOV R4,A MOV A,R3 SWAP A ADD A,R4 SJMP END2
    LOOP2:DEC R0 DJNZ R1,BACK2 MOV R0,#39H MOV R4,#06H MOV R5,#46H MOV R6,#37H
    BACK3:CJNE A,05H,LOOP3 CLR C SUBB A,R6 MOV R4,A MOV A,R3 SWAP A ADD A,R4 SJMP END2
    LOOP3:DEC R5 DJNZ R4,BACK3 MOV R5,#46H CLR C MOV 08H,A SUBB A,R7 JZ MAIN1 MOV A,08H
    END2: NOP MOV P2,A

    ; A1:MOV R0,#0FFH ;DELAY OF 15
    ; A2:DJNZ R0,A2

    SETB P0.6 ;PULSE FOR SOC A3:MOV R1,#0FH A4:DJNZ R1,A4

    CLR P0.6 ;CLEAR SOC

    ;; MOV R1,#69H
    ; A5:DJNZ R1,A5 LOOP4:JB P0.7,LOOP4 ; MONITOR EOC ; ANL A,#80H
    ; JZ LOOP4
    ; ACALL DELAY
    ; ACALL DELAY SETB P0.5 ;PULSE FOR OE
    ; MOV R1,#0FH
    ; A5:DJNZ R1,A5 ; transmit to pc

    MOV TMOD,#20H MOV TH1,#0FDH MOV SCON,#50H SETB TR1 MOV A,P1
    ; CLR P0.5 ;LOW THE OE SIGNAL AFTER COMPLETE RECEPTION OF THE DATA MOV R3,A ANL A,#0F0H SWAP A MOV R2,#30H MOV R1,#0AH MOV R0,#09H
    BACK4:CJNE A,00H,LOOP5 CLR C ADD A,R2 SJMP END3
    LOOP5:DEC R0 DJNZ R1,BACK4 MOV R0,#09H MOV R4,#06 MOV R5,#0FH MOV R6,#37H
    BACK5:CJNE A,05H,LOOP6 CLR C ADD A,R6
    ; MOV P2,A ; SJMP END3
    LOOP6:DEC R5 DJNZ R4,BACK5 MOV R5,#0FH END3:NOP MOV SBUF,A
    HERE2:JNB TI,HERE2 CLR TI MOV A,R3 ANL A,#0FH MOV R2,#30H MOV R1,#0AH MOV R0,#09H
    BACK6:CJNE A,00H,LOOP7 CLR C ADD A,R2
    ; MOV P2,A SJMP END4
    LOOP7:DEC R0 DJNZ R1,BACK6 MOV R0,#09H MOV R4,#06 MOV R5,#0FH MOV R6,#37H
    BACK7:CJNE A,05H,LOOP8 CLR C ADD A,R6 MOV R3,A SJMP END4
    LOOP8:DEC R5 DJNZ R4,BACK7 MOV R5,#0FH END4:NOP MOV SBUF,A
    HERE3:JNB TI,HERE3 CLR TI LJMP MAIN

    ;DELAY SUBROUTINE
    DELAY:MOV R0,#0FFH DELA:MOV R1,#0FFH DEL:DJNZ R1,DEL DJNZ R0,DELA RET

    END;
    the coneection goes like this:
    form pc to max232,max232 to mc,mc to dac,dac to adc,adc back to mc, and mc to max 232 and to pc...could you tell me where is the falult..
    i am getting the wrong result in hyperterminal. all connections are correct...

  • the code is

                  ORG 0030h
                       MOV SP,#07H
              CLR P0.0
              CLR P0.1
              CLR P0.2
              CLR P0.4
              CLR P0.6
              CLR P0.7
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
    
              SETB P0.4      ;PULSE FOR ALE
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
              ACALL DELAY
    
              CLR P0.4
    MAIN:MOV TMOD,#20H
         MOV TH1,#0FDH
             MOV SCON,#50H
             SETB TR1
    HERE:JNB RI,HERE
         MOV A,SBUF
             MOV R7,A
             MOV R2,#30H
             MOV R1,#0AH
             MOV R0,#39H
    BACK:CJNE A,00H,LOOP
         CLR C
             SUBB A,R2
             MOV R3,A
             SJMP END1
    LOOP:DEC R0
         DJNZ R1,BACK
             MOV R0,#39H
             MOV R4,#06H
             MOV R5,#46H
             MOV R6,#37H
    BACK1:CJNE A,05H,LOOP1
          CLR C
              SUBB A,R6
              MOV R3,A
              SJMP END1
    LOOP1:DEC R5
          DJNZ R4,BACK1
              MOV R5,#46H
              CLR C
          MOV 08H,A
          SUBB A,R7
          JZ MAIN
          MOV A,08H
    END1: NOP
    MAIN1:CLR RI
              SETB TR1
    HERE1:JNB RI,HERE1
          MOV A, SBUF
              MOV R7,A
              MOV R2,#30H
              MOV R1,#0AH
              MOV R0,#39H
    BACK2:CJNE A,00H,LOOP2
          CLR C
              SUBB A,R2
              MOV R4,A
              MOV A,R3
              SWAP A
              ADD A,R4
              SJMP END2
    LOOP2:DEC R0
          DJNZ R1,BACK2
              MOV R0,#39H
              MOV R4,#06H
              MOV R5,#46H
              MOV R6,#37H
    BACK3:CJNE A,05H,LOOP3
          CLR C
              SUBB A,R6
              MOV R4,A
              MOV A,R3
              SWAP A
              ADD A,R4
              SJMP END2
    LOOP3:DEC R5
          DJNZ R4,BACK3
              MOV R5,#46H
              CLR C
          MOV 08H,A
          SUBB A,R7
          JZ MAIN1
          MOV A,08H
    END2: NOP
          MOV P2,A
    
    ;         A1:MOV R0,#0FFH        ;DELAY OF 15
    ;         A2:DJNZ R0,A2
    
              SETB P0.6                       ;PULSE FOR SOC
              A3:MOV R1,#0FH
              A4:DJNZ R1,A4
    
              CLR P0.6                       ;CLEAR SOC
    
    ;;        MOV R1,#69H
    ;   A5:DJNZ R1,A5
              LOOP4:JB P0.7,LOOP4           ; MONITOR EOC
     ;     ANL A,#80H
    ;         JZ LOOP4
    ;      ACALL DELAY
    ;         ACALL DELAY
         SETB P0.5        ;PULSE FOR OE
    ;        MOV R1,#0FH
    ;  A5:DJNZ R1,A5
                      ;     transmit to pc
    
          MOV TMOD,#20H
              MOV TH1,#0FDH
              MOV SCON,#50H
              SETB TR1
              MOV A,P1
    ;          CLR P0.5             ;LOW THE OE SIGNAL AFTER COMPLETE RECEPTION OF THE DATA
              MOV R3,A
              ANL A,#0F0H
              SWAP A
              MOV R2,#30H
              MOV R1,#0AH
              MOV R0,#09H
    BACK4:CJNE A,00H,LOOP5
          CLR C
              ADD A,R2
              SJMP END3
    LOOP5:DEC R0
          DJNZ R1,BACK4
              MOV R0,#09H
              MOV R4,#06
              MOV R5,#0FH
              MOV R6,#37H
    BACK5:CJNE A,05H,LOOP6
          CLR C
              ADD A,R6
    ;         MOV P2,A      ;
              SJMP END3
    LOOP6:DEC R5
          DJNZ R4,BACK5
              MOV R5,#0FH
     END3:NOP
          MOV SBUF,A
    HERE2:JNB TI,HERE2
          CLR TI
              MOV A,R3
              ANL A,#0FH
              MOV R2,#30H
              MOV R1,#0AH
              MOV R0,#09H
    BACK6:CJNE A,00H,LOOP7
         CLR C
              ADD A,R2
    ;         MOV P2,A
              SJMP END4
    LOOP7:DEC R0
          DJNZ R1,BACK6
              MOV R0,#09H
              MOV R4,#06
              MOV R5,#0FH
              MOV R6,#37H
    BACK7:CJNE A,05H,LOOP8
          CLR C
              ADD A,R6
              MOV R3,A
              SJMP END4
    LOOP8:DEC R5
          DJNZ R4,BACK7
              MOV R5,#0FH
     END4:NOP
          MOV SBUF,A
    HERE3:JNB TI,HERE3
          CLR TI
               LJMP MAIN
    
              ;DELAY SUBROUTINE
    DELAY:MOV R0,#0FFH
     DELA:MOV R1,#0FFH
      DEL:DJNZ R1,DEL
          DJNZ R0,DELA
          RET
    
              END
    

  • ...is to go through that code and provide comments that describe what you think it is supposed to be doing!

    Also strip-out all the redundant text.

    This exercise alone may well take you to your mistake!

  • hi,

    Why do you have given so much delay before serial communication settings?

    Because if you type any character before settings, controller can not receive it.

    Another thing is that clear RI flag & stop timer TR1 after receiving any character.

    MAIN:MOV TMOD,#20H
         MOV TH1,#0FDH
         MOV SCON,#50H
         SETB TR1
    
    HERE:JNB RI,HERE
         CLR RI
         CLR TR1
         MOV A,SBUF
    

  • thank you madam for your reply....actually i am doing my project and i am stuck in the programming part... i will make changes in the code and i will let you know the result..thank you again...

  • madam , when i am executing the above code (with tha above modifications), only "FF" is getting displayed in the hyperterminal when i press the characters from the keyboard.... i am not getting the where is the fault... will you provide me the code.. or the link where i can get some help on the code.. please...

  • madam

    What about us poor males? What about us? Aren't you going to ask us? What about us? What?!?!?!

  • ya sure sir, but till now i am getting the satisfactory answer from madam only...thats y i mentioned madam... can you give me the solution for that..

  • And the first step to getting un-stuck is to properly comment the code that you have!

    "i will make changes in the code"

    There is no point in making random changes in the code if you aren't even sure what the current code does!

  • Above code is for receiving characters.

    I think you are displaying the characters which you have typed from keypad.(if not then tell me what actually you want to do?)

    for this first you take character from keypad, save it in one register, and then transmit it to hyper terminal.

  • And what about the link that I gave you in your other thread?

    http://www.8052.com/faqs

    Have you studied it yet?

    Did you learn anything?

    Have you checked all settings - baud rate, parity, etc - and on both the PC and the microcontroller?

    You didn't say how you know that your connections are correct...

  • There is no point in making random changes in the code if you aren't even sure what the current code does!

  • "i will make changes in the code" .. i mean to say that i will include the some steps suggested by shital madam. i also don't change the code randomly.. because i need to complete my project as early as possible..!!!!

  • i also don't change the code randomly..

    I have a feeling that is "shital madam" would tell you to, you would...