⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i2c.h

📁 uCOS-II在飞思卡尔AW60的移植程序包
💻 H
字号:
/***************************************************
 *文件名:I2C.h
 *描述:提供I2C的底层驱动,可选的400K或100K速度。
 *日期:2004/11/10
 *****************************************************/
 
 #ifndef I2C_H
 #define	I2C_H

#include <mc9s08aw60.h>
#include "MCUinit.h"
#ifndef TRUE
	#define TRUE	1
	#define true	1
#endif

#ifndef FALSE
	#define	FALSE	0
	#define	false	0
#endif

#ifndef uchar
    #define uchar unsigned char
    #define	UCHAR uchar
#endif

#ifndef uint
    #define uint unsigned int
    #define	UINT uint
#endif

//#ifndef ulong
//    #define ulong unsigned long
//    #define	ULONG ulong
//#endif

#ifndef bool
    #define bool unsigned char
    #define	BOOL bool
#endif

#ifndef CONST
    #define	CONST const
#endif



#ifdef I2C_C
/********************************************内部定义*******************************************/
#define			I2C_100K			0				//100K速度模式
#define			I2C_400K			1				//400K速度模式
/*********************************************配置参数******************************************/
#define			I2C_SPEED			I2C_400K		//配置速度为100K													
													//通讯端口配置		
#define			CLR_SCL()			PTCD_PTCD0=0//P2DIR |= 0X02;P2OUT &= ~0X02		
#define			SET_SCL()			PTCD_PTCD0=1
#define			CLR_SDA()			PTCDD_PTCDD1=1;PTCD_PTCD1=0 //P2DIR |= 0X04;P2OUT &= ~0X04
#define			SET_SDA()			PTCDD_PTCDD1=1;PTCD_PTCD1=1//把数据PTC1口的方向寄存器置为发送态PTCDD_PTCDD1=1

#define			READ_SDA()		PTCD_PTCD1==1  //把数据PTC1口的方向寄存器置为接收态PTCDD_PTCDD1=0

#define			NOP()				asm nop			//空等待

#endif


/********************************************外部接口函数***************************************/

/**********************************************************
 *函数性质:公共
 *入口:无
 *出口:无
 *功能:启动I2C。
 ************************************************************/
void I2cStart(void);


/*****************************************************
 *函数性质:公共
 *入口:无
 *出口:无
 *功能:停止I2C。
 *******************************************************/
void I2cStop(void);


/****************************************************
 *函数性质:公共
 *入口:无
 *出口:应答标志,true:检测到应答标志,false:无应答标志
 *功能:检测从机的应答标志
 *******************************************************/
bool WaitAck(void);


/*******************************************************
 *函数性质:公共
 *入口:无
 *出口:无
 *功能:发送应答标志
 ******************************************************/
void SendAck(void);


/*****************************************************
 *函数性质:公共
 *入口:无
 *出口:无
 *功能:发送非应答标志
 *****************************************************/
void SendNotAck(void);

                         
/*****************************************************
 *函数性质:
 *入口:待发送的字符
 *出口;发送成功标志,true 发送成功  false 发送失败
 *功能:向I2C接口发送一个字符
 *****************************************************/
bool I2cSend(uchar ucData);     


/*******************************************************
 *函数性质:公共
 *入口:无
 *出口:从I2C接口接收到的数据
 *功能:从I2C接口接收一个数据。
 ********************************************************/
uchar I2cReceive(void);

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -