Pcf8563 library


Download library from here


 
/***********************************************************
               Clock ini 
***********************************************************/

void ini_clk(void) // clock initialisation - only at start up
{
 unsigned char Err;
  I2C_Start();
    Write_I2C_Byte(0xA2);
     Err=I2C_Ack();  // Check for acknowledge from I2C device
      Write_I2C_Byte(0x00); 
       Err=I2C_Ack();  // Check for acknowledge from I2C device
        Write_I2C_Byte(0x80); 
         Err=I2C_Ack();  // Check for acknowledge from I2C device
  I2C_Stop();	  					   // Set I2C Stop condition
  haltb();
   I2C_Start();
    Write_I2C_Byte(0xA2);
     Err=I2C_Ack();  // Check for acknowledge from I2C device
      Write_I2C_Byte(0x00); 
       Err=I2C_Ack();  // Check for acknowledge from I2C device
        Write_I2C_Byte(0x00); 
         Err=I2C_Ack();  // Check for acknowledge from I2C device
  I2C_Stop();	  					   // Set I2C Stop condition
//  haltb();
//  I2C_Start();
//   Write_I2C_Byte(0xA2);
//    Err=I2C_Ack();  // Check for acknowledge from I2C device
//     Write_I2C_Byte(0x08); 
//      Err=I2C_Ack();  // Check for acknowledge from I2C device
//       Write_I2C_Byte(0x00); 
//        Err=I2C_Ack();  // Check for acknowledge from I2C device
//  I2C_Stop();	  					   // Set I2C Stop condition
  haltb();
}


/***********************************************************
               Clock read functions
***********************************************************/

unsigned char read_clk_ss(void) // read seconds
{
unsigned char ss,Err;
  I2C_Start();
   Write_I2C_Byte(0xA2);
    Err=I2C_Ack();  // Check for acknowledge from I2C device
     Write_I2C_Byte(0x02); 
      Err=I2C_Ack();  // Check for acknowledge from I2C device
       I2C_Start();
        Write_I2C_Byte(0xA3);
	     Err=I2C_Ack();  // Check for acknowledge from I2C device
	      ss=Read_I2C_Byte();
	       I2C_Clock();				  // Clock I2C bit *** No ACK *** //
  I2C_Stop();	  					   // Set I2C Stop condition
  if (Err==1) {return 0xFF;} else {return ss;};	
	
}


unsigned char read_clk_mm(void) // read minutes
{
unsigned char mm,Err;
  I2C_Start();
   Write_I2C_Byte(0xA2);
    Err=I2C_Ack();  // Check for acknowledge from I2C device
     Write_I2C_Byte(0x03); 
      Err=I2C_Ack();  // Check for acknowledge from I2C device
       I2C_Start();
        Write_I2C_Byte(0xA3);
	     Err=I2C_Ack();  // Check for acknowledge from I2C device
	      mm=Read_I2C_Byte();
	       I2C_Clock();				  // Clock I2C bit *** No ACK *** //
  I2C_Stop();	  					   // Set I2C Stop condition
  if (Err==1) {return 0xFF;} else {return mm;};	
	
}

unsigned char read_clk_hh(void) // read hours
{
unsigned char hh,Err;
  I2C_Start();
   Write_I2C_Byte(0xA2);
    Err=I2C_Ack();  // Check for acknowledge from I2C device
     Write_I2C_Byte(0x04); 
      Err=I2C_Ack();  // Check for acknowledge from I2C device
       I2C_Start();
        Write_I2C_Byte(0xA3);
	     Err=I2C_Ack();  // Check for acknowledge from I2C device
	      hh=Read_I2C_Byte();
	       I2C_Clock();				  // Clock I2C bit *** No ACK *** //
  I2C_Stop();	  					   // Set I2C Stop condition
  if (Err==1) {return 0xFF;} else {return hh;};	
	
}


unsigned char read_clk_dd(void) // read days
{
unsigned char dd,Err;
  I2C_Start();
   Write_I2C_Byte(0xA2);
    Err=I2C_Ack();  // Check for acknowledge from I2C device
     Write_I2C_Byte(0x05); 
      Err=I2C_Ack();  // Check for acknowledge from I2C device
       I2C_Start();
        Write_I2C_Byte(0xA3);
	     Err=I2C_Ack();  // Check for acknowledge from I2C device
	      dd=Read_I2C_Byte();
	       I2C_Clock();				  // Clock I2C bit *** No ACK *** //
  I2C_Stop();	  					   // Set I2C Stop condition
  if (Err==1) {return 0xFF;} else {return dd;};	
	
}

unsigned char read_clk_mo(void) // read months
{
unsigned char mo,Err;
  I2C_Start();
   Write_I2C_Byte(0xA2);
    Err=I2C_Ack();  // Check for acknowledge from I2C device
     Write_I2C_Byte(0x07); 
      Err=I2C_Ack();  // Check for acknowledge from I2C device
       I2C_Start();
        Write_I2C_Byte(0xA3);
	     Err=I2C_Ack();  // Check for acknowledge from I2C device
	      mo=Read_I2C_Byte();
	       I2C_Clock();				  // Clock I2C bit *** No ACK *** //
  I2C_Stop();	  					   // Set I2C Stop condition
  if (Err==1) {return 0xFF;} else {return mo;};	
	
}


unsigned char read_clk_yy(void) // read years
{
unsigned char yy,Err;
  I2C_Start();
   Write_I2C_Byte(0xA2);
    Err=I2C_Ack();  // Check for acknowledge from I2C device
     Write_I2C_Byte(0x08); 
      Err=I2C_Ack();  // Check for acknowledge from I2C device
       I2C_Start();
        Write_I2C_Byte(0xA3);
	     Err=I2C_Ack();  // Check for acknowledge from I2C device
	      yy=Read_I2C_Byte();
	I2C_Clock();				  // Clock I2C bit *** No ACK *** //
	I2C_Stop();	  					   // Set I2C Stop condition
  if (Err==1) {return 0xFF;} else {return yy;};	
	
}






/***********************************************************
               Clock ini set function
***********************************************************/

/*
void ini_clk(void)	// clock initialisation - only at start up
{
static unsigned char as;
as = write_i2c(0x00,0x00);	// Control/Status1 = 0x00
as = write_i2c(0x01,0x00);	// Control/Status2 = 0x00
as = write_i2c(0x0e,0x00);	// Timer control = 0x00
}

*/


/***********************************************************
               Clock set functions
***********************************************************/

void set_clk_time(unsigned char hh, unsigned char mm, unsigned char ss, unsigned char dd, unsigned char ll, unsigned char yy)
{
unsigned char Err;

	I2C_Start();
	Write_I2C_Byte(0xA2);
	Err=I2C_Ack();	// Check for acknowledge from I2C device
	Write_I2C_Byte(0x02); 
	Err=I2C_Ack();	// Check for acknowledge from I2C device
	Write_I2C_Byte(ss);
	Err=I2C_Ack();	// Check for acknowledge from I2C device
	Write_I2C_Byte(mm);
	Err=I2C_Ack();	// Check for acknowledge from I2C device
	Write_I2C_Byte(hh);
	Err=I2C_Ack();	// Check for acknowledge from I2C device
	Write_I2C_Byte(dd);
	Err=I2C_Ack();	// Check for acknowledge from I2C device
	I2C_Stop();
	halta();

	I2C_Start();
	Write_I2C_Byte(0xA2);
	Err=I2C_Ack();	// Check for acknowledge from I2C device
	Write_I2C_Byte(0x07);
	Err=I2C_Ack();	// Check for acknowledge from I2C device
	Write_I2C_Byte(ll);
	Err=I2C_Ack();	// Check for acknowledge from I2C device
	Write_I2C_Byte(yy);
	Err=I2C_Ack();	// Check for acknowledge from I2C device
	I2C_Stop();		// Set I2C Stop condition
}



Back to my home page

Last updated January, 2010

© Copyright 2010 Bergthaller Iulian-Alexandru