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

📄 key_scan.c

📁 环保型IC卡门禁系统的C程序
💻 C
字号:
#include <iom8v.h>
#include <macros.h>
#include "lcd1602.h"

unsigned char Key_Scan(void)
{
  unsigned char Key_1 = 0 , Key_2 = 0 ;
  
  //CLI();
  
  if((PIND&0x04)==0)     
    Key_1 = 1 ;
  else if((PIND&0x02)==0) 
    Key_1 = 2 ;
  else if((PIND&0x01)==0)
    Key_1 = 3 ;
  
  PORTD = 0xf0 ;
  DDRD  = 0x0f ;
  
  if((PIND&0x80)==0)       
    Key_1 += 0 ;
  else if((PIND&0x40)==0)  
    Key_1 += 3 ;
  else if((PIND&0x20)==0)  
    Key_1 += 6 ;
  else if((PIND&0x10)==0)  
    Key_1 += 9 ;
	
  PORTD = 0x0f ;         // 要先写 PORT , 后写 DDR
  DDRD  = 0xf0 ;
  
  delay_nms(80);
  
  if((PIND&0x04)==0)     
    Key_2 = 1 ;
  else if((PIND&0x02)==0) 
    Key_2 = 2 ;
  else if((PIND&0x01)==0)
    Key_2 = 3 ;
	
  PORTD = 0xf0 ;
  DDRD  = 0x0f ;
  
  if((PIND&0x80)==0)       
    Key_2 += 0 ;
  else if((PIND&0x40)==0)  
    Key_2 += 3 ;
  else if((PIND&0x20)==0)  
    Key_2 += 6 ;
  else if((PIND&0x10)==0)  
    Key_2 += 9 ;
	
  PORTD = 0x0f ;         // 要先写 PORT , 后写 DDR
  DDRD  = 0xf0 ;
  
  //SEI();
  
  if(Key_1==Key_2)
  {
    return Key_2 ;
  }
  else
  {
    return 0 ;
  }
}

⌨️ 快捷键说明

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