|
微信圖片_20180928193012.png (79.58 KB, 下載次數(shù): 69)
下載附件
2018-10-12 14:27 上傳
這個(gè)程序看了兩天了,還是看不是很明白,看的腦瓜疼。所以來求助大家。
現(xiàn)在最弄不明白的是這些按位與和或的做用到底是什么�。� PORTC |= KEYSCAN_OUTH; PORTC &= KeyOut_Table[pt];
順便也解釋一下紅色字體的。
#include "Global.h"
/*********************************************************************************************************/
s_Key Key;
#define SC_LINE 2 //inpu
#define SC_ROW 2 //outpu
#define KEYPRESS_RELEASE ((PORTC&0x06) ^ 0x06) // PC2,1 as input TURE:按鍵中 FALSE:按鍵釋放
#define KEYSCAN_OUTH _0000_1000 //PC3 output high
const unsigned char KeyOut_Table[SC_ROW] = {0xFF,0xF7,}; //GND PC3
/*********************************************************************************************************/
void KeyScan_Process(void)//按鍵掃描過程
{
unsigned char pt;//,keytemp;
unsigned char ReadState;
for(pt = 0;pt < SC_ROW;pt++)
{
PORTC |= KEYSCAN_OUTH;
PORTC &= KeyOut_Table[pt];
ReadState = KEYPRESS_RELEASE;
if (ReadState)
{
Key.value = NO_PRESS;
switch(ReadState)
{
case 0x02:
Key.value = SC_LINE*pt + 1; break;
case 0x04:
Key.value = SC_LINE*pt + 2; break;
default:break;
}
break;
}
}
PORTC &= ~KEYSCAN_OUTH;//used P15(output "L")
/****************************************************
//for longkey press
/***************************************************/
ReadState = KEYPRESS_RELEASE; // 不按 短按 長按
Key.Trg = ReadState & (ReadState ^ Key.Cont); // 0 1 0
Key.Cont = ReadState; // 0 1 1
if (Key.Trg)
{
Key.Count = 0;
Key.Trg_flag = 1;
Key.state = SHORT_PRESS;
}
}
|
|