資源簡(jiǎn)介
直接調(diào)用接口,單獨(dú)獲取鍵值,精準(zhǔn),穩(wěn)定。同時(shí)為C語(yǔ)言開發(fā),精簡(jiǎn),方便,適合各類微處理器移植。

代碼片段和文件信息
/**********************************
CY?為單片機(jī)CY位,移植時(shí)可根據(jù)芯片更改
**********************************/
#include?“BS8116A.h“
void?BS8116A_int()
{
GPIO_InitTypeDef GPIO_InitStructure; ??????????
GPIO_InitStructure.Pin??=?GPIO_Pin_0?|?GPIO_Pin_1;
GPIO_InitStructure.Mode?=?GPIO_OUT_OD;
GPIO_Inilize(GPIO_P3&GPIO_InitStructure);
}
void?BS8116A_Start()
{
SDA?=?1;??????
SCL?=?1;?
Delay5us();?
SDA?=?0;?
Delay5us();?
SCL?=?0;?
}
void?BS8116A_Stop()
{
SDA?=?0;???????????????
SCL?=?1;????????
Delay5us();???????
SDA?=?1;???????
Delay5us();??????????
}
bit?BS8116A_RecvACK()
{
SCL?=?1;??????????????????
Delay5us();???????????????
CY?=?SDA;?????????????????
SCL?=?0;??????????????????
Delay5us();???????????????
return?CY;
}
void?BS8116A_SendByte(u8?dat)
{
u8?i;
for?(i=0;?i<8;?i++)?????????
{
dat?<<=?1;???????????
SDA?=?CY;????????????
SCL?=?1;?????????????
Delay5us();??????????
SCL?=?0;?????????????
Delay5us();??????????
}
BS8116A_RecvACK();
}
u8?BS8116A_RecvByte()
{
????u8?i;
????u8?dat?=?0;
????SDA?=?1;???????????????
????for?(i=0;?i<8;?i++)????
????{
????????dat?<<=?1;
????????SCL?=?1;???????????
????????Delay5us();????????
????????dat?|=?SDA;????????
????????SCL?=?0;???????????
????????Delay5us();????????
????}
????return?dat;
}
//0---ACK1---NACK
void?BS8116A_SendACK(bit?ack)
{
????SDA?=?ack;????????????
????SCL?=?1;??????????????
????Delay5us();???????????
????SCL?=?0;??????????????
????Delay5us();???????????
}
u8?Get_Key(u8?dat)
{
u8?Temp;????????????????????
BS8116A_Start();?????????????//起始
BS8116A_SendByte(0xA0);??????//發(fā)送
BS8116A_SendACK(0);??????????//ack
BS8116A_SendByte(dat);???????//發(fā)送
BS8116A_SendACK(0);??????????//ack
BS8116A_Start();?????????????//起始
BS8116A_SendByte(0xA1);??????//發(fā)送
BS8116A_SendACK(0);??????????//ack
Temp?=?BS8116A_RecvByte();???//讀取
BS8116A_SendACK(1);??????????//nack
BS8116A_Stop();??????????????//結(jié)束
return?Temp;
}
void?main()
{
u8??Key_HKey_L;
u16?Key;
while(1)
{
Key_H?=?Get_Key(0x09);
Key_L?=?Get_Key(0x08);
Key?=?(Key_H<<8)?|?Key_L;
printf(“Key?value:%X\n“Key);
delay_ms(200);
}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????2343??2018-08-08?15:28??BS8116A.c
?????文件????????350??2018-08-08?15:25??BS8116A.h
?????文件?????873635??2018-08-08?09:32??simBS81xA-xv150.pdf
-----------?---------??----------?-----??----
???????????????876328????????????????????3
評(píng)論
共有 條評(píng)論