资源简介
此资料为GT316L 16通道触摸芯片源码,内涵I2C代码以及datasheet
代码片段和文件信息
/* Includes ------------------------------------------------------------------*/
#include “define.h“
#include “iic.h“
#include “delay.h“
#define P_IIC_SDA(x) ((x) ? GPIO_WriteBit(P_PORT_IIC_SDA P_PIN_IIC_SDA SET) : GPIO_WriteBit(P_PORT_IIC_SDA P_PIN_IIC_SDA RESET))
#define P_IIC_SCL(x) ((x) ? GPIO_WriteBit(P_PORT_IIC_SCL P_PIN_IIC_SCL SET) : GPIO_WriteBit(P_PORT_IIC_SCL P_PIN_IIC_SCL RESET))
#define D_IIC_DELAY_TIMER(x) Delay_halts(x)
/**
* @brief
* @param
* @retval
*/
void IIC_PortInit(void)
{
GPIO_Init(P_PORT_IIC_SDA P_PIN_IIC_SDA GPIO_Mode_Out_OD_HiZ_Fast);
GPIO_Init(P_PORT_IIC_SCL P_PIN_IIC_SCL GPIO_Mode_Out_OD_HiZ_Fast);
}
/**
* @brief
* @param
* @retval
*/
void IIC_SetPortMode(uint8_t state)
{
if(state)
{
GPIO_Init(P_PORT_IIC_SDA P_PIN_IIC_SDA GPIO_Mode_In_FL_No_IT);
}
else
{
GPIO_Init(P_PORT_IIC_SDA P_PIN_IIC_SDA GPIO_Mode_Out_OD_HiZ_Fast);
}
}
/**
* @brief
* @param
* @retval
*/
void IIC_Start(void)
{
IIC_SetPortMode(0);
D_IIC_DELAY_TIMER(1);
P_IIC_SDA(1);
P_IIC_SCL(1);
D_IIC_DELAY_TIMER(5);
P_IIC_SDA(0);
D_IIC_DELAY_TIMER(5);
P_IIC_SCL(0);
D_IIC_DELAY_TIMER(1);
}
/**
* @brief
* @param
* @retval
*/
void IIC_Stop(void)
{
P_IIC_SCL(0);
P_IIC_SDA(0);
D_IIC_DELAY_TIMER(2);
P_IIC_SCL(1);
D_IIC_DELAY_TIMER(5);
P_IIC_SDA(1);
D_IIC_DELAY_TIMER(5);
}
/**
* @brief
* @param
* @retval
*/
uint8_t IIC_WaitAck(void)
{
uint8_t errtime = 0xFF;
uint8_t rtn = 0xFF;
P_IIC_SDA(1);
D_IIC_DELAY_TIMER(2);
IIC_SetPortMode(1);
P_IIC_SCL(1);
D_IIC_DELAY_TIMER(5);
while(GPIO_ReadInputDataBit(P_PORT_IIC_SDA P_PIN_IIC_SDA) != RESET)
{
if (!(errtime--))
{
rtn = 0x00;
break;
}
}
P_IIC_SCL(0);
IIC_SetPortMode(0);
D_IIC_DELAY_TIMER(2);
return rtn;
}
/**
* @brief
* @param
* @retval
*/
void IIC_SendAck(uint8_t ack)
{
if(ack)
{
P_IIC_SDA(1);
}
else
{
P_IIC_SDA(0);
}
D_IIC_DELAY_TIMER(2);
P_IIC_SCL(1);
D_IIC_DELAY_TIMER(5);
P_IIC_SCL(0);
D_IIC_DELAY_TIMER(2);
}
/**
* @brief
* @param
* @retval
*/
void IIC_WriteByte(uint8_t para)
{
uint8_t i;
P_IIC_SCL(0);
D_IIC_DELAY_TIMER(5);
for(i=0; i<8; i++)
{
if(para & 0x80)
{
P_IIC_SDA(1);
}
else
{
P_IIC_SDA(0);
}
para <<= 1;
D_IIC_DELAY_TIMER(1);
P_IIC_SCL(1);
D_IIC_DELAY_TIMER(5);
P_IIC_SCL(0);
}
D_IIC_DELAY_TIMER(2);
}
/**
* @brief
* @param
* @retval
*/
uint8_t IIC_ReadByte(void)
{
uint8_t idata = 0;
IIC_SetPortMode(1);
D_IIC_DELAY_TIMER(2);
for (i=0; i<8; i++)
{
P_IIC_SCL(1);
D_IIC_DELAY_TIMER(2);
data <<= 1;
if(GPIO_ReadInputDataBit(P_PORT_IIC_SDA P_PIN_IIC_SDA) != RESET)
{
data |= 0x01;
}
else
{
D_IIC_DELAY_TIMER(1);
}
D_IIC_DELAY_TIMER(2);
P_IIC_SCL(0);
D_IIC_DELAY_TIMER(5);
}
IIC_SetPortMode(0);
D_IIC_
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-08-25 14:29 GT316L-touch\
文件 563422 2018-08-03 18:14 GT316L-touch\GT316L_Datasheet_v2.80.pdf
文件 3041 2018-08-25 14:27 GT316L-touch\iic.c
文件 298 2018-08-25 14:27 GT316L-touch\iic.h
文件 4014 2018-08-25 14:28 GT316L-touch\touch.c
文件 725 2018-08-25 14:28 GT316L-touch\touch.h
- 上一篇:ANSYS17链接.docx
- 下一篇:MES 接口设计说明书
评论
共有 条评论