?? keystate.c
字號:
/******************************************************************************/
//鍵盤掃描
/******************************************************************************/
#include <msp430x14x.h>
unsigned char state1 = 1,state2 = 0xf0;
unsigned char key_value;
/******************************************************************************/
//功能:鍵盤處理程序
/******************************************************************************/
void key_main(void)
{
Init_Port();
key_state();
}
/******************************************************************************/
//初始化IO口
/******************************************************************************/
void Init_Port(void)
{
//將P2口所有的管腳在初始化的時候設置為輸入方式
P2DIR = 0;
//將P2口所有的管腳設置為一般I/O口
P2SEL = 0;
// 將P2.4 P2.5 P2.6 P2.7設置為輸出方向
P2DIR |= BIT4;
P2DIR |= BIT5;
P2DIR |= BIT6;
P2DIR |= BIT7;
//先輸出低電平
P2OUT = 0x00;
return;
}
/******************************************************************************/
//獲取鍵值
/******************************************************************************/
int KeyProcess(void)
{
int nP20,nP21,nP22,nP23;
int nRes = 0;
//P2.4輸出低電平
P2OUT &= ~(BIT4);
nP20 = P2IN & BIT0;
if (nP20 == 0) nRes = 13;
nP21 = P2IN & BIT1;
if (nP21 == 0) nRes = 14;
nP22 = P2IN & BIT2;
if (nP22 == 0) nRes = 15;
nP23 = P2IN & BIT3;
if (nP23 == 0) nRes = 16;
//P2.5輸出低電平
P2OUT &= ~(BIT4);
nP20 = P2IN & BIT0;
if (nP20 == 0) nRes = 9;
nP21 = P2IN & BIT1;
if (nP21 == 0) nRes = 10;
nP22 = P2IN & BIT2;
if (nP22 == 0) nRes = 11;
nP23 = P2IN & BIT3;
if (nP23 == 0) nRes = 12;
//P2.6輸出低電平
P2OUT &= ~(BIT4);
nP20 = P2IN & BIT0;
if (nP20 == 0) nRes = 5;
nP21 = P2IN & BIT1;
if (nP21 == 0) nRes = 6;
nP22 = P2IN & BIT2;
if (nP22 == 0) nRes = 7;
nP23 = P2IN & BIT3;
if (nP23 == 0) nRes = 8;
//P2.7輸出低電平
P2OUT &= ~(BIT4);
nP20 = P2IN & BIT0;
if (nP20 == 0) nRes = 1;
nP21 = P2IN & BIT1;
if (nP21 == 0) nRes = 2;
nP22 = P2IN & BIT2;
if (nP22 == 0) nRes = 3;
nP23 = P2IN & BIT3;
if (nP23 == 0) nRes = 4;
P2OUT = 0x00;//恢復以前值。
return nRes;
}
/******************************************************************************/
//模塊功能:狀態確認
/******************************************************************************/
void key_state(void)
{
unsigned char k_state;
P2OUT = 0;
k_state = P2IN;
if(k_state==0xf0) //判斷是否有按鍵按下
{
if(state1==0xf0) //判斷現在的鍵值是一還是零
{
state1 = 1;
}
else
{
state1 = k_state;
state1 = 0x08;
}
}
else
{
if(state1==0xf0)
{
state1 = 0x02;
state1 = 0;
}
else
{
state1 = k_state;
state1 = 0x04;
}
}
state2 = k_state;
state1 <<= 1;
}
else
{
}
switch(state1) //按鍵處在的狀態級
{
case1:
break;
case2:
break;
case4:
key_value = KeyProcess();
break;
case8:
key_value //調用相應的按鍵處理程序
state1 = 1;
break;
default:
break;
}
}
/******************************************************************************/
//按鍵處理程序
/******************************************************************************/
void key_act(void) //相應按鍵對應的處理程序
{
switch(i)
{
case 1:
CO2setpoint(); //CO2濃度設置
break;
case 2:
CO2deadband();
break;
case 3:
CO2calibrate();
break;
case 4:
tempsetpoint();
break;
case 5:
T_max();
break;
case 6:
tempdeadband();
break;
case 7:
tempcalibrate();
break;
case 8:
mode();
break;
case 9:
cancel();
break;
case 10:
restrore_factory();
break;
case 11:
confirm();
break;
case 12:
UP();
break;
case 13:
Down();
break;
case 14:
time();
break;
case 15:
break;
case 16:
break;
default:
break;
}
key_value = 0;
}
void CO2setpoint(void)
{
}
void CO2deadband(void)
{
}
void CO2calibrate(void)
{
}
void tempsetpoint(void)
{
}
void tempdeadband(void)
{
}
void tempcalibrate(void)
{
}
void mode(void)
{
}
void T_max(void)
{
}
void cancel(void)
{
}
void restrore_factory(void)
{
}
void confirm(void)
{
}
void UP(void)
{
}
void Down(void)
{
}
void time(void)
{
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -