?? keyboard.c
字號:
#include <AT89X55.H>
#include<absacc.h>
#include <string.h>
#include "keyboard.h"
/******************************* 顯示字符*****************************************/
void print(char *pdat)
{
int i,len;
len = strlen(pdat);
for(i=0;i<len;i++)
{
SBUF = pdat[i];
while(TI != 1)
{
;
}
TI = 0;
}
}
/*******************************顯示數字*****************************************/
void printhex(ulong dat)
{
uchar temp;
char i;
for(i=28;i>=0;i=i-4)
{
temp = (dat)>>i;
temp = temp&0xf;
if(temp >= 0 && temp <=9) temp = temp + '0';
else if(temp >= 0xa && temp <= 0xf) temp = temp + '0' +7;
SBUF = temp;
while(TI != 1)
{
;
}
TI = 0;
}
}
/******************************* 8279延遲函數*****************************************/
void delay8279()
{
int i;
for(i=0;i<200;i++);
}
/******************************* 向8279發命令*****************************************/
uchar SendCom(uchar com)
{
A1 = 0; // A1 = P3^5; 定時器 T1
A0 = 0; // A0 = P3^4; 定時器 TO
A08279 = 1; //the signale in or out are interpreted as a command or status
Com8279 = com;
delay8279();
return 0;
}
/******************************* 8279讀數據*****************************************/
uchar GetFiFoStatus()
{
uchar temp;
A08279 = 1; //
A0 = 0; // A0 = P3^4; 定時器 TO
A1 = 0; // A1 = P3^5; 定時器 T1
temp = Dat8279;
return temp;
}
/******************************* 8279讀數據*****************************************/
uchar RdData()
{
uchar temp; //i,num;
A1 = 0;
A0 = 0;
SendCom(0x40); // read FIFO
A08279 = 0; // 數據
temp = Dat8279;
return temp;
}
/******************************* 初始化8279*****************************************/
Init8279()
{
EX1 = 1; //外中斷1中斷允許
IE1 = 0; //INT1中斷請求標志位,有外部中斷請求時置1,
IT1 = 1; //INT1 觸發方式控制位 ,為負跳變觸發方式
A1 = 0;
A0 = 0;
SendCom(0); //設置鍵盤工作方式 兩鍵鎖定
SendCom(0x20 | 18); //設置時鐘頻率 大約為100KHZ
return 1;
}
/******************************* 外中斷INT1******************************************/
void KeyIsr() interrupt 2 using 0
{
uchar temp;
print("int1\r\n");
temp = RdData();
if(temp == 0) return ;
print("in int data is:");
printhex(temp);
print("\r\n");
print("test 8 :");
printhex(0x8);
print("\r\n");
IE1 = 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -