microC software i2c with pic16f877

Discussion in 'Embedded Systems and Microcontrollers' started by sumani, Mar 31, 2009.

  1. sumani

    Thread Starter New Member

    Mar 12, 2009

    unfortunately i can not understand MicroC software I2C example.

    if it's possible, learn me how can i use defined function (Software I²C Library) for PIC16F877A and 24lc64, please.
    i want one sample code for learning that functions.


    could anyone please explain me how write the word 'computer' into the 24lc64 i2c eeprom which is connected with pic16f877a at PORTB {Soft_I2C_Config(&PORTB, 1, 2);} and read it back.
  2. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    Seems you made a Double Post.

    MikroC has an I2C example I2C program under examples/BigPic5/18Fxxxx/RTC.C

    The realtime clock on their boards is through I2C, so any of the clock code examples will give you the I2C code in Mikro C. Mine is heavily commented, both read and write.

    Which example were you viewing?
  3. sumani

    Thread Starter New Member

    Mar 12, 2009
    hi sorry for that inconvenience.
    I've gone through both examples. but i couldn't understand both.
    this is the part of the coding i extract from the write example..
    Soft_I2C_Write(0xA0); // address PCF8583
    Soft_I2C_Write(0); // start from word at address 0 (configuration word)
    Soft_I2C_Write(0x80); // write $80 to config. (pause counter...)
    Soft_I2C_Write(0); // write 0 to cents word
    Soft_I2C_Write(0); // write 0 to seconds word
    Soft_I2C_Write(0x30); // write $30 to minutes word
    Soft_I2C_Write(0x11); // write $11 to hours word
    Soft_I2C_Write(0x30); // write $30 to year/date word
    Soft_I2C_Write(0x08); // write $08 to weekday/month
    in above coding what is 0xA0, configuration word, 0x80?
    and could you please explain what is actually happening when run above coding?
    how can i modify this code to write a word (lets say that word is 'computer')into the eeprom (24lc64)?
  4. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    My examples look like this:

    Code ( (Unknown Language)):
    2. I2C_Init(100000);         // initialize I2C communication
    3.   I2C_Start();              // issue I2C start signal
    4.   I2C_Wr(0xA2);             // send byte via I2C  (device address + W)
    5.   I2C_Wr(2);                // send byte (address of EEPROM location)
    6.   I2C_Wr(0xF0);             // send data (data to be written)
    7.   I2C_Stop();               // issue I2C stop signal
    To send a string of data, it needs to be sent one character at a time, since it is a serial protocol.

    The initial write is for addressing which device on the bus will be "spoken to"

    See I2C Introduction
  5. sumani

    Thread Starter New Member

    Mar 12, 2009
    thank you for your reply. The recommended link is very helpful. now i can go ahead on my project.
    thanks a lot.