123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- #ifndef __I2C_H__
- #define __I2C_H__
- #pragma library io
- #include <pic18fregs.h>
- #define _I2CPARAM_SPEC __data
- #define I2C_SLAVE10B_INT 0x0f
- #define I2C_SLAVE7B_INT 0x0e
- #define I2C_SLAVE_IDLE 0x0b
- #define I2C_MASTER 0x08
- #define I2C_SLAVE10B 0x07
- #define I2C_SLAVE7B 0x06
- #define I2C_SLEW_OFF 0x80
- #define I2C_SLEW_ON 0x00
- #define I2C_STOP() do { SSPCON2bits.PEN = 1; } while (0)
- #define I2C_START() do { SSPCON2bits.SEN = 1; } while (0)
- #define I2C_RESTART() do { SSPCON2bits.RSEN = 1; } while (0)
- #define I2C_NACK() do { SSPCON2bits.ACKDT = 1; SSPCON2bits.ACKEN = 1; } while (0)
- #define I2C_ACK() do { SSPCON2bits.ACKDT = 0; SSPCON2bits.ACKEN = 1; } while (0)
- #define I2C_IDLE() do { } while ((SSPCON2 & 0x1f) | (SSPSTATbits.R_W))
- #define I2C_DRDY() (SSPSTATbits.BF)
- void i2c_stop(void);
- void i2c_start(void);
- void i2c_restart(void);
- void i2c_nack(void);
- void i2c_ack(void);
- void i2c_idle(void);
- unsigned char i2c_drdy(void);
- unsigned char i2c_readchar(void);
- char i2c_readstr(_I2CPARAM_SPEC unsigned char *ptr, unsigned char len);
- char i2c_writechar(unsigned char dat);
- char i2c_writestr(unsigned char *ptr);
- void i2c_open(unsigned char mode, unsigned char slew, unsigned char addr_brd);
- void i2c_close(void);
- #endif
|