/* * File: I2C_Main.c * Author: datpa * * Created on 5. november 2015, 13:36 */#include <xc.h>#include "I2C_Header.h"//const char display[10] = {// tal0, tal1, tal2, tal3, tal4, tal5, tal6, tal7, tal8, tal9 };char tal = 0;char read_temp = 0b01001011;void main (void) { ANSELB= 0x00; TRISB=252; OPTION_REG=0b00000101; ANSELA=0x00; TRISA=0; INTCONbits.IOCIE=1; INTCONbits.GIE=1; IOCBNbits.IOCBN2=1; SSP2CON1 = 0b00101000; SSP2ADD = 39; OSCCON=0b01111010; while(1){ char ener = 0; char tier = 0; SSPCON2bits.SEN = 1; //Start flag while (SSPCON2bits.SEN) {}; PIR4bits.SSP2IF = 0; //make sure the interrups is cleared //addr<<1 = move one to the left (roter) 00111110 = 01111100 SSP2BUF = 0b10010111; while(PIR4bits.SSP2IF == 0) { } ; //see of tjere is a problem with NACK if there is lengh is 9 and for loob is skipped if(SSP2CON2bits.ACKSTAT) { } SSP2CON2bits.RCEN = 1; PIR4bits.SSP2IF = 0; //make sure the interrupt flag is cleared while(PIR4bits.SSP2IF ==0) {} ; tal = SSP2BUF; PIR4bits.SSP2IF = 0; SSP2CON2bits.ACKDT = 1; SSP2CON2bits.ACKEN = 1; while(PIR4bits.SSP2IF ==2 ) {} ; SSP2CON2bits.PEN = 1; //STOP FLAG while (SSP2CON2bits.PEN) {}; ener = counter[counterSelect] % 10; tier = counter[counterSelect] / 10; // Display Enere PORTBbits.RB0 = 1; __delay_ms(5); PORTA = display[ener]; PORTBbits.RB0 = 0; //Display Tiere PORTBbits.RB1 = 0; __delay_ms(5); PORTA = display[tier]; PORTBbits.RB1 = 1; // return; }}