Eprom Access Functions.c

PIC16F877 sample code that demonstrates how to access an external I2C EEPROM chip connected to a PIC. PIC16F877 is running at 20MHz and 24LC256 with RC0 as a clock pin and RC1 as a data pin. This example does not use the I2C specific interrupt features of the PIC16F877 to enable it to be used on a wider variety of PIC's. Modular approach makes it easy to follow and adapt for other designs (by Jamie Balfour).




// External Eprom Access. Jamie Balfour. Dec 2002.

// No Liability Accepted.



#include "I2C Low Level.h"

#include "Eprom Functions.h"





unsigned char RetrieveData( unsigned char ControlByte, unsigned char HighByte, unsigned char LowByte )

{

    unsigned char required_data=0, test=1;

    while( test )

    {

        SendStart();

        test=SendDeviceAddress( ControlByte, WRITE );		/* Wait for eprom to signal it is ready */

    }

    SendData(HighByte);

    SendData(LowByte);

    Restart();

    SendDeviceAddress( ControlByte, READ );

    required_data = GetData();

    SendStop();

    return required_data;

}



void ByteWrite( unsigned char ControlByte, unsigned char HighByte, unsigned char LowByte, unsigned char DataByte )

{

    unsigned char required_data=0, test=1;

    while( test )

    {

        SendStart();

        test=SendDeviceAddress( ControlByte, WRITE );		/* Wait for eprom to signal it is ready */

    }

    SendData(HighByte);

    SendData(LowByte);

    SendData(DataByte);

    SendStop();

}





Copyright© 2002 Pavel Baranov.