📄 pcf8563.c
字号:
/* **************************************************************************************
* Copyright (c) 2002 ZORAN Corporation, All Rights Reserved
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
*
* File: $Workfile: EEPROM.C $
*
* Description:
* ============
* EEprom access
*
* Log:
* ====
* $Revision: 8 $
* Last Modified by $Author: Mikex $ at $Modtime: 04-04-02 22:25 $
****************************************************************************************
* Updates:
****************************************************************************************
* $Log: /I76/I76_Common/I76_Reference/Customer/device/eeprom/EEPROM.C $
*
* 8 04-04-03 15:08 Mikex
* changed eeprom r/w function to allow writting bytes count more than 256
*
* 7 1/13/04 12:08 Hamadk
* Merged with CES DB
*
* 6 24/11/03 11:38 Rinata
* support read/write of address more then 8 bit
*
* 4 3/20/03 9:51a Clifflv
* Add one more param for i2c_write_string
*
* 4 23/04/02 9:12 Nirm
* - Added dependency in "Config.h".
*
* 3 8/01/02 16:24 Nirm
* Corrected Include-Paths.
*
* 2 1/01/02 14:11 Atai
* Code cleaning
*
*
**************************************************************************************** */
#include "Config.h" // Global Configuration - do not remove!
#ifdef D_PCF8563_CLOCK
#include "Include\SysDefs.h"
#include "Devices\pcf8563\pcf8563.h"
#include "Devices\i2c\i2c.h"
#include "Include\math-macro.h"
#include "CoreAPI\CoreAPI.h"
BOOL clock_write(unsigned int addr, unsigned char *data, unsigned int count)
{
BOOL retValue;
BYTE device_id = D_PCF8563_ADDRESS;
BYTE offset = addr&0xff;
WORD number;
while(count)
{
number= MIN(0x100-offset, count);
retValue = i2c_write_pcf8563(device_id, offset, number, data, 8 );
offset = (offset+number)&0xff;
count-=number;
device_id+=2;
data+=number;
}
return retValue;
}
BOOL clock_read(unsigned int addr, unsigned char *data, unsigned int count)
{
BOOL retValue;
BYTE device_id = D_PCF8563_ADDRESS;
BYTE offset = addr&0xff;
WORD number;
while(count)
{
number= MIN(0x100-offset, count);
retValue = i2c_read_pcf8563(device_id, offset, number, data);
offset = (offset+number)&0xff;
count-=number;
device_id+=2;
data+=number;
}
return retValue;
}
void pcf8563_init(void)
{
BYTE bInitData[16];
bInitData[0]=0x00;
bInitData[1]=0x00;
if (FALSE == clock_write(0x00,bInitData,2))
{
tr_printf(("Init clock fail at clock.c\n"));
}
}
void pcf8563_upgrade(void)
{
BYTE bUpdata[7];
write_pcf8563(bUpdata);
if (FALSE == clock_write(PCF8563_SECOND,bUpdata,7))
{
tr_printf(("pcf8563_upgrade clock fail at clock.c\n"));
}
}
void write_pcf8563(BYTE *bWriteData)
{
BYTE bTempValue;
bTempValue = CoreAPI_GetCurrentSecond();
if ( bTempValue > 59 )
bTempValue = 1;
if ( bTempValue > 9 )
bWriteData[0] = ((bTempValue/10)<<4);
else
bWriteData[0] = 0;
bWriteData[0] |= (bTempValue%10);
bTempValue = CoreAPI_GetCurrentMinute();
if ( bTempValue >59 )
bTempValue = 0;
if ( bTempValue > 9 )
bWriteData[1] = ((bTempValue/10)<<4);
else
bWriteData[1] = 0;
bWriteData[1] |= (bTempValue%10);
bTempValue = CoreAPI_GetCurrentHour();
if ( bTempValue > 23 )
bTempValue = 0;
if ( bTempValue > 9 )
bWriteData[2] = ((bTempValue/10)<<4);
else
bWriteData[2] = 0;
bWriteData[2] |= (bTempValue%10);
bTempValue = CoreAPI_GetCurrentDay();
if ( bTempValue > 31 )
bTempValue = 0;
if ( bTempValue > 9 )
bWriteData[3] = ((bTempValue/10)<<4);
else
bWriteData[3] = 0;
bWriteData[3] |= (bTempValue%10);
//bWriteData[4] = 1;
bWriteData[4] = WeekDay(CoreAPI_GetCurrentYear(),CoreAPI_GetCurrentMonth(),1);//tenglee
bTempValue = CoreAPI_GetCurrentMonth();
if ( bTempValue > 12 )
bTempValue = 0;
if ( bTempValue > 9 )
bWriteData[5] = ((bTempValue/10)<<4);
else
bWriteData[5] = 0;
bWriteData[5] |= (bTempValue%10);
bTempValue = CoreAPI_GetCurrentYear();
if (bTempValue<100)
bWriteData[5] |= 0x80;
bTempValue = CoreAPI_GetCurrentYear();
if (bTempValue>150)
bTempValue = 1;
if (bTempValue>99)
bWriteData[6] = bTempValue - 100 ;
else
bWriteData[6] = bTempValue;
//tr_printf(("write data is %x %x %x %x %x %x %x",bWriteData[0],bWriteData[1],bWriteData[2],bWriteData[3],bWriteData[4],bWriteData[5],bWriteData[6]));
}
void pcf8563_reset(void)
{
BYTE bInitData[14];
bInitData[0]=0x00;
bInitData[1]=0x00;
if (FALSE == clock_write(0x00,bInitData,2))
{
tr_printf(("pcf8563_reset clock fail at clock.c\n"));
}
//delay_us(5000UL);
write_pcf8563(bInitData);
bInitData[7]=0x80;
bInitData[8]=0x80;
bInitData[9]=0x80;
bInitData[10]=0x80;
bInitData[11]=0x00;
bInitData[12]=0x00;
bInitData[13]=0x00;
if (FALSE == clock_write(PCF8563_SECOND,bInitData,14))
{
tr_printf(("Init clock fail at clock.c\n"));
}
}
#endif // D_PCF8563_CLOCK
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -