📄 key_scan.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"
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;
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -