Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <xc.h>
- void i2cWait(void)
- {
- while(SSPCON2 && 0b00011111);
- PIR1bits.SSPIF = 0;
- }
- void i2cStartBit(void)
- {
- SSPCON2bits.SEN = 1;
- i2cWait();
- }
- void i2cRestartBit(void)
- {
- SSPCON2bits.RSEN = 1;
- i2cWait();
- }
- void i2cSend(char a)
- {
- PIR1bits.SSPIF = 0;
- SSPBUF = a;
- while(!PIR1bits.SSPIF);
- PIR1bits.SSPIF = 0;
- }
- char i2cReceive(void)
- {
- SSPCON2bits.RCEN = 1;
- i2cWait();
- return SSPBUF;
- }
- void i2cAckNack(void)
- {
- SSPCON2bits.ACKEN = 1;
- i2cWait();
- }
- void i2cStop(void)
- {
- SSPCON2bits.PEN = 1;
- i2cWait();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement