⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t_keyscan.c

📁 schduler for AVR mcu
💻 C
字号:
/*
------------------------------------------------------------------*-

   T_KeyScan.C (v1.00)

  ------------------------------------------------------------------
   
   Key scan  program (Test Version 1.0)


   COPYRIGHT
   ---------

   This code is from the book:

   PATTERNS FOR TIME-TRIGGERED EMBEDDED SYSTEMS by Michael J. Pont 
   [Pearson Education, 2001; ISBN: 0-201-33138-1].

   This code is copyright (c) 2001 by Michael J. Pont.
 
   --- Modefied by  sylva zhu to apply for  AVR Microcontroller .
   --- Ver 1.0  Sept 25th , 2006 .

-*------------------------------------------------------------------
*/
#include  <iom32.h>
#include  <inavr.h>
#include  <comp_a90.h>

#include  "Main.h"
#include  "T_KeyScan.h"
//
// global variables
volatile unsigned char FKeyunProcessed;
volatile unsigned char KeyValue;
static   unsigned char GKey;
// private function declaration 
static unsigned char  KeyScan(void);
/*
------------------------------------------------------------------*-

  KEY_SCAN_Update()

  Must be called once per 10mS.

-*------------------------------------------------------------------
*/
void KEY_SCAN_Update(void)
{
  static unsigned char Duration=0;
  //
  if( KeyScan()==1 )
   {
      Duration+=1;
      //
      if( Duration > 3 )
        {
          KeyScan();
          if( FKeyunProcessed==0 )
            {
              FKeyunProcessed=1;
              KeyValue=GKey;
            }
          Duration=0;
          return;
        }
      //
      return ;
   }
  //
  Duration=0;  
}
/*
********************************************************************************
*
*	Function name :     KeyScan
*
*	Returns :	    Input from user on board Buttons    	
*
*	Parameters :	    none
*
*	Purpose :	    Check if any input from the Buttons
*
********************************************************************************
*/
static unsigned char  KeyScan(void)
{
  GKey=NO_KEY_PRESSED;
  //
  if( !(PINA&(1<<PINA6)) )
    GKey=KEY_UP;
  //
  if( !(PINA&(1<<PINA7)) )
    GKey=KEY_DOWN;
  //
  if( !(PIND&(1<<PIND2)) )
    GKey=KEY_MODE;
  //
  //------------------------//
  //
  if(GKey==NO_KEY_PRESSED)
    return 0;
  else
    return 1;
  
}












⌨️ 快捷键说明

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