Searching \ for '[PIC:] Philips PCF8753 (I2C) RTC on 16F877A (prob' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/i2cs.htm?key=i2c
Search entire site for: 'Philips PCF8753 (I2C) RTC on 16F877A (prob'.

Exact match. Not showing close matches.
PICList Thread
'[PIC:] Philips PCF8753 (I2C) RTC on 16F877A (prob'
2004\02\24@132804 by Jim Franklin

flavicon
face
Hi Guys (& Gals ?)

I have just bought a couple of Philips PCF8753 RTC chips from RS components,
(seemed like a good idea at the time!) but I am having a mare of a time
talking to them on my 16F877A.

I have the wiring ok (I am absolutely 100% sure of this - after all it is
only 2 wire I2C :) I have followed some of the not-very-helpful philips
datasheets (is this me, or are all philips datasheets hard to read?).
but can't get it to talk to me...

I am using CCSinfo's PCWH C Compiler. but I can read ASM if someone has any
ideas/code/guidelines/valium...

Thanks
Jim

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body

2004\02\24@133807 by Roland

flavicon
face
part 1 1018 bytes content-type:text/plain; charset="us-ascii"here's Julian Winpenny's file on doing that;

At 06:26 PM 24/02/04 +0000, you wrote:
{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body



part 2 9962 bytes content-type:text/plain; charset="us-ascii"
/***************************************************************************/
/*  I2C.C       i2c protocol implementation sources                        */
/*                                                                         */
/*  Version :   1.0                                                        */
/*                                                                         */
/*       By :   Julian Winpenny                                            */
/*                                                                         */
/*     Date :   31/5/1999                                                  */
/*                                                                         */
/*  Purpose :   I2C Protocol implementation                                */
/*                                                                         */
/* Comments :   The SDA data line uses inverted logic, because             */
/*              if the serial data line is not connected to an             */
/*              open-drain output ( Port A bit 4 ), then an external       */
/*              transistor must be used                                    */
/*                                                                         */
/***************************************************************************/

#define EESlaveWrite 0xA0      // EEPROM Slave address and write mode
#define EESlaveRead  0xA1      // EEPROM Slave address and read mode
#define ClockWrite   0xA2      // PCF8583 Clock Write mode
#define ClockRead    0xA3      // PCF8583 Clock Read mode



/*************************************************************/
/*       Start Bit Subroutine                                */
/*       this routine generates a start bit                  */
/*       (Low going data line while clock is high)           */
/*************************************************************/


void BitStart(void)
{

        output_low_port_b( sdataOut ); // make sure data is high ( Inverted by a Transistor !)
        output_low_port_a( sclk );     // make sure clock is low

        output_low_port_b( sdataOut ); // Ensure data is High
        Delay();
        output_high_port_a( sclk );    // set clock high
        Delay();
        output_high_port_b( sdataOut );// data line goes low during
                                       // high clock for start bit
        Delay();
        output_low_port_a( sclk );     // start clock train
        Delay();

}

/************************************************************/
/*       Stop Bit Subroutine                                */
/*       This routine generates a stop bit                  */
/*       (High going data line while clock is high)         */
/************************************************************/

void BitStop(void)
{
        output_high_port_b( sdataOut ); // make sure data line is low
        nop();
        output_high_port_a( sclk ); // set clock high
        Delay();
        output_low_port_b( sdataOut ); // data goes high while clock high
                                      // for stop bit
        Delay();
        output_low_port_a( sclk );  // set clock low again
        Delay();
}

/**************************************************************/
/*       BITIN routine reads one bit of data from the         */
/*       serial EE device and stores it in the bit 'di'       */
/**************************************************************/
void BitIn(void)
{
        set_bit( eeflag, di );        // assume input bit is high
        output_high_port_a( sclk );   // set clock line high
        Delay();                      // just sit here a sec

        if ( ( input_port_b() & sdataInmask ) == 0 )
        clear_bit( eeflag, di );      // input bit was low, set 'di' accordingly

        output_low_port_a( sclk );    // set clock line low
        Delay();

}

/*************************************************************/
/*       BITOUT routine takes the bit of data in 'do' and    */
/*       transmits it to the serial EE device                */
/*************************************************************/
void BitOut(void)
{

        if ( ( eeflag & domask ) == 0 )
           {
              output_high_port_b( sdataOut );// output a low bit
           }

        else
           {
              output_low_port_b( sdataOut ); // high? set data line high
           }

        Delay(); // Small delay
        output_high_port_a( sclk ); // set clock line high
        Delay();
        output_low_port_a( sclk );  // return clock line low
        Delay();
        output_low_port_b( sdataOut );// set sdataOut line to float sDataIn
}

/*****************************************************************/
/*       Receive data byte routine                               */
/*       This routine reads one byte of data from the part       */
/*       into the 'eedata' register.  It then sends a high       */
/*       ack bit to indicate that no more data is to be read     */
/*****************************************************************/

void ReadEEByte(void)
{

eedata = 0;                         // Clear input buffer

     for ( Temp = 0; Temp < 8; Temp++ )
         {
            asm rlf _eedata, F;     // rotate datai 1 bit left
            BitIn();                // read a bit
                                    // set/clear bit 0 as necessary
            if ( ( eeflag & dimask ) != 0 )
                set_bit( eedata, 0 );
            else
               clear_bit( eedata, 0 );
          }

// data returned in eedata
}


/********************************************************************/
/*       Write Data byte function                                   */
/*       This routine takes the byte of data stored in the          */
/*       'eedata' register and transmits it to the serial EE device.*/
/*       It will then send 1 more clock to the serial EE for the    */
/*       acknowledge bit.  If the ack bit from the part was low     */
/*       then the transmission was sucessful.  If it is high, then  */
/*       the device did not send a proper ack bit.                  */
/*                                                                  */
/********************************************************************/
void WriteEEByte(void)
{


 for ( Temp = 0; Temp < 8; Temp++ )
     {
        clear_bit( eeflag, do );    // assume bit out is low
        if ( ( eedata & 0x80 ) != 0 )  // Do we send a low?
            set_bit( eeflag, do );  // ...no, send a high
        BitOut();                   // Send the bit to serial EE
        asm rlf _eedata, F;         // Rotate data left 1 bit
     }

  BitIn();

}




/********************************************************************/
/*       READ (read routine)                                        */
/*       In the read mode, the PIC must send the acknowledge        */
/*       bit after every 8 data bits from the device.  When the     */
/*       last byte needed has been read, then the controller will   */
/*       send a high acknowledge bit and then a stop bit to halt    */
/*       transmission from the device.                              */
/********************************************************************/

char ReadData( char AdrHigh, char AdrLow )
{


        BitStart();                  // generate start bit

        eedata = E2Device;
        WriteEEByte();              // Slave write mode

        if ( E2Device == EESlaveWrite ) // If E2 then two byte address needed
           {
              eedata = AdrHigh;
              WriteEEByte();         // Send high byte of address
           }

        eedata = AdrLow;
        WriteEEByte();               // Send low byte of address

        BitStart();                  // generate start bit

        eedata = (E2Device + 1);
        WriteEEByte( );              // Switch to read mode

        ReadEEByte();                // Read 1 byte from device (eedata)

        set_bit( eeflag, do );       // yes, send high ack bit
        BitOut();                    // to stop tranxmission
        BitStop();                   // and send a stop bit

 return eedata;

}


/********************************************************************/
/* Input HighAddress, LowAddress, data.                             */
/*                                                                  */
/********************************************************************/

void WriteData( char AdrHigh, char AdrLow, char ch )
{


        BitStart();                 // generate start bit
        eedata = E2Device;
        WriteEEByte();              // Slave write mode

        if ( E2Device == EESlaveWrite ) // if EEPROM device, two byte address
           {
              eedata = AdrHigh;
              WriteEEByte();        // Send high byte of address
           }

        eedata = AdrLow;
        WriteEEByte();              // Send low byte of address
        eedata = ch;
        WriteEEByte();              // Send the byte to write
        BitStop();                  // and send a stop bit

 Delay();


if ( E2Device == EESlaveWrite )
 {

 for ( Temp = 0; Temp < 100; Temp++ ) // Wait for program cycle complete
     {
       Delay();
       BitStart();
       eedata = E2Device;
       WriteEEByte();
       BitIn();                           // read ack bit
       if ( ( eeflag & di ) == 0 )        // check ack bit
              break;                      // Break when program cycle complete.
     }
 }
     //;BitStop();
     clear_bit( eeflag, err );            // Assume it was ok !

     if ( Temp == 100 )
     set_bit( eeflag, err );              // set error flag


}





--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam.....mitvma.mit.edu with SET PICList DIGEST in the body




part 3 420 bytes content-type:text/plain; charset="us-ascii"

Regards
Roland Jollivet


JeM Electric cc
PO Box 1460
Kloof
3640
Kwazulu Natal
South Africa
Tel: +27 31 7024412
Fax: +27 31 7011674                                \o
Cell: +27 83 255 6017                               l>
Email: EraseMEenquiriesspam_OUTspamTakeThisOuTcaon.co.za                        < \

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body


2004\02\24@135303 by Roland

flavicon
face
part 1 1117 bytes content-type:text/plain; charset="us-ascii"here's Julian Winpenny's file on doing that;
and, I forgot, his cct. Actually he's using an '84. So maybe it's not what
you need. Oops.

Roland

At 06:26 PM 24/02/04 +0000, you wrote:
{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email KILLspamlistservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body



part 2 6265 bytes content-type:image/gif; name="e2test2.gif"; (decode)


part 3 420 bytes content-type:text/plain; charset="us-ascii"

Regards
Roland Jollivet


JeM Electric cc
PO Box 1460
Kloof
3640
Kwazulu Natal
South Africa
Tel: +27 31 7024412
Fax: +27 31 7011674                                \o
Cell: +27 83 255 6017                               l>
Email: RemoveMEenquiriesTakeThisOuTspamcaon.co.za                        < \

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spamBeGonelistservspamBeGonespammitvma.mit.edu with SET PICList DIGEST in the body


2004\02\24@140546 by Roland

flavicon
face
part 1 1061 bytes content-type:text/plain; charset="us-ascii"Ok, try again, same source, Julian Winpenny(is he on this list?),
this time on the F877

At 06:26 PM 24/02/04 +0000, you wrote:
{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body



part 2 10071 bytes content-type:text/plain; charset="us-ascii"
/***************************************************************************/
/*      Example implementation of I2C using PIC16F8XX MSSP module.         */
/*                                                                         */
/*                                                                         */
/*                                                                         */
/*       By : J. Winpenny                                                  */
/*     Date : 25/9/99                                                      */
/*  Version : 1.0                                                          */
/*                                                                         */
/*                                                                         */
/*                                                                         */
/*     Mode : I2C MASTER                                                   */
/* Hardware : PIC16F877                                                    */
/*                                                                         */
/*                                                                         */
/***************************************************************************/

// Configuration Registers for I2C
char SSPSTAT@0x94;  // In Bank 1
char SSPCON@0x14;   // In Bank 0
char SSPCON2@0x91;  // In Bank 1
char SSPBUF@0x13;   // I2C Buffer
char SSPADD@0x93;   // I2C Slave Address register
// Bits of SSPSTAT
#define SMP 7
#define CKE 6
#define D_A 5
#define P   4
#define S   3
#define R_W 2
#define R_W_MASK 0x04
#define UA  1
#define BF  0


// Bits of SSPCON2
#define GCEN    7
#define ACKSTAT 6
#define ACKDT   5
#define ACKEN   4
#define RCEN    3
#define PEN     2
#define RSEN    1
#define SEN     0
// E2C Addresses
#define ClockWrite   0xA2      // PCF8583 Clock Write mode
#define ClockRead    0xA3      // PCF8583 Clock Read mode
#define SetupClock   0x08
// PCF8583 Clock registers
#define control        0x00
#define hundredths     0x01
#define seconds        0x02
#define minutes        0x03
#define hours          0x04
#define date           0x05
#define month          0x06
#define timer          0x07
#define alarm_ctrl     0x08
#define alarm_hundreds 0x09
#define alarm_seconds  0x0a
#define alarm_minutes  0x0b
#define alarm_hours    0x0c
#define alarm_date     0x0d
#define alarm_month    0x0e
#define alarm_timer    0x0f
#define ramzero        0x10

// Bits of PIR1
#define PSPIF  7
#define ADIF   6
#define RCIF   5
#define TXIF   4
#define SSPIF  3
#define SSPIF_MASK 0x08
#define CCP1IF 2
#define TMR2IF 1
#define TMR1IF 0


// Bits of SSPCON
#define WCOL  7
#define SSPOV 6
#define SSPEN 5
#define CKP   4
#define SSPM3 3
#define SSPM2 2
#define SSPM1 1
#define SSPM0 0

/* Function Prototypes  */
void ConfigureI2C(void);
void I2CSend( char );
char I2CReceive(void);
void I2CAck(void);
void I2CNak(void);
void I2CStart(void);
void I2CStop(void);
void I2CWait(void);
void SetClock(void);
void ReadClock(void);
/*************************  I2C Routines  ************************************/




/**************************************/
/* Configure the MSSP as an I2C Port  */
/* For PIC16F877                      */
/*                                    */
/* Relevant port pins configured as   */
/* Inputs                             */
/**************************************/
void ConfigureI2C(void)
{
  set_bit( SSPCON, SSPEN );  // Enable I2C mode

  set_bit( SSPCON, SSPM3 );  // Setup I2C
  clear_bit( SSPCON, SSPM2 );
  clear_bit( SSPCON, SSPM1 );
  clear_bit( SSPCON, SSPM0 );

  set_bit( STATUS, RP0 );    // *** Register page 1 ***

  SSPCON2 = 0;

  clear_bit( SSPSTAT, SMP );
  clear_bit( SSPSTAT, CKE ); // Set I2C Levels
        // Set I2C Speed
  SSPADD = 10;               // 100k at 4Mhz clock
  clear_bit( STATUS, RP0 );  // *** Register page 0 ***
}

/***********************/
/* Send a char via I2C */
/***********************/
void I2CSend( char ch )
{
  SSPBUF = ch;               // Load DATA to send
  I2CWait();                 // Wait for completion
}
/**************************/
/* Receive a char via I2C */
/**************************/
char I2CReceive(void)
{
  set_bit( STATUS, RP0 );        // *** Register page 1 ***

  while ( SSPSTAT & R_W_MASK  ); // Wait for Transmit to end

  set_bit( SSPCON2, RCEN );      // Enable I2C receiver
  clear_bit( STATUS, RP0 );      // *** Register page 0 ***
  I2CWait();                     // Wait for data to arrive.

  return SSPBUF;                 // Return the data
}
/**************************/
/* Send an I2C ACK        */
/**************************/
void I2CAck(void)
{
  set_bit( STATUS, RP0 );        // *** Register page 1 ***
  clear_bit( SSPCON2, ACKDT );   // Setup for ACK
  set_bit( SSPCON2, ACKEN );     // Send ACK
  clear_bit( STATUS, RP0 );      // *** Register page 0 ***
  I2CWait();                     // Wait for completion
}
/**************************/
/* Send an I2C ACK        */
/**************************/
void I2CNak(void)
{
  set_bit( STATUS, RP0 );        // *** Register page 1 ***
  set_bit( SSPCON2, ACKDT );     // Setup for NAK
  set_bit( SSPCON2, ACKEN );     // Send NAK
  clear_bit( STATUS, RP0 );      // *** Register page 0 ***
  I2CWait();                     // Wait for completion
}
/**************************/
/* Generate an I2C START  */
/**************************/
void I2CStart(void)
{
  set_bit( STATUS, RP0 );        // *** Register page 1 ***
  set_bit( SSPCON2, SEN );       // Initiate START condition
  clear_bit( STATUS, RP0 );      // *** Register page 0 ***
  I2CWait();                     // Wait for completion
}
/***************************/
/* Generate an I2C RESTART */
/***************************/
void I2CRestart(void)
{
  set_bit( STATUS, RP0 );        // *** Register page 1 ***
  set_bit( SSPCON2, RSEN );      // Initiate START condition
  clear_bit( STATUS, RP0 );      // *** Register page 0 ***
  I2CWait();                     // Wait for completion
}
/**************************/
/* Generate an I2C STOP   */
/**************************/
void I2CStop(void)
{
  set_bit( STATUS, RP0 );        // *** Register page 1 ***
  set_bit( SSPCON2, PEN );       // Generate STOP condition
  clear_bit( STATUS, RP0 );      // *** Register page 0 ***
  I2CWait();                     // Wait for completion
}

/**************************************/
/* Waits for I2C process to complete  */
/**************************************/
void I2CWait(void)
{
  while ( !( PIR1 & SSPIF_MASK ) );     // Wait for Interrupt

  clear_bit( PIR1, SSPIF );             // Clear Interrupt flag
}



/*****************************************************************************/
/*                     Examples of using the above functions                 */
/*****************************************************************************/



/*****************************************************************/
/* Set the PCF8593 Low Power Clock Calendar                      */
/*                                                               */
/* see : http://www-us.semiconductors.philips.com/index.html     */
/*                                                               */
/* Illustrates setting the clock                                 */
/* ( NOT Year 2000 tested )                                      */
/*****************************************************************/
void SetClock(void)
{
 // Example = 25/09/99 at 19:45:00.00

 I2CStart();
 I2CSend( ClockWrite );
 I2CSend( control );
 I2CSend( 0x08 );      // Setup the Clock Calendar
                       // to read date & month directly

 I2CSend( 0x00 );      // Hundredths of seconds
 I2CSend( 0x00 );      // Seconds
 I2CSend( 0x45 );      // Minutes
 I2CSend( 0x19 );      // Hours
 I2CSend( 0x25 );      // Date  ( Bits 7,6 are The Year ( 0-3 ) )
 I2CSend( 0x09 );      // Month
 I2CStop();            // Stop data transfer

}

/**********************************************/
/* Read the PCF8593 Low Power Clock Calendar. */
/* Display on LCD                             */
/**********************************************/
void ReadClock(void)
{

/* Lets waste some registers ! */
/* ( These should really be passed or global ) */

char s;   // To save seconds value
char m;   // To save minutes value
char h;   // To save hours value
char d;   // To save days value
char mo;  // To save month value
char nn;  // Temporary storage


 I2CStart();          // Set a START condition I2C Bus
 I2CSend( ClockWrite );
 I2CSend( seconds );  // Setup address ( Then auto increment )
 I2CRestart();
 I2CSend( ClockRead );
 s = I2CReceive();    // Read Seconds
 I2CAck();
 m = I2CReceive();    // Read Minutes
 I2CAck();
 h = I2CReceive();    // Read Hours
 I2CAck();
 d = I2CReceive();    // Read Days
 I2CAck();
 mo = I2CReceive();   // Read Month
 I2CNak();
 I2CStop();

 nn = ( d & 0x0f );   // Units of Day
 d >>= 4 & 0x0f;      // Tens of Days

 LCD_Line_2();        // Goto line 2 of LCD

 LCD_Write_4_Bit( d + '0' );
 LCD_Write_4_Bit( nn + '0' );
 LCD_Write_4_Bit( '/' );

 nn = ( mo & 0x0f);    // Units of Months
 mo >>= 4 & 0x0f;      // Tens of Months

 LCD_Write_4_Bit( mo + '0' );
 LCD_Write_4_Bit( nn + '0' );
 LCD_Write_4_Bit( ' ' );

 nn = (h & 0x0f);      // Units of Hours
 h >>= 4 & 0x0f;       // Tens of Hours

 LCD_Write_4_Bit( h + '0' );
 LCD_Write_4_Bit( nn + '0' );
 LCD_Write_4_Bit( ':' );

 nn = (m & 0x0f);      // Units of Minutes
 m >>= 4 & 0x0f;       // Tens of Minutes

 LCD_Write_4_Bit( m + '0' );
 LCD_Write_4_Bit( nn + '0' );
 LCD_Write_4_Bit( '.' );

 nn = (s & 0x0f);     // Units of Seconds
 s >>= 4 & 0x0f;      // Tens of Seconds

 LCD_Write_4_Bit( s + '0' );
 LCD_Write_4_Bit( nn + '0' );

}





--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservEraseMEspam.....mitvma.mit.edu with SET PICList DIGEST in the body




part 3 420 bytes content-type:text/plain; charset="us-ascii"

Regards
Roland Jollivet


JeM Electric cc
PO Box 1460
Kloof
3640
Kwazulu Natal
South Africa
Tel: +27 31 7024412
Fax: +27 31 7011674                                \o
Cell: +27 83 255 6017                               l>
Email: EraseMEenquiriesspamcaon.co.za                        < \

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservEraseMEspamEraseMEmitvma.mit.edu with SET PICList DIGEST in the body


2004\02\24@161551 by Jim Franklin

flavicon
face
Roland,

Fantastic help! I have been surfing like mad since I received the chips and
didn't find a lot to help me.
I have spent far too much time re-inventing the wheel on this one, so your
help is very much appreciated.
The PCWH Compiler has I2C functions built in, but I was having difficulty
setting/reading the clock. The attachments have all the info I need, so I
will hopefully get this gpoing tonight.

Again thank you.

Jim

-----Original Message-----
From: pic microcontroller discussion list
[RemoveMEPICLISTspam_OUTspamKILLspamMITVMA.MIT.EDU]On Behalf Of Roland
Sent: 24 February 2004 19:06
To: RemoveMEPICLISTTakeThisOuTspamspamMITVMA.MIT.EDU
Subject: Re: [PIC:] Philips PCF8753 (I2C) RTC on 16F877A (problems with)


Ok, try again, same source, Julian Winpenny(is he on this list?),
this time on the F877

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspamspamspamBeGonemitvma.mit.edu with SET PICList DIGEST in the body

More... (looser matching)
- Last day of these posts
- In 2004 , 2005 only
- Today
- New search...