keyboard.c

来自「at89C51 keyboard example」· C语言 代码 · 共 73 行

C
73
字号
/**
 * @file $RCSfile: keyboard.c,v $
 *
 * Copyright (c) 2004 Atmel.
 *
 * Please read file license.txt for copyright notice.
 *
 * @brief This file is an example to use keyboard.
 *
 * This file can be parsed by Doxygen for automatic documentation
 * generation.
 * Put here the functional description of this file within the software
 * architecture of your program.
 *
 * @version $Revision: 1.0 $ $Name:  $
 */

/* @section  I N C L U D E S */
#include "reg_C51.h"

/*_____ D E C L A R A T I O N ___________________________________________*/
unsigned int keypressed;         /* key pressed value */
bit key_flag;                    /* software flag */

/**
 * 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
 */
void  main()
{
EA=1; /* enable interrupts */
/* init keyboard */
   KBE=0xFF;                     /*Enable all P1 I/O as keyboard IO */
   KBF=0x00;                     /* Clear all keyboard flags */
   IEN1 |=0x01;                  /* Enable keyboard interupt */

while(1)                         /* endless */
{
   if (key_flag)                 /* keyboard occur */
   {
      if ( keypressed==16)       /*enter Idle mode */
      {
         /* Entering Idle Mode */
         PCON |=0x01;
         /* Wake up by keypressed value */
      }
      if ( keypressed==32)       /* enter powerdown mode */
      {
         /* Entering PowerDown Mode */
         PCON |=0x02;
         /* Wake up by keypressed value */
      }
      key_flag=0;                /* reset softaware flag */
      }
   }
}

/**
* FUNCTION_PURPOSE:keyboard_interrupt. Save pressed key
* FUNCTION_INPUTS:void
* FUNCTION_OUTPUTS:void
*/
void keyboard_interrupt() interrupt 7 using 1
{
keypressed=KBF;                  /* save pressed key */
key_flag=1;                      /* set the software flag */
KBF=0x00;                        /* clear keyboard flags */ 
}

⌨️ 快捷键说明

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