;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;另外一种键值扫描法
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


KEYH:           SETB    P1.6
                SETB    P1.7
                SETB    P0.3
                SETB    P0.4
                SETB    P0.5
                SETB    P0.6
                MOV     A,      KEYBUF1
                JNB     ACC.0,  KEYH1
                JNB     ACC.1,  KEYH2
                JNB     ACC.2,  KEYH3
                JNB     ACC.3,  KEYH4
                JNB     ACC.4,  KEYH5
                JNB     ACC.5,  KEYH6
                MOV     KEYBUF1,     #0FEH
                RET
KEYH1:          CLR     P1.6
                RL      A
                MOV     KEYBUF1,        A
                RET
KEYH2:          CLR     P1.7
                RL      A
                MOV     KEYBUF1,        A
                RET
KEYH3:          CLR     P0.3
                RL      A
                MOV     KEYBUF1,        A
                RET
KEYH4:          CLR     P0.4
                RL      A
                MOV     KEYBUF1,        A
                RET
KEYH5:          CLR     P0.5
                RL      A
                MOV     KEYBUF1,        A
                RET
KEYH6:          NOP
                CLR     P0.6
                MOV     KEYBUF1,        #0FEH
                RET

REPEAT_H:

                SETB    P1.6
                SETB    P1.7
                SETB    P0.3
                SETB    P0.4
                SETB    P0.5
                SETB    P0.6
                MOV     A,      KEYBUF1
                RR      A
                MOV     C,      ACC.7
                MOV     ACC.5,  c
                JNB     ACC.0,  REPH1
                JNB     ACC.1,  REPH2
                JNB     ACC.2,  REPH3
                JNB     ACC.3,  REPH4
                JNB     ACC.4,  REPH5
                JNB     ACC.5,  REPH6
                RET
REPH1:          CLR     P1.6
                RET
REPH2:          CLR     P1.7
                RET
REPH3:          CLR     P0.3
                RET
REPH4:          CLR     P0.4
                RET
REPH5:          CLR     P0.5
                RET
REPH6:          CLR     P0.6
                RET


KEYMAIN:
                LCALL   KEYH

                LCALL   SDELAY

                MOV     A,    P1
                RR      A
                ORL     A,      #0E0H
                CPL     A
                JNZ     KEYMAIN1
                DJNZ    IRCOUN,         KEY1
                MOV     IRCOUN,         #08H
                CLR     KEYFLAG
                LCALL   DELAY
KEY1:           RET


KEYMAIN0:       RET

KEYMAIN1:       LCALL   REPEAT_H
                LCALL   SDELAY

                MOV     A,    P1
                RR      A
                ORL     A,      #0E0H
                CPL     A
                JNZ     KEYMAIN2
                RET

KEYMAIN2:
                MOV     IRCOUN,         #08H
                JB      KEYFLAG,        KEYMAIN0
                SETB    KEYFLAG
                MOV     IRCOUN,         #08H
                MOV     B,      A
                MOV     A,      KEYBUF1
                CJNE    A,      #0F7H,  KEYM2
KEYM1:          MOV     A,      B
                CJNE    A,      #10H,  KEY1M_A
                LJMP    KEY_MUSTOP
KEY1M_A:        CJNE    A,      #08H,  KEY1M_B
                LJMP    KEY_MASTERVOLUP
KEY1M_B:        CJNE    A,      #04H,  KEY1M_C
                LJMP    KEY_MASTERVOLDN
KEY1M_C:        CJNE    A,      #02H,  KEY1M_D
                LJMP    KEY_MUTE
KEY1M_D:        CJNE    A,       #01H, KEY1M_E
                LJMP    KEY_LEARING
KEY1M_E:        RET


KEYM2:          CJNE    A,      #0DFH,   KEYM3
                MOV     A,      B
                CJNE    A,      #10H,  KEY2M_A
                LJMP    KEY_IRPOWER
KEY2M_A:        CJNE    A,      #08H,  KEY2M_B
                LJMP    KEY_IRBACK
KEY2M_B:        CJNE    A,      #04H,  KEY2M_C
                LJMP    KEY_IRPLAY
KEY2M_C:        RET

KEYM3:          CJNE    A,      #0FBH,  KEYM4

KEYM3S:         MOV     A,      B
                CJNE    A,      #10H,  KEY3M_A
                LJMP    KEY_IRSTOP
KEY3M_A:        CJNE    A,      #08H,  KEY3M_B
                LJMP    KEY_IRPUSE
KEY3M_B:        CJNE    A,      #04H,  KEY3M_C
                LJMP    KEY_IRNEXT
KEY3M_C:        RET


KEYM4:          CJNE    A,      #0FDH,    KEYM5
                MOV     A,      B
                CJNE    A,      #02H,  KEYM4S
                LJMP    KEY_VGA
KEYM4S:         CJNE    A,      #01H,  KEY4M_B
                LJMP    KEY_COMPUTER1
KEY4M_B:        CJNE    A,      #04H,  KEY4M_C
                LJMP    KEY_COMPUTER2
KEY4M_C:        CJNE    A,      #08H,  KEY4M_D
                LJMP    KEY_XIAKE
KEY4M_D:        CJNE    A,      #10H, KEY4M_E
                LJMP    KEY_SHANGKE
KEY4M_E:        RET

KEYM5:          CJNE    A,      #0FEH,  KEYM6
KEYM5S:         MOV     A,      B
                CJNE    A,      #10H,  KEY5M_A
                LJMP    KEY_DVD1
KEY5M_A:        CJNE    A,      #08H,  KEY5M_B
                LJMP    KEY_VCR1
KEY5M_B:        CJNE    A,      #04H,  KEY5M_C
                LJMP    KEY_VIEW1
KEY5M_C:        CJNE    A,      #02H,  KEY5M_D
                LJMP    KEY_TAPE1
KEY5M_D:        CJNE    A,       #01H,  KEY5M_E
                LJMP    KEY_VIDEO
                RET
KEY5M_E:        RET


KEYM6:          CJNE    A,      #0EFH,  KEYM7
KEYM6S:         MOV     A,      B
                CJNE    A,      #10H,  KEY6M_A
                LJMP    KEY_POWERON
KEY6M_A:        CJNE    A,      #08H,  KEY6M_B
                LJMP    KEY_POWEROFF
KEY6M_B:        CJNE    A,      #04H,  KEY6M_C
                LJMP    KEY_MUUPDN
KEY6M_C:        CJNE    A,      #01H,  KEY6M_C
                LJMP    KEY_LEARING
                RET
KEYM7:          RET


SDELAY:       MOV       R7,     #1H
SDEL1:        NOP
              DJNZ      R7,     SDEL1
              RET

DELAY:        MOV  R7,     #90H
DLY1:         NOP
              NOP
              DJNZ R7,     DLY1
              RET
