8051 - reading values from Port 0 and display a digit on 7-segment display

Discussion in 'Embedded Systems and Microcontrollers' started by PG1995, May 2, 2012.

  1. PG1995

    Thread Starter Active Member

    Apr 15, 2011
    753
    5
    Hi

    Do you find the code below correct and do you think it can read values from Port 0? The keypad and 7-segment display don't need any kind of programming in MCU 8051 IDE. The segments of 7-segment display need LOW voltage in order to get activated. For example, in the linked video you can notice that all the segments turn on when "0" is moved into the Port 1 at the end of the code. I think there is some problem with the code and the code doesn't read the keypad's input. Kindly help me. Thank you.

    Video: http://www.youtube.com/watch?v=8IsqWjMUaMQ

    Code ( (Unknown Language)):
    1.  
    2. ; Interface a numeric keypad to PORT 0 and display the entered decimal digits
    3. ; ,1-9, on a 7-segment display connected to PORT 1
    4.  
    5. org 0x0
    6.  
    7.     Repeat:
    8.     mov P0, #0x0FF    ;Port 1 is not an input port
    9.     mov A, P1    ;the contents of P1 are moved into A
    10.    
    11.     CJNE A, #1, DigitIz2 ;if A=1, then this would mean entered digit was "1"
    12.     mov P1, #1      ;this will diplay "1" on 7-segment display
    13.     SJMP Repeat     ;execution of the program repeats
    14.    
    15.     DigitIz2:
    16.     CJNE A, #2, DigitIz3
    17.     mov P1, #2
    18.     SJMP Repeat
    19.  
    20.     DigitIz3:
    21.     CJNE A, #3, DigitIz4
    22.     mov P1, #3
    23.     SJMP Repeat
    24.  
    25.     DigitIz4:
    26.     CJNE A, #4, DigitIz5
    27.     mov P1, #4
    28.     SJMP Repeat
    29.  
    30.     DigitIz5:
    31.     CJNE A, #5, DigitIz6
    32.     mov P1, #5
    33.     SJMP Repeat
    34.  
    35.     DigitIz6:
    36.     CJNE A, #6, DigitIz7
    37.     mov P1, #6
    38.     SJMP Repeat
    39.  
    40.     DigitIz7:
    41.     CJNE A, #7, DigitIz8
    42.     mov P1, #7
    43.     SJMP Repeat
    44.  
    45.     DigitIz8:
    46.     CJNE A, #8, DigitIz9
    47.     mov P1, #8
    48.     SJMP Repeat
    49.  
    50.     DigitIz9:
    51.     CJNE A, #9, DigitIz0  ;here digit "0" stands for an error
    52.     mov P1, #9
    53.     SJMP Repeat
    54.  
    55.     DigitIz0:
    56.     mov P1, #0
    57.     SJMP Repeat
    58.  
    59. end
    60.  
     
  2. BillO

    Well-Known Member

    Nov 24, 2008
    985
    136
    I think:

    mov A, P1

    should be:

    mov A, P0

    In the 2nd line after REPEAT:
     
  3. PG1995

    Thread Starter Active Member

    Apr 15, 2011
    753
    5
Loading...