PIC16F72 with I2C 'C'- program error plze give me suggestion

Ian Rogers

Joined Dec 12, 2012
1,136
Are you simulating a pic16C72a?? Proteus doesn't have a pic16f72 model..

When using I2C in proteus you CANNOT!! use analogue resistor models for your pullup. In the library you will find a digital "pullup" resistor model.. Use this...
 

Picbuster

Joined Dec 2, 2013
1,047
Hi Form,

Please i am trying to write the code pic16f72 with i2c i don't know its not showing output in proteous but is excuted in mplab without error.
Load program in chip and see what happens.
Emulators are beautiful things but the real live could differ.

Picbuster
 

Thread Starter

pramoda.g

Joined Aug 20, 2019
13
Are you simulating a pic16C72a?? Proteus doesn't have a pic16f72 model..

When using I2C in proteus you CANNOT!! use analogue resistor models for your pullup. In the library you will find a digital "pullup" resistor model.. Use this...
Load program in chip and see what happens.
Emulators are beautiful things but the real live could differ.

Picbuster
Even in real time also excuted but not working may be program error I am writing first time this program ...Please check once the code ....

Are you simulating a pic16C72a?? Proteus doesn't have a pic16f72 model..

When using I2C in proteus you CANNOT!! use analogue resistor models for your pullup. In the library you will find a digital "pullup" resistor model.. Use this...
Hi I have PIC16f72 data sheet available please check in internet available...May code error please check once
 
Last edited by a moderator:

Ian Rogers

Joined Dec 12, 2012
1,136
Now.... You said it runs fine in MPLAB... I very much doubt that it compiles... You have doubled several of the functions and several are called before definition...

Then!!! The pic16F72 doesn't have a port D..
Then!! The I2C routines are for a newer SSP module and none of the bits are available...

It would take me far too long to convert this code to this "lesser" chip..
 

Thread Starter

pramoda.g

Joined Aug 20, 2019
13
Now.... You said it runs fine in MPLAB... I very much doubt that it compiles... You have doubled several of the functions and several are called before definition...

Then!!! The pic16F72 doesn't have a port D..
Then!! The I2C routines are for a newer SSP module and none of the bits are available...

It would take me far too long to convert this code to this "lesser" chip..
Hi ...
Long time means ...1 week
 

Thread Starter

pramoda.g

Joined Aug 20, 2019
13
Any type ok for me
I can help with your project and solve your issue. Check your PM (Private Message).
Any Type of for me personally or in forum...This is my what's app number <SNIP>

Moderators note : removed private info

hi javanthd,
If you want to help the TS, please do so by using this Forum, not PM's

Moderation.[/QUO
hi javanthd,
If you want to help the TS, please do so by using this Forum, not PM's

Moderation.
Hi actually I have urgent for this any type I want ...This is my wts app no <SNIP>

Moderators note : removed private info
 
Last edited by a moderator:

Thread Starter

pramoda.g

Joined Aug 20, 2019
13
This is the code i wrote.....
C:
#include <xc.h>

#define F_OSC 8000000                        /* define F_OSC for finding bit rate here oscillator frequency is 8 MHz so define as 800000 */
#define I2C_CLOCK  100000                    /* I2C clock frequency is 100 kHz  */
#define BITRATE ((F_OSC/(4*I2C_CLOCK))-1)    /* find bit rate to assign this value to SSPADD register */

void MSSP_WAIT()
{
    while(!PIR1bits.SSPIF);   // wait till SSPIF flag is set
    PIR1bits.SSPIF=0 ;
}

void I2C_IDLE()
{
while ( (SSPCON & 0b00011111) || (SSPSTAT & 0b00000100) ) ;
//check the this on registers to make sure the                                                                
//IIC is not in progress
}

unsigned char I2CRead(void)
{
  while (!SSPSTATbits.BF);      // wait until byte received
  return (SSPBUF);              // return with read byte
}

signed char WriteI2C( unsigned char data_out )
{
  SSPBUF = data_out;           // write single byte to SSPBUF
  if ( SSPCONbits.WCOL )      // test if write collision occurred
   return(-1);              // if WCOL bit is set return negative #
  else
  {
    while(SSPSTATbits.BF);   // wait until write cycle is complete  
  
    if (PIR1bits.SSPIF) // test for ACK condition received
        return (-2);
    else
         return (0);              // if WCOL bit is not set return non-negative #
  }
}

void I2C_START()
{
    SSPSTATbits.S = 1; // Initialize the start condition
    I2C_IDLE();        // check if the I2C bus is idle
    MSSP_WAIT();       // wait till completion of event
}

void I2C_Init()
{
        TRISC3  = 1; TRISC4  = 1;        /* set up I2C lines by setting as input*/
        SSPSTAT = 80;                   /* slew rate disabled, other bits are cleared*/
        SSPCON  = 0x3B;                    /* enable SSP port for I2C Master mode,
                                         * clock = FOSC / (4 * (SSPADD+1)) */
        SSPADD  = BITRATE;              /* clock 100 kHz */
        PIE1bits.SSPIE = 1;             /* enable SSPIF interrupt */
        PIR1bits.SSPIF = 0;            
}

void I2C_STOP()
{
    SSPSTATbits.P = 1;      // Initiate stop condition
    MSSP_WAIT();            // Wait till completion of event
    SSPCONbits.SSPEN = 0;   // Disable I2C operation
}

void main()
{    
    int seconds[60],minutes[60],hours[24];
    int day[30],month[12];

    I2C_Init();                 /* initialize I2C protocol */
    I2C_START();                // Issue start signal

    WriteI2C(0xD0);             // Address PIC16F722, see  datasheet
    WriteI2C(0x00);
    WriteI2C(0x00);
    WriteI2C(0xD1);             // Address PIC16F722 for reading R/W=1
      seconds = I2CRead(1);     // Read seconds byte
      minutes = I2CRead(1);     // Read minutes byte
      hours = I2CRead(1);       // Read hours byte
      day = I2CRead(1);         // Read year/day byte
      month = I2CRead(0);       // Read weekday/month byte
  
    I2C_STOP();                 // Issue stop signal
   __delay_ms(10);
}
Moderators note : used code tags for C
 

Thread Starter

pramoda.g

Joined Aug 20, 2019
13
Hi ja
http://saeedsolutions.blogspot.com/2012/12/interfacing-of-pic16f877-with-ds1307.html

Let me know if you nee\d more help.

If you are just simulating in proteus then you have to set the I2C Pull-up resistors of 4.7k for 100kHz I2C Clock frequency to DIGITAL type. By default, it is ANALOG type.
http://saeedsolutions.blogspot.com/2012/12/interfacing-of-pic16f877-with-ds1307.html

Let me know if you nee\d more help.

If you are just simulating in proteus then you have to set the I2C Pull-up resistors of 4.7k for 100kHz I2C Clock frequency to DIGITAL type. By default, it is ANALOG type.
Hi jayanthd,

In that link they are using the pic16f877 with DS1307 ,In the PIC16f877 there are using SSPCON2 register But in PIC16f72 only having the SSPCON register there is no SSPCON2 register.
 

Ian Rogers

Joined Dec 12, 2012
1,136
Hi ja


Hi jayanthd,

In that link they are using the pic16f877 with DS1307 ,In the PIC16f877 there are using SSPCON2 register But in PIC16f72 only having the SSPCON register there is no SSPCON2 register.
There are MANY changes needed... I cannot even find the ACK bit.. I can't imagine that it's polled... Why must you use the pic16f72??
 
Top