📄 i2c.h
字号:
// ./i2c.h start
//
/*----------------------------------------------------------------------------------**
** Driver: I2C Bus Device Driver Package for M16C/62 serires MCUs. **
** (c) 1999 Mitsubishi Electronics America, Inc. **
** Three Diamond Lane **
** Durham, North Carolina 27704 USA **
** Ph 919-479-3333 **
** File: i2c.h **
** Discription: This multi-master driver provides the software interface to the **
** I2C Bus hardware of the M3062x series of Mitsubishi's MCU. **
**----------------------------------------------------------------------------------*/
/*-----------------------------------------------**
** Please make the following settings. **
**-----------------------------------------------*/
#define MAIN_CLOCK 16e6 // Main Clock speed of MCU.
#define CLOCK_DIV 1 // Main Clock divide ratio.
#define I2C_BUS_SPEED 200e3 // I2C Bits per second rate.
#define GET_ERROR_MES_RET 0 // 0 for beggining of message "Use for debugging"
// 1 for error value.
//------- Do not edit below this line. ------------------------------------------------
// The following 7 functions should be called by the user's application.
// iic_ini is called to initialize slave operations.
extern void iic_ini(unsigned char,unsigned char*);
// init_i2c_busy_flag is called to initailization baudrate, main clock speed, ETC.
extern void init_i2c_mas_func(void);
// iic_stop is called to disable I2C bus communications.
extern unsigned char iic_stop(void);
// iic_mr_start is called to begin master read data tranfers.
extern unsigned char iic_mr_start(unsigned char,unsigned char*,unsigned char);
// iic_mw_start is called to begin master write dta transfers.
extern unsigned char iic_mw_start(unsigned char,unsigned char*,unsigned char);
// check_i2c_bus_statur is call to check the status of the bus opperation.
extern unsigned char check_i2c_bus_status(unsigned char i);
// To get the current error code for the status call Get_error_mass
extern char far* Get_error_mass(void);
#pragma PARAMETER iic_ini(R0H,A0)
#pragma PARAMETER iic_mr_start(R0H,A0,R0L)
#pragma PARAMETER iic_mw_start(R0H,A0,R0L)
#ifndef I2C_C
extern unsigned char lng; // Number of data bytes transfered by Master.
extern unsigned char I2C_bus_busy; // Bus busy flag.
extern unsigned char status; // Current status of bus.
extern unsigned char iic_ram[128]; // Slave Ram.
#else
// The next two functions listed are for internal processing only.
void iic_mw_end(unsigned char MW_STATUS, unsigned char MW_LNG);
void iic_mr_end(unsigned char MR_STATUS,unsigned char MR_LNG);
// --------------------------------------------------------------------------------------------------
// The following defines set up static values used in assembley langage code.
// Original times "DELAY_2USEC" are based on 16MHZ main clock, clock divide ratio of 1, and
// BAUD rate of 100k bits per second. The delay values and baudrate will automatically
// be properly programmed when this library is compiled for the target system.
#define I2C_BUS_BAUDRATE ((unsigned char) ((MAIN_CLOCK / (2 * CLOCK_DIV * I2C_BUS_SPEED)) - 1) )
#define COUNTER_RATIO ((float)((CLOCK_DIV * 5.0)/MAIN_CLOCK)) // Delay_counter executes in 5 clock cycles.
#define BAUD_RATE_ADJUST ((float)(100e3 / I2C_BUS_SPEED ))
#define DELAY_2USEC ((unsigned int)(2e-6 * BAUD_RATE_ADJUST / COUNTER_RATIO ))
#define DELAY_4USEC ((unsigned int)(4e-6 * BAUD_RATE_ADJUST / COUNTER_RATIO ))
#define DELAY_5USEC ((unsigned int)(5e-6 * BAUD_RATE_ADJUST / COUNTER_RATIO ))
#define DELAY_15USEC ((unsigned int)(15e-6 * BAUD_RATE_ADJUST / COUNTER_RATIO ))
#define DELAY_20USEC ((unsigned int)(20e-6 * BAUD_RATE_ADJUST / COUNTER_RATIO ))
// --------------------------------------------------------------------------------------------------
#endif
/*-----------------------------------------------------------**
** Use enum data type for both MW_END and MR_END functions. **
**-----------------------------------------------------------*/
enum I2C_status_Responses {
Master_transmission_completed_normally = 0,
Slave_returned_NACK_in_the_first_byte,
Slave_returned_NACK_in_data_region,
BUS_competition_detected_and_master_operation_completed,
Improper_start_condition_detected,
Improper_stop_condition_detected
};
/*-------------------------------------------**
** Use enum data tyype for status of bus. **
**-------------------------------------------*/
enum I2C_status_flags {
Not_busy = 0,
Busy,
Set_flag
};
// ./i2c.h end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -