📄 key_ment._c
字号:
/*****************************************************
* File name : Keyscan.C
* Description : Header file of LCD_S.H
* Platform : ICCAVR
* Author : xiao xue
* Email : ay1509@yahoo.com
* Date : 2008-03-13
* Description :Keyboard Scan
*********************头文件**************************/
#include"main_H.h"
/***************************************************
*函 数:KeyScan
*函数功能:按键扫描程序
*入口参数:无
*返 回 值:键码
*备 注:
****************************************************/
uchar Keyscan(void)
{
uchar KeyCode=0x00;
if((PIND&0xfb)==0xfb) //判断有无键按下,没有则直接返回
return(0);
else{
delay_nms(15); //延时去抖动
KeyCode = PIND&0xfb;//获得D口键值
if (KeyCode == 0xfb)//再次继续判断有无键按下,无则返回
return(0);
while ((PIND&0xfb) != 0xfb); //等待弹起
delay_nms(15); //延时去抖动
while ((PIND&0xfb) != 0xfb); //再次判断是否弹起
switch(KeyCode){
case 0xf3:return(1);break; //按键1
case 0xeb:return(2);break; //按键2
case 0xdb:return(3);break; //按键3
case 0xbb:return(4);break;
case 0x7b:return(5);break;
default: return(6);break; //其他特殊情况
}//end switch
}//end else
}
/***************************************************
*函 数:KeyInit
*函数功能:按键端口初始化
*入口参数:无
*返 回 值:无
*备 注:
****************************************************/
void KeyInit(void)
{
DDRD=0x04; //键盘初化
PORTD=0xfb; //键盘初值
}
/***************************************************
*函 数:data_memory
*函数功能:对键盘设定的数据进行存储
*入口参数:无
*返 回 值:无
*备 注:
****************************************************/
void data_memory(void)
{
switch(temp){ //存储运动模式
case 0: p=Pretty;break; //天女散花
case 1: p=Thest;break; //扩胸运动
case 2: p=Armup;break; //振臂运动
case 3: p=Armdown;break; //甩臂运动
}//end switch
switch(temp1){ //存储幅度值
case 0: status[1]=0x3C;break;
case 1: status[1]=0x46;break;
case 2: status[1]=0x50;break;
case 3: status[1]=0x5A;break;
case 4: status[1]=0x64;break;
}
switch(temp2){ //存储时间值
case 0: status[2]=300;break;
case 1: status[2]=600;break;
case 2: status[2]=900;break;
case 3: status[2]=1200;break;
case 4: status[2]=1500;break;
}
moto1[2]=status[0]; //存储模式控制字
moto2[2]=status[0];
moto3[2]=status[0];
moto4[2]=status[0];
page=3; //显示参数值运动界面
flag=1; //flag=1液晶显示
}
/************************键盘处理函数************************/
void Keyment(void)
{
uchar Key=0;
Key=Keyscan(); //键盘扫描函数
if(page==1){ //页面1
switch(Key){ //判断返回的键值
case 1: status[0]=0x87; page=2;flag=1;break; //被动模式
case 2: status[0]=0x78; page=2;flag=1;break; //主动模式
case 3: status[0]=0x69; page=2;flag=1;break; //助力模式
case 4: status[0]=0x5A; page=2;flag=1;break; //阻力模式
default:break;
}
} //end if
else if(page==2){ //页面2
switch(Key){ //判断返回的键值
case 1:
temp++;
if(temp==4) temp=0; //被动模式选择
if(temp==0) temp1=3,temp3=4; //天女散花,幅度与力量
if(temp==1) temp1=2,temp3=3; //阔胸运动,幅度与力量
if(temp==2) temp1=3,temp3=2; //振臂运动,幅度与力量
if(temp==3) temp1=4,temp3=2; //甩臂运动,幅度与力量
page=2;flag=1;break; //显示页面2,页面显示标志
case 2: //幅度值设定
temp1++; //递增
if(temp1==5) //到达最大值后清零
temp1=0;
page=2;flag=1; //显示标志
break;
case 3: //时间值设定
temp2++; //递增
if(temp2==5) //到达最大值后清零
temp2=0;
page=2;flag=1; //显示标志
break;
case 4: //力量值设定
temp3++; //递增
if(temp3==5) //到达最大值后清零
temp3=0;
page=2;flag=1; break;
case 5: { //开始键
TIMSK=0x04; //开始键、打开定时器
data_memory(); //存储设定值函数
}//end case
} //end switch
}//end else if
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -