how can I interface seven segment display with keypad to show values? simulation doesn't work?

38 Views Asked by At

enter image description here

        ORG 0000H
        MOV P2,#00000000B

BACK:   MOV P1,#11111111B
        CLR P1.0
        JB P1.4, NEXT1
        MOV P2,#00000110B
NEXT1:  JB P1.5,NEXT2
        MOV P2,#01011011B
NEXT2:  JB P1.6,NEXT3
        MOV P2,#01001111B
NEXT3:  JB P1.7,NEXT4
        MOV P2,#01110111B
NEXT4:  SETB P1.0
        CLR P1.1
        JB P1.4,NEXT5
        MOV P2,#01100110B
NEXT5:  JB P1.5,NEXT6
        MOV P2,#01101101B
NEXT6:  JB P1.6,NEXT7
        MOV P2,#01111101B
NEXT7:  JB P1.7,NEXT8
        MOV P2,#01111100B
NEXT8:  SETB P1.1
        CLR P1.2
        JB P1.4,NEXT9
        MOV P2, #00000111B
NEXT9:  JB P1.5,NEXT10
        MOV P2,#01111111B
NEXT10: JB P1.6,NEXT11
        MOV P2, #01101111B
NEXT11: JB P1.7,NEXT12
        MOV P2, #00111001B
NEXT12:
        SETB P1.2
        CLR P1.3
        JB P1.4,NEXT13
        MOV P2,#01110001B
NEXT13: JB P1.5,NEXT14
        MOV P2,#00111111B
NEXT14: JB P1.6,NEXT15
        MOV P2,#01111001B
NEXT15: JB P1.7,BACK
        MOV P2,#01011110B
        LJMP BACK
        END
        ORG 0000H
        MOV DPTR,#LUT
        MOV A, #11111111B
        MOV P2,#00000000B

BACK:   MOV P1,#11111111B
        CLR P1.0
        JB P1.4,NEXT1
        MOV A,#0D
        ACALL DISPLAY
NEXT1:  JB P1.5,NEXT2
        MOV A,#1D
        ACALL DISPLAY
NEXT2:  JB P1.6,NEXT3
        MOV A,#2D
        ACALL DISPLAY
NEXT3:  JB P1.7,NEXT4
        MOV A,#3D
        ACALL DISPLAY
NEXT4:  SETB P1.0
        CLR P1.1
        JB P1.4,NEXT5
        MOV A,#4D
        ACALL DISPLAY
NEXT5:  JB P1.5, NEXT6
        MOV A,#5D
        ACALL DISPLAY
NEXT6:  JB P1.6,NEXT7
        MOV A,#6D
        ACALL DISPLAY
NEXT7:  JB P1.7,NEXT8
        MOV A,#7D
        ACALL DISPLAY
NEXT8:  SETB P1.1
        CLR P1.2
        JB P1.4,NEXT9
        MOV A, #8D
        ACALL DISPLAY
NEXT9:  JB P1.5,NEXT10
        MOV A,#9D
        ACALL DISPLAY
NEXT10: JB P1.6,NEXT11
        MOV A,#10D
        ACALL DISPLAY
NEXT11: JB P1.7,NEXT12
        MOV A,#11D
        ACALL DISPLAY
NEXT12: SETB P1.2
        CLR P1.3
        JB P1.4,NEXT13
        MOV A,#12D
        ACALL DISPLAY
NEXT13: JB P1.5,NEXT14
        MOV A,#13D
        ACALL DISPLAY
NEXT14: JB P1.6,NEXT15
        MOV A,#14D
        ACALL DISPLAY
NEXT15: JB P1.7, BACK
        MOV A,#15D
        ACALL DISPLAY
        LJMP BACK

DISPLAY:MOVC A,@A+DPTR
        MOV P2,A
        RET

        ORG 200H
LUT:
        DB 00000110B ;1
        DB 01011011B ;2
        DB 01001111B ;3
        DB 01110111B ;A
        DB 01100110B ;4
        DB 01101101B ;5
        DB 01111101B ;6
        DB 01111100B ;b
        DB 00000111B ;7
        DB 01111111B ;8
        DB 01101111B ;9
        DB 00111001B ;C
        DB 01110001B ;F
        DB 00111111B ;0
        DB 01111001B ;e
        DB 01011110B ;D
        END
1

There are 1 best solutions below

0
Mohamed Ahmed Mokhtar On

To interact with the keypad, initiate the process by setting all keypad pins to a high state. Subsequently, navigate through each row, executing the following routine: set row 1 to a low state, then inspect each column. If any column registers a low state, indicating a pressed button, you have identified the specific column and the row (which was set to low). Proceed to the next step by restoring row 1 to a high state, and then set row 2 to a low state. Repeat the process by examining each column once again to determine the pressed button in the new row. This sequential approach ensures systematic keypad interfacing.

for me i used 7448 decoder for the 7 segment. TRY this code

ROW1 BIT P1.3
ROW2 BIT P1.2
ROW3 BIT P1.1
ROW4 BIT P1.0

COL1 BIT P1.4
COL2 BIT P1.5
COL3 BIT P1.6
COL4 BIT P1.7

ORG     0000H

MOV     P2,#00000000B   ; INITIALIZES P0 AS OUTPUT PORT

BACK:   MOV     P1,#11111111B
        
        CLR ROW4
        MOV A, #0
        CALL CHECK_COL1
        
        SETB ROW4
        CLR ROW3
        MOV A, #4
        CALL CHECK_COL1
        
        SETB ROW3
        CLR ROW2
        MOV A, #8
        CALL CHECK_COL1
        
        SETB ROW2
        CLR ROW1
        MOV A, #12
        CALL CHECK_COL1
        
        JMP BACK
        
    
CHECK_COL1:
    JB COL1, CHECK_COL2
    MOV B, #0
    JMP COL_CALC
CHECK_COL2:
    JB COL2, CHECK_COL3
    MOV B, #1
    JMP COL_CALC
CHECK_COL3:
    JB COL3, CHECK_COL4
    MOV B, #2
    JMP COL_CALC
CHECK_COL4:
    JB COL4, CHECK_COL_END
    MOV B, #3
    
COL_CALC:
    ADD A, B
    MOV P2, A   ;Display value on 7seg

CHECK_COL_END:  
    RET

END