Thông báo

Collapse
No announcement yet.

quét bàn phím hex bằng 89c51

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • quét bàn phím hex bằng 89c51

    mấy bác ơi...em đang tìm hiểu cách quét bàn phím hex!
    ai rành chỉ giúp em với nha.
    em định dùng bàn phím hex để khóa cho 1 thiết bị.
    ai có hướng làm chỉ em với.ai có tài liệu thì cho em xin để học hỏi nha.
    thanks all
    đàn bà sinh ra để đàn ông ăn hiếp...ko ăn được thì hiếp....

  • #2
    ;_________________________________________________ __________________________________________________

    ; Author: Ashwin
    ; Location: India
    ; Code: 4x4 matRIx key pad
    ; Inputs: hex keypad via port1
    ; outputs: ASCII value of pressed button is sent through the seRIal port and also the hex equivalent
    ; is ouput thru p3.5 to p3.2
    ;_________________________________________________ __________________________________________________


    ROW0 EQU P1.0
    ROW1 EQU P1.1
    ROW2 EQU P1.2
    ROW3 EQU P1.3

    CLMN0 EQU P1.7
    CLMN1 EQU P1.6
    CLMN2 EQU P1.5
    CLMN3 EQU P1.4

    Keypad EQU P1
    ;_________________________________________________ __________________________________________________

    BSEG AT 0

    KeyPressed: DBIT 1
    ;_________________________________________________ __________________________________________________
    DSEG AT 30H

    KeyData: DS 1
    Debounce: DS 1
    DL1: DS 1
    DL2: DS 1
    ;_________________________________________________ __________________________________________________
    CSEG

    ORG 8000H

    MOV SP, #80H
    ACALL KeypadScan
    SJMP $
    ;_________________________________________________ __________________________________________________
    ;
    ; |------|------|------|------| |------|------|------|------|
    ; | P1.4 | P1.5 | P1.6 | P1.7 | | P1.4 | P1.5 | P1.6 | P1.7 |
    ; |------|------|------|------| |------|------|------|------|
    ; P1.0 | 0 | 1 | 2 | 3 | | | UP | | |
    ; |------|------|------|------| |------|------|------|------|
    ; P1.1 | 4 | 5 | 6 | 7 | | SL | VIEW | SR | |
    ; |------|------|------|------| |------|------|------|------|
    ; P1.2 | 8 | 9 | A | B | | | DOWN | | |
    ; |------|------|------|------| |------|------|------|------|
    ; P1.3 | C | D | E | F | | | | | |
    ; |------|------|------|------| |------|------|------|------|
    ;_________________________________________________ __________________________________________________


    KeypadScan:
    MOV Keypad, #0F0H ; Cho các cột lên cao, các hàng xuống thấp
    MOV A, Keypad ; Kiểm tra xem có phím nào được nhấn hay không
    ANL A, #0F0H
    CJNE A, #0F0H, KeypadScan1
    CLR KeyPressed ; Không có phím nào nhấn
    RET

    KeypadScan1:
    MOV Debounce, #10
    DJNZ Debounce, KeypadScan2
    CLR KeyPressed ; Phím bấm bị lỗi
    MOV KeyData, #0
    RET

    KeypadScan2:
    MOV KeyData, A
    ACALL Delay_1mS
    MOV A, Keypad
    ANL A, #0F0H
    XRL A, KeyData
    JNZ KeypadScan1
    DJNZ Debounce, KeypadScan2
    KeyRelease:
    MOV A, Keypad
    ORL A, #00FH
    CPL A
    JNZ KeyRelease

    Check_Row:
    MOV DPTR, #Disp_Pressed
    ACALL Disp_Message
    MOV Keypad, #0FEH
    MOV A, Keypad
    ANL A, #0FEH ; Thử hàng 0
    CJNE A, #0FEH, Row_0

    MOV Keypad, #0FDH
    MOV A, Keypad
    ANL A, #0FDH ; Thử hàng 1
    CJNE A, #0FDH, Row_1

    MOV Keypad, #0FBH
    MOV A, Keypad
    ANL A, #0FBH ; Thử hàng 2
    CJNE A, #0FBH, Row_2

    MOV Keypad, #0F7H
    MOV A, Keypad
    ANL A, #0F7H ; Thử hàng 3
    CJNE A, #0F7H, Row_3
    CLR KeyPressed
    RET
    ;---------------------------------------------------------------------------------------------------

    Row_0: MOV DPTR, #Disp_Kcode0 ;
    SJMP Find_Num

    Row_1: MOV DPTR, #Disp_Kcode1
    SJMP Find_Num

    Row_2: MOV DPTR, #Disp_Kcode2
    SJMP Find_Num

    Row_3: MOV DPTR, #Disp_Kcode3
    SJMP Find_Num
    ;---------------------------------------------------------------------------------------------------

    Find_Num:
    RLC A
    JNC Found_Num ; which column is pressed/grounded
    INC DPTR
    SJMP Find_Num
    ;---------------------------------------------------------------------------------------------------
    Found_Num:
    SETB KeyPressed
    CLR A
    MOVC A, @A+DPTR
    MOV KeyData, A
    ACALL Tx_Main ; send pressed button to seRIal port
    ; ACALL Ascii2Hex
    RET
    ;_________________________________________________ __________________________________________________

    Tx_Main:
    MOV SBUF, A
    Tx_Loop:
    JNB TI, Tx_Loop
    CLR TI
    RET
    ;_________________________________________________ __________________________________________________

    Disp_Message:
    PUSH ACC
    Disp_Message_Loop1:
    MOV A, #0
    MOVC A, @A+DPTR
    CJNE A, #0, Disp_Message_Loop2
    POP ACC
    RET
    ;---------------------------------------------------------------------------------------------------
    Disp_Message_Loop2:
    ACALL Tx_Main
    INC DPTR
    SJMP Disp_Message_Loop1

    Disp_Pressed:
    DB ' Key pressed is: ', 0
    ;_________________________________________________ __________________________________________________

    ; Packed ASCII to HEX conversion
    Ascii2Hex:
    PUSH ACC
    MOV A, KeyData
    SUBB A, #30H
    MOV B, A
    ANL A, #10H
    CJNE A, #0, Ascii2Hex_Loop2
    MOV A, B
    Ascii2Hex_Loop1:
    MOV KeyData, A
    POP ACC
    RET

    Ascii2Hex_Loop2:
    MOV A, KeyData
    SUBB A, #37H
    SJMP Ascii2Hex_Loop1
    ;_________________________________________________ __________________________________________________


    ;_________________________________________________ __________________________________________________

    Disp_Kcode0:
    DB '0', '1', '2', '3'
    Disp_Kcode1:
    DB '4', '5', '6', '7'
    Disp_Kcode2:
    DB '8', '9', 'A', 'B'
    Disp_Kcode3:
    DB 'C', 'D', 'E', 'F'
    ;_________________________________________________ __________________________________________________

    Delay_1mS:
    MOV DL2, #2
    MOV DL1, #238
    DLy1: DJNZ DL1, DLy1
    DJNZ DL2, DLy1
    RET
    ;_________________________________________________ __________________________________________________

    Delay_2mS:
    MOV DL2, #4
    MOV DL1, #224
    DLy2: DJNZ DL1, DLy2
    DJNZ DL2, DLy2
    RET
    ;_________________________________________________ __________________________________________________

    Delay_5mS:
    MOV DL2, #10
    MOV DL1, #182
    DLy5: DJNZ DL1, DLy5
    DJNZ DL2, DLy5
    RET
    ;_________________________________________________ __________________________________________________

    Delay_10mS:
    MOV DL2, #20
    MOV DL1, #112
    DLy10: DJNZ DL1, DLy10
    DJNZ DL2, DLy10
    RET
    ;_________________________________________________ __________________________________________________

    Delay_20mS:
    MOV DL2, #39
    MOV DL1, #229
    DLy20: DJNZ DL1, DLy20
    DJNZ DL2, DLy20
    RET
    ;_________________________________________________ __________________________________________________








    END

    Comment

    Về tác giả

    Collapse

    dinhthuan911 hehe Tìm hiểu thêm về dinhthuan911

    Bài viết mới nhất

    Collapse

    Đang tải...
    X