Exemple #1
0
        private byte i2c_write_byte_data(byte reg, byte data)
        {
            AppStatus = I2C.I2C_SetStart();                                                     // I2C START
            if (AppStatus != 0)
            {
                return(1);
            }

            AppStatus = I2C.I2C_SendDeviceAddrAndCheckACK(OLED_ADDRESS, false);                 // I2C ADDRESS (for write)
            if (AppStatus != 0)
            {
                return(1);
            }
            if (I2C.I2C_Ack != true)
            {
                I2C.I2C_SetStop(); return(1);
            }                                                                                   // if oled NAKs then send stop and return

            AppStatus = I2C.I2C_SendByteAndCheckACK(reg);                                       // SEND REGISTER ID
            if (AppStatus != 0)
            {
                return(1);
            }
            if (I2C.I2C_Ack != true)
            {
                I2C.I2C_SetStop(); return(1);
            }                                                                                   // if oled NAKs then send stop and return

            AppStatus = I2C.I2C_SendByteAndCheckACK(data);                                      // SEND VALUE TO WRITE
            if (AppStatus != 0)
            {
                return(1);
            }
            if (I2C.I2C_Ack != true)
            {
                I2C.I2C_SetStop(); return(1);
            }                                                                                   // if oled NAKs then send stop and return

            AppStatus = I2C.I2C_SetStop();                                                      // I2C STOP
            if (AppStatus != 0)
            {
                return(1);
            }

            return(0);
        }