keyboard.a51

来自「at89C51 keyboard example」· A51 代码 · 共 64 行

A51
64
字号
$INCLUDE   (reg_c51.INC)

;/*_____ D E C L A R A T I O N ___________________________________________*/
keypressed DATA 10H;                /* key pressed value */
key_flag BIT 20H;                   /* software flag */

org 000h
ljmp begin

org 3Bh
ljmp keyboard_it

;/**
; * FUNCTION_PURPOSE:this function setup keyboard.
; * A key set idle mode and an other set the power-down mode
; * In this two mode the microcontoleur wake up at keyboard event
; * FUNCTION_INPUTS:void
; * FUNCTION_OUTPUTS:void
; */
org 0100h
begin:

SETB EA;                            /* enable interrupts */

;/* init keyboard */
MOV   KBE,#0FFh;                    /*Enable all P1 I/O as keyboard IO */
MOV   KBF,#00;                      /* Clear all keyboard flags */
ORL   IEN1,#01h;                    /* Enable keyboard interupt */

loop:

   JNB key_flag,end_if_key_flag     /* keyboard occur */
      MOV R7, keypressed;  
      CJNE R7,#10h,end_if_key0x10;  /*enter Idle mode */
;        /* Entering Idle Mode */
         ORL PCON,#01h;
;        /* Wake up by keypressed value */
      end_if_key0x10:

      CJNE R7,#20h,end_if_key0x20;  /* enter powerdown mode */
;        /* Entering PowerDown Mode */
         ORL PCON,#02h;
;        /* Wake up by keypressed value */
      end_if_key0x20:

      CLR key_flag;                 /* reset softaware flag */
   end_if_key_flag:

JMP loop

;/**
;* FUNCTION_PURPOSE:keyboard_interrupt. Save pressed key
;* FUNCTION_INPUTS:void
;* FUNCTION_OUTPUTS:void
;*/
keyboard_it:

MOV keypressed,KBF;                 /* save pressed key */
SETB key_flag;                      /* set the software flag */
MOV KBF,#00h;                       /* clear keyboard flags */ 
RETI

end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?