⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 read 8563.txt

📁 这是控制时钟芯片8563读写操作的程序
💻 TXT
字号:
/****************************************************************************
* 文件名:8563.C
* 功能:实现时钟芯片PCF8563的读写操作 
*	1、写时间 
*	2、读时间
*	3、写报警(唤醒)时间
*	4、读报警(唤醒)时间 
* 接口:数据线:SDA(P0.3) 
*               SCL(P0.2) 
* 说明:采用模拟IIC总线的方式,读写函数的入口处先初始化I2C端口为普通IO,出口处再初始化I2C端口为特殊管脚
*       初始化端口的时候不破坏其他端口的值
* 编写:王鹏
* 日期:2006年5月26号
****************************************************************************/
#include  "config.h"
#include  "8563.h"

#define  DIRECT1     (1<<10)		    // P0.10--485DIR1  0000 0001

void  UART1_SendByte(uint8 data);
void  UART1_SendStr(uint8 const *str);
void  InitAllPort(void);
void  UART1_Ini(void);
void  UART1_SendData(uint32 xxx);
void  fnDelay(uint32  dly);
/**********************************************************************
** 函数名 uint8 fnReadTime(uint8 *sDateTime)
** 版本号: V1.0		前一版本:  无
** 编制:   王鹏       	日期: 2006年5月19日
** 测试:	王建		日期: 2006年5月31日
***********************************************************************
【函数功能】:从时钟芯片PCF8563里读时间;
【函数使用前提】1:在头文件中加入 "8563.h"   
				2:本函数及相关函数一般被保存在 "8563.h"中 
【入口参数】无
【出口参数】*sDateTime:数组格式:sDateTime[0]:年 sDateTime[1]:月 sDateTime[2]:日 sDateTime[3]:周 
								 sDateTime[4]:时 sDateTime[5]:分 sDateTime[6]:秒
【返 回 值】uint8  1:读数据成功 0:读数据失败
【范例调用】fnRead8563Time(Date):将读出的时间存入Date数组中 
【完整范例】 参见 Test_Serclock.c 
***********************************************************************
**   以下在软件移植时需注意                                          **
***********************************************************************
【调用函数】 下列函数将被本函数调用:
			 ReadTimeWord(): 读时钟寄存器内的值
			 BcdToHex(): BCD码转换为16进制数
【配置参数】    无 
【实现思路】采用引脚模拟I2C总线时序
【编译环境】本函数在EasyARM ADS1.2编译环境下调试通过
【适用硬件】本函数在目标板 SJZRTU060516、SMRTU503等上测试通过
          	CPU=ARM LPC2114  	clock=PCF8563T  
【硬件接口】本函数用于读I2C CLOCK时钟的时间
【硬件接口引脚】本函数需要使用如下引脚。
  ARM2114 Pin45 P0.2 输出模式  作为I2C器件的CLK
  ARM2114 Pin46 P0.3 双向模式  作为I2C器件的Data
***********************************************************************/
uint8 fnReadTime(uint8 *sDateTime)
{
	uint8 cccc;
	PINSEL0 = PINSEL0 & 0XFFFFFF0F; 		  // 设置为I2C为普通IO
	fnInit8563();
	cccc=ReadTimeWord(0x08);      	
    sDateTime[0]=BcdToHex(cccc);
   
    cccc=ReadTimeWord(0x07);
    cccc&=0x1f;
    sDateTime[1]=BcdToHex(cccc); 
	
    cccc=ReadTimeWord(0x05);                  			
    cccc&=0x3f;
    sDateTime[2]=BcdToHex(cccc);	
    
    cccc=ReadTimeWord(0x06);
    cccc&=0x07;
	sDateTime[3]=BcdToHex(cccc);
	
    cccc=ReadTimeWord(0x04);
    cccc&=0x3f;     	
	sDateTime[4]=BcdToHex(cccc);
	  
    cccc=ReadTimeWord(0x03);                  	
    cccc&=0x7f;
	sDateTime[5]=BcdToHex(cccc);
	
    cccc=ReadTimeWord(0x02);
    cccc&=0x7f;
	sDateTime[6]=BcdToHex(cccc);
	PINSEL0 = (PINSEL0 & (~0xF0)) | 0x50; 		// 设置为特殊管脚I2C
	return(1);
	
}

/**********************************************************************
** 函数名 uint8 fnWriteTime(uint8 *sDateTime)
** 版本号: V1.0		前一版本:  无
** 编制:   王鹏       	日期: 2006年5月19日
** 测试:	王建		日期: 2006年5月31日
***********************************************************************
【函数功能】:给时钟芯片8563里写初始化时间;
【函数使用前提】1:头文件中包含 "8563.h"   
				2:本函数及相关函数一般被保存在 "8563.h"中 
【入口参数】*sDateTime:数组格式:sDateTime[0]:年 sDateTime[1]:月 sDateTime[2]:日 sDateTime[3]:周 
								 sDateTime[4]:时 sDateTime[5]:分 sDateTime[6]:秒
【出口参数】无
【返 回 值】uint8  1:写数据成功 0:写数据失败
【范例调用】uint8 InitDate[7]={6,5,18,4,19,45,40};fnWriteTime(InitDate):初始化时间06年5月18号周4 19点45分40秒
【完整范例】 参见 Test_Serclock.c 
***********************************************************************
**   以下在软件移植时需注意                                          **
***********************************************************************
【调用函数】 下列函数将被本函数调用:
			1、 WriteTimeWord(): 读时钟寄存器内的值
			2、 HexToBcd():16进制数转换为 BCD码
			3、 fnReadTime():读时钟芯片的时间
【配置参数】    无 
【实现思路】采用引脚模拟I2C总线时序
【编译环境】本函数在EasyARM ADS1.2编译环境下调试通过
【适用硬件】本函数在目标板 SJZRTU060516、SMRTU503等上测试通过
          	CPU=ARM LPC2114  	clock=PCF8563T  
【硬件接口】本函数用于读I2C CLOCK时钟的时间
【硬件接口引脚】本函数需要使用如下引脚。
  ARM2114 Pin45 P0.2 输出模式  作为I2C器件的CLK
  ARM2114 Pin46 P0.3 双向模式  作为I2C器件的Data
***********************************************************************/
uint8 fnWriteTime(uint8 *sDateTime)
{
	uint8 c,i;
	uint8 date[7];
	PINSEL0 = PINSEL0 & 0XFFFFFF0F; 		  // 设置为I2C为普通IO
	fnInit8563();
	WriteTimeWord(0x00,0X00);				  // 清除报警
	WriteTimeWord(0x01,0X12);
	WriteTimeWord(0x0d,0);
    c=HexToBcd(sDateTime[0]);
      	WriteTimeWord(0x08,c);
  	c=HexToBcd(sDateTime[1]);
      	WriteTimeWord(0x07,c);
    c=HexToBcd(sDateTime[2]);
     	WriteTimeWord(0x05,c);
  	c=HexToBcd(sDateTime[3]);
      	WriteTimeWord(0x06,c);
   	c=HexToBcd(sDateTime[4]);
      	WriteTimeWord(0x04,c);
  	c=HexToBcd(sDateTime[5]);
      	WriteTimeWord(0x03,c);                  	
 	c=HexToBcd(sDateTime[6]);
      	WriteTimeWord(0x02,c);     	
    fnReadTime(date);
    PINSEL0 = (PINSEL0 & (~0xF0)) | 0x50; 	 // 设置为特殊管脚I2C
    for(i=0;i<7;i++)
    {
    if(date[i]==sDateTime[i])
    return(0);  
    else
    return(1);
    }
}
/****************************************************************************
* 名称:uint8 fnReadWeakupTime(uint8 *sDateTime)
* 功能:设置报警时间:天,时,分
* 入口参数:无 
* 出口参数:*sDateTime:读出的唤醒时间   格式:day:日  hours:时 minutes:分 
* 返回值:uint8  1:写数据成功 0:写数据失败
****************************************************************************/
uint8 fnReadWeakupTime(uint8 *sDateTime)
{
	uint8 cccc;
	PINSEL0 = PINSEL0 & 0XFFFFFF0F; 		  // 设置为I2C为普通IO
	fnInit8563();
    cccc=ReadTimeWord(0x0b);
    cccc&=0x3f;
    sDateTime[0]=BcdToHex(cccc);
    
    cccc=ReadTimeWord(0x0a);                  	
    cccc&=0x3f;
	sDateTime[1]=BcdToHex(cccc);	
	
    cccc=ReadTimeWord(0x09);
    cccc&=0x7f;     	

	sDateTime[2]=BcdToHex(cccc);
	
//	cccc=ReadTimeWord(0x0c); 
//	cccc&=0x07;     	
//   	sDateTime[3]=BcdToHex(cccc);
   	PINSEL0 = (PINSEL0 & (~0xF0)) | 0x50; 			// 设置为特殊管脚I2C
	return(1);

}	
/****************************************************************************
* 名称:uint8 fnWriteWeakupTime(uint8 *sDateTime)
* 功能:设置报警时间:天,时,分
* 入口参数:*sDateTime:写入的唤醒时间   数据格式: 日  时  分 
* 出口参数:无
* 返回值:uint8  1:写数据成功 0:写数据失败
****************************************************************************/
uint8 fnWriteWeakupTime(uint8 *sDateTime)
	{
    uint8 c,i;
    uint8 date[4];
	PINSEL0 = PINSEL0 & 0XFFFFFF0F; 		  // 设置为I2C为普通IO
	fnInit8563();
	WriteTimeWord(0x00,0X00);				  // 清除报警
	WriteTimeWord(0x01,0X12);
	WriteTimeWord(0x0d,0);    
  	c=HexToBcd(sDateTime[2]);
      	WriteTimeWord(0x09,c);//分
   	c=HexToBcd(sDateTime[1]);
		WriteTimeWord(0x0a,c);//时
    c=HexToBcd(sDateTime[0]);
  	    WriteTimeWord(0x0b,c);//日                        	
//  	c=HexToBcd(sDateTime[3]);
      	WriteTimeWord(0x0c,0X80);//周    屏蔽周报警  	
    c=0x2;
      	WriteTimeWord(0x0f,c);//倒计时定时器    
    fnReadWeakupTime(date); 	
    PINSEL0 = (PINSEL0 & (~0xF0)) | 0x50; 			// 设置为特殊管脚I2C
    for(i=0;i<4;i++)
    {
    if(date[i]==sDateTime[i])
    return(0);  
    else
    return(1);
    }
	}

/****************************************************************************
* 名称:测试程序
* 功能:测试时间操作函数
****************************************************************************/ 
// uint16 xxx;
// uint8 ReadDate[7];						//读出的时间数组
// uint8 aReadDate[3];					//读出的报警时间数组
// uint8 InitDate[7]={6,12,31,6,23,59,45};//写入的时间数组
// uint8 aInitDate[3]={1,0,0};		    //写入的报警时间数组
// uint8 aInitDate1[3]={1,0,1};		    //写入的报警时间数组1
/****************************************************************************
* 名称:main()
* 功能:主函数
****************************************************************************/ 
/*
int main(void)
{

 InitAllPort();
 IO0DIR = IO0DIR|DIRECT1;                  //置P0.10为输出口,RS485方向控制
 UART1_Ini();
 UART1_SendStr((uint8 *)"测试实时钟PCF8563:\r\n");

 if(fnWriteTime(InitDate)==0)					//写时间,06年12月31号周6 23点59分40秒
 {
 xxx=1;
 UART1_SendStr((uint8 *)"写时间成功:06年12月31号周6 23点59分40秒\r\n");
 }
 else
 {
 xxx=0;
 UART1_SendStr((uint8 *)"写时间失败"); 
 }	
 if(fnWriteWeakupTime(aInitDate)==0)			//写下次唤醒时间:1号0点0分唤醒
 {
 xxx=1;
 UART1_SendStr((uint8 *)"写下次唤醒时间成功:1号0点0分唤醒\r\n");
 }		
 else 
 {
 xxx=0;							
 UART1_SendStr((uint8 *)"写下次唤醒时间失败\r\n");
 }
 fnReadWeakupTime(aReadDate);			 		//读唤醒时间

 {
 fnReadTime(ReadDate);							//读时间:年 月 日 周 时 分 秒
 fnWriteWeakupTime(aInitDate1);                 //写下次唤醒时间:1号0点1分唤醒
 fnReadWeakupTime(aReadDate);					//读下次唤醒时间
 UART1_SendStr((uint8 *)"读下次唤醒时间:\r\n");
 UART1_SendData((uint32)aReadDate[0]);
 UART1_SendStr((uint8 *)"号");
 UART1_SendData((uint32)aReadDate[1]);
 UART1_SendStr((uint8 *)"时");
 UART1_SendData((uint32)aReadDate[2]);
 UART1_SendStr((uint8 *)"分");
 fnDelay(1500);
 
 }
 while(1)
 {
 fnReadTime(ReadDate);							//读当前时间
 UART1_SendData((uint32)ReadDate[0]);
 UART1_SendStr((uint8 *)"年");
 UART1_SendData((uint32)ReadDate[1]);
 UART1_SendStr((uint8 *)"月");
 UART1_SendData((uint32)ReadDate[2]);
 UART1_SendStr((uint8 *)"号");
 UART1_SendData((uint32)ReadDate[3]);
 UART1_SendStr((uint8 *)"周");
 UART1_SendData((uint32)ReadDate[4]);
 UART1_SendStr((uint8 *)"时");
 UART1_SendData((uint32)ReadDate[5]);
 UART1_SendStr((uint8 *)"分");
 UART1_SendData((uint32)ReadDate[6]);
 UART1_SendStr((uint8 *)"秒\r\n");
 fnDelay(1500);
 }

}        
 
 */       

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -