?? i2c.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 + -