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

📄 main.c

📁 基于lpc2148的按键扫描程序
💻 C
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzou ZLG-MCU Development Co.,LTD.
**                                      graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:			main.c
** Last modified Date:  2004-09-16
** Last Version:		1.0
** Descriptions:		The main() function example template
**
**------------------------------------------------------------------------------------------------------
** Created by:			Chenmingji
** Created date:		2004-09-16
** Version:				1.0
** Descriptions:		The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include "config.h"
#include  "lcd_12232.h"
#define KP_OUT0	 0,17	 
#define KP_OUT1	 0,18	  
#define KP_OUT2	 0,19	 
#define KP_OUT3	 0,20	  
#define KP_IN0	 0,0
#define KP_IN1	 0,1	 
#define KP_IN2	 0,9	 
#define KP_IN3	 0,11 
#define uchar    unsigned char  

void DelayNS (uint32 dly)
{
 uint32 i;
 for ( ; dly>0; dly--)
 for (i=0; i<50000; i++);
}

void Io_SetK(uchar group,uchar key)	   
{
unsigned int io_data=1;
io_data=io_data<<key;
if (group==0)
 IO0SET=io_data;        
else
 IO1SET=io_data; 
}

void Io_ClrK(uchar group,uchar key)	  
{
unsigned int io_data=1;
io_data=io_data<<key;
if (group==0)
 IO0CLR=io_data;        
else
 IO1CLR=io_data; 
}

unsigned int Io_PinK(uchar group,uchar key)	 
{
unsigned int io_data=1,s;
io_data=io_data<<key;
if (group==0)
 {
 s=(IO0PIN&io_data);        
 return s;
 }
else
 {
 s=(IO1PIN&io_data);        
 return s;
 }
}

void Io_DirK(uchar group,uchar key)	  
{
unsigned int io_data=1;
io_data=io_data<<key;
if (group==0)
 IO0DIR|=io_data;         
else
 IO1DIR|=io_data;
}


int key_scan_init(void)
{
Io_DirK(KP_OUT0);
Io_DirK(KP_OUT1);
Io_DirK(KP_OUT2);
Io_DirK(KP_OUT3);	
return 1;
}


int key_scan (void)
{

Io_SetK(KP_OUT0);	
Io_ClrK(KP_OUT1);
Io_ClrK(KP_OUT2);
Io_ClrK(KP_OUT3);
if(Io_PinK(KP_IN0))
{
 DelayNS (10);
 if(Io_PinK(KP_IN0))
 {
 DelayNS (15);
 return 1;
 }
}
if(Io_PinK(KP_IN1))
{
 DelayNS (10);
 if(Io_PinK(KP_IN1))
 {
 DelayNS (15);
 return 2;
 }
} 
if(Io_PinK(KP_IN2))
{
 DelayNS (10);
 if(Io_PinK(KP_IN2))
 {
 DelayNS (15);
 return 3;
 }
}
if(Io_PinK(KP_IN3))
{
 DelayNS (10);
 if(Io_PinK(KP_IN3))
 {
 DelayNS (15);
 return 4;
 }
}
  
Io_ClrK(KP_OUT0);	
Io_SetK(KP_OUT1);
Io_ClrK(KP_OUT2);
Io_ClrK(KP_OUT3);
if(Io_PinK(KP_IN0))
{
 DelayNS (10);
 if(Io_PinK(KP_IN0))
 {
 DelayNS (15);
 return 5;
 }
}
if(Io_PinK(KP_IN1))
{
 DelayNS (10);
 if(Io_PinK(KP_IN1))
 {
 DelayNS (15);
 return 6;
 }
}  
if(Io_PinK(KP_IN2))
{
 DelayNS (10);
 if(Io_PinK(KP_IN2))
 {
 DelayNS (15);
 return 7;
 }
}  
if(Io_PinK(KP_IN3))
{
 DelayNS (10);
 if(Io_PinK(KP_IN3))
 {
 DelayNS (15);
 return 8;
 }
}

      
Io_ClrK(KP_OUT0);	
Io_ClrK(KP_OUT1);
Io_SetK(KP_OUT2);
Io_ClrK(KP_OUT3);
if(Io_PinK(KP_IN0))
{
 DelayNS (10);
 if(Io_PinK(KP_IN0))
 {
 DelayNS (15);
 return 9;
 }
}
if(Io_PinK(KP_IN1))
{
 DelayNS (10);
 if(Io_PinK(KP_IN1))
 {
 DelayNS (15);
 return 10;
 }
}  
if(Io_PinK(KP_IN2))
{
 DelayNS (10);
 if(Io_PinK(KP_IN2))
 {
 DelayNS (15);
 return 11;
 }
} 
if(Io_PinK(KP_IN3))
{
 DelayNS (10);
 if(Io_PinK(KP_IN3))
 {
 DelayNS (15);
 return 12;
 }
}


Io_ClrK(KP_OUT0);	
Io_ClrK(KP_OUT1);
Io_ClrK(KP_OUT2);
Io_SetK(KP_OUT3);
if(Io_PinK(KP_IN0))
{
 DelayNS (10);
 if(Io_PinK(KP_IN0))
 {
 DelayNS (15);
 return 13;
 }
}
if(Io_PinK(KP_IN1))
{
 DelayNS (10);
 if(Io_PinK(KP_IN1))
 {
 DelayNS (15);
 return 14;
 }
}  
if(Io_PinK(KP_IN2))
{
 DelayNS (10);
 if(Io_PinK(KP_IN2))
 {
 DelayNS (15);
 return 15;
 }
}  
if(Io_PinK(KP_IN3))
{
 DelayNS (10);
 if(Io_PinK(KP_IN3))
 {
 DelayNS (15);
 return 16;
 }
}
return 0;
}


int main(void)
{
int key=0;
key_scan_init();
 lcd_init();
 
 while(1)
 {
  key=key_scan();
 Draw_char(key/10,1,1,8);
 Draw_char(key%10,10,1,8);
 }
 return 1;
}
/*********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

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