Advertisement
Guest User

msspi2c.c

a guest
Sep 14th, 2012
898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include <xc.h>
  2.  
  3. void i2cWait(void)
  4. {
  5.     while(SSPCON2 && 0b00011111);
  6.     PIR1bits.SSPIF = 0;
  7. }
  8.  
  9. void i2cStartBit(void)
  10. {
  11.     SSPCON2bits.SEN = 1;
  12.     i2cWait();
  13. }
  14.  
  15. void i2cRestartBit(void)
  16. {
  17.     SSPCON2bits.RSEN = 1;
  18.     i2cWait();
  19. }
  20.  
  21. void i2cSend(char a)
  22. {
  23.     PIR1bits.SSPIF = 0;
  24.     SSPBUF = a;
  25.     while(!PIR1bits.SSPIF);
  26.     PIR1bits.SSPIF = 0;
  27. }
  28.  
  29. char i2cReceive(void)
  30. {
  31.     SSPCON2bits.RCEN = 1;
  32.     i2cWait();
  33.     return SSPBUF;
  34. }
  35.  
  36. void i2cAckNack(void)
  37. {
  38.     SSPCON2bits.ACKEN = 1;
  39.     i2cWait();
  40. }
  41.  
  42. void i2cStop(void)
  43. {
  44.     SSPCON2bits.PEN = 1;
  45.     i2cWait();
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement