?? keyboard.c
字號:
/****************************************Copyright (c)**************************************************/
/**
;** 西南科技大學計算機科學學院
;**
;** http://www.cs.suswt.edu.cn
;**
;** 日期: 2007.09.21
;** 描述: keyboard.c 西南科技大學計算機學院CS-II型實驗板鍵盤工作程序,控制
;** 鍵盤掃描功能,負責將數據傳輸到目標,并控制595對鍵盤進行掃描,
;** 完成鍵盤工作的功能
;** 作者:miracle
;**
;**--------------keyboard.c文件
;**------------------------------------------------------------------------------------------------------*/
/**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#define _KEYBOARD_C_
#ifdef _KEYBOARD_C_
/************************************************
* Header File *
***********************************************/
#include "config.h"
#include "keyboard.h"
/************************************************
* Globale variable *
***********************************************/
uint8 gc_key_bit = 0x00;
/******************************************************************************
* Function Name: KEYInit *
* Description : 鍵盤端口初始化 *
*****************************************************************************/
void KEYInit(void)
{
PINSEL0 &= KEYBOARD_SMAT;
IO0DIR |= KEYBOARD_SCK;
IO0DIR |= KEYBOARD_RCK;
IO0DIR |= KEYBOARD_SI;
IO0DIR &= (KEYBOARD_KEY^0XFFFFFFFF);
}
/******************************************************************************
* Function Name: KEYSendWord
* Description : 向595端口傳一個字數據。用來選重鍵盤位的。其中比有且只有一位為0 *
*****************************************************************************/
void KEYSendWord(uint16 display_data)
{
uint8 send_keycount;
IO0CLR=KEYBOARD_RCK;
for(send_keycount=0x00;send_keycount<0x10;send_keycount++)
{
IO0CLR=KEYBOARD_SCK;
if((display_data&(0x01<<send_keycount))==0x00)//注意運算符號的優先級
{
IO0CLR = KEYBOARD_SI;
}
else
{
IO0SET = KEYBOARD_SI;
}
IO0SET=KEYBOARD_SCK;
}
IO0SET=KEYBOARD_RCK;
}
/******************************************************************************
* Function Name: KEYSendBit *
* Description : 向595端口傳輸一位為1的數據,可以通過它讓595中的數據移位 *
*****************************************************************************/
void KEYSendBit()
{
IO0CLR=KEYBOARD_RCK;
IO0CLR=KEYBOARD_SCK;
IO0SET=KEYBOARD_SI;
IO0SET=KEYBOARD_SCK;
IO0SET=KEYBOARD_RCK;
}
/******************************************************************************
* Function Name: KEYScan *
* Description : 掃描鍵盤,并給予返回值,掃描的方式是通過移位的方式來進行的 *
*****************************************************************************/
uint8 KEYScan(void)
{
/*for(Key_Bit=0x00;Key_Bit<0x10;Key_Bit++)
{
if(Key_Bit==0x00)
{
Keyboard_Sendword(0x7fff);
}
else
{
//Speak();
Keyboard_Sendbit();
}
if((IO0PIN&Keyboard_KEY)==0)
{
//Speak();
if(Key_Bit==0)
{
Speak();
}
return Key_Bit;
}
}
return 0xff;*/
//Speak();
if(gc_key_bit==0x00) //兩處注釋分別為另外兩種方法
{
KEYSendWord(0x7fff);
}
else
{
KEYSendBit();
}
if((IO0PIN&KEYBOARD_KEY)==0x00)
{
//Speak();
return gc_key_bit;
}
gc_key_bit++;
if(gc_key_bit==0x10)
{
gc_key_bit=0x00;
}
if((IO0PIN&KEYBOARD_KEY)!=0)
{
//Speak();
return 0xff;
}
/* if((IO0PIN&Keyboard_KEY)==0)
{
return Key_Bit;
}
else
{
if(Key_Bit==0x0f)
{
Key_Bit=0;
Keyboard_Sendword(0x7fff);
}
else
{
Key_Bit++;
Keyboard_Sendbit();
}
return 0xff;
}*/
return 0;
}
#endif
/*****************************************************************************
* End of Entire File *
****************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -