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

Define the ports of AT89C51 as input or output.

I m using AT89C51 for digital clock, with external clock.

i want to set the port0-1-2 for parallel data, and port3 for serial data

the problem is to define the port as input or Output

Master Clock
------------------
port0 for input
port1 for output
port2 for output
port3 for output (to send serial data)

Slave Clock
------------------
port0 for output
port1 for output
port2 for output
port3 for input (to receive data)

please tell me how can i set the ports for input and/or as outpur

Parents
  • What is port0, port1, port2, port3? Individual pins or full 8-bit ports?

    With most 8051 chips, you don't have to change a setting to use a pin as input or output. It has a weak pull-up, so when you set the pin as high from the inside, any external equipment can use it as an input. If you set the pin as low from your program, it will be able to sink current.

    Just note that the reset state is the weak pull-up state, and it really is weak and not intended to supply power to a LED or similar.

    Have you spent time reading up on the 8051 in general, and your specific chip?

Reply
  • What is port0, port1, port2, port3? Individual pins or full 8-bit ports?

    With most 8051 chips, you don't have to change a setting to use a pin as input or output. It has a weak pull-up, so when you set the pin as high from the inside, any external equipment can use it as an input. If you set the pin as low from your program, it will be able to sink current.

    Just note that the reset state is the weak pull-up state, and it really is weak and not intended to supply power to a LED or similar.

    Have you spent time reading up on the 8051 in general, and your specific chip?

Children
  • Thanks to support me, ports0-3 are full 8-bit ports.

    I m sending my source code please inform me any types of errors

    I shell be very thankful to you.

    org 00h
    
    ;Set up Timer 1
            MOV     IE, #0                  ; Disable all interrupt
            MOV     TMOD, #020h             ; Timer 1: Mode 2 (8-bit reload)
            MOV     TH1, #230d              ; Reload value for 1201, SMOD = 0
            MOV     TL1, #230d              ; Make first time-out correct
            ANL     PCON, #07fh             ; To make SMOD =0
    
    ;Set up serial ports
            MOV     SCON, #50h              ; Timer 1 : Mode 1 (vari baud) and set receive enable
            SETB    TR1                             ; Start timer 1
            mov r1, #6d
            mov r2, #91d
            mov r3, #63d
            mov r4, #63d
    
    MainLoop:
    setb p0.7
    
    mov r7, #90d
            SubLoop:
            mov r6, #90d
                    InnerSpot:
                            jmp DisplayData
                    InnerSpot1:
                    djnz r6, InnerSpot
            djnz r7, SubLoop
    
    clr p0.7
    
    mov r7, #90d
            SubLoop1:
            mov r6, #90d
                    InnerSpot12:
                            jmp DisplayData
                    InnerSpot11:
                    djnz r6, InnerSpot12
            djnz r7, SubLoop1
    
    
    jmp MainLoop
    
    DisplayData:
    mov C, p2.7
    orl C, p0.7
    
    
            mov b, r1
       mov p2, b
    JNC Skip1
            mov b, #254d
            mov p1, b
    Skip1:
                    mov b, #255d
               mov p1, b
            mov b, r2
       mov p2, b
    JNC Skip2
            mov b, #253d
       mov p1, b
    Skip2:
                    mov b, #255d
               mov p1, b
    
            mov b, r3
       mov p2, b
    JNC Skip3
            mov b, #251d
       mov p1, b
    Skip3:
                    mov b, #255d
               mov p1, b
    
            mov b, r4
       mov p2, b
    JNC Skip4
            mov b, #247d
       mov p1, b
    Skip4:
                    mov b, #255d
               mov p1, b
    
            jnb RI, CheckReturnPoint
            clr RI
            mov a, sbuf
    
    cjne a, #246d, CountCountinus
            mov r0, #0d
    
    CheckReturnPoint:
    mov c, p0.7
            jc InnerSpot1
    jnc InnerSpot11
    
    CountCountinus:
    inc r0
    
    DigOne:
    cjne r0, #1d, DigTwo
       mov r1, a
       Jmp DisplayData
    
    DigTwo:
    cjne r0, #2d, DigThree
       mov r2, a
       Jmp DisplayData
    
    DigThree:
    cjne r0, #3d, DigFour
       mov r3, a
       Jmp DisplayData
    
    DigFour:
    cjne r0, #4d, CheckReturnPoint
            mov r0, #0d
       mov r4, a
    Jmp DisplayData
    
    End
    
    

  • thanks

    very important help

    i m really thankful to you

  • from tyhe above
    ;Set up serial ports

            MOV     SCON, #50h              ; Timer 1 : Mode 1 (vari baud) and set receive enable
            SETB    TR1                             ; Start timer 1
            mov r1, #6d
            mov r2, #91d
            mov r3, #63d
            mov r4, #63d
    MainLoop: