📄 i2c_start.c
字号:
/***************************** File Message *******************************
** File Name : I2C.c
** created by: ZhangBinn
** Last modified: 12/28/04 (MM/DD/YY)
** Description: this file is specified for I2C devices,such as 24LC32
***************************************************************************/
#include <pic.h>
#include "delay.h"
#include "define.h"
/* I2C module uses PORT C */
#define I2C_CTRL TRISC
#define I2C_LINE PORTC
#define SCL RC3 /* clock on port C bit 3 */
#define SCL_DIR TRISC3
#define SCL_DIR_IN() (SCL = 1)
#define SCL_DIR_OUT() (SCL = 0)
#define SDA RC4 /* data on port C bit 4 */
#define SDA_DIR TRISC4
#define SDA_DIR_IN() (SDA = 1)
#define SDA_DIR_OUT() (SDA = 0)
#define __I2C_DELAY 20
#define I2C_DELAY() DelayNus(__I2C_DELAY)
#define RD_ID 0xA1
#define WR_ID 0xA0
/*************************** Function Message ****************************
** Funtion Name : I2C_Start
** Arguments: BYTE bComOrder: the communication order
** Return Value: return the communication status
** Restrictions: none
** created by: ZhangBin
** Last modified: 12/2/04 (MM/DD/YY)
** Description: the main program of the EOS System
***************************************************************************/
void I2C_Start(void)
{
SDA_DIR = 0;
SCL_DIR = 0;
SDA_DIR_IN(); //SDA = 1;
I2C_DELAY();
SCL_DIR_IN(); // SCL = 1;
I2C_DELAY();
SDA_DIR_OUT(); // SDA = 0;
I2C_DELAY();
SCL_DIR_OUT(); // SCL = 0;
};
/*************************** Function Message ****************************
** Funtion Name : I2C_ReStart
** Arguments: BYTE bComOrder: the communication order
** Return Value: return the communication status
** Restrictions: none
** created by: ZhangBin
** Last modified: 12/2/04 (MM/DD/YY)
** Description: the main program of the EOS System
***************************************************************************/
void I2C_ReStart(void)
{
SCL_DIR_OUT(); // SCL = 0;
SDA_DIR_IN(); // SDA = 1;
I2C_DELAY();
SCL_DIR_IN(); // SCL = 1;
I2C_DELAY();
SDA_DIR_OUT(); // SDA = 0;
I2C_DELAY();
SCL_DIR_OUT(); // SCL = 0;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -