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

📄 pcf8563.c~rf24711a.tmp

📁 MSP430F1611+LCD12864_st7920+Key刚完成调试.请有需要的朋下载!
💻 TMP
字号:
/********************************************************************
文件名:pcf8563l.c/pcf8563l.h
名称:PCF8563实时时钟芯片应用程序 
********************************************************************/
#include "PCF8563.h"
#include "IIC_PCF8563.h"
#define uint unsigned int
#define uchar unsigned char
//时钟取得的数

__interrupt void TimerB_ISR(void);
void Init_PCF8563_Port(void);

unsigned char SendStr(unsigned char  sladdr,  unsigned char  subaddr,  unsigned char  *s, unsigned char  len);
unsigned char RecvStr(unsigned char sladdr, unsigned char subaddr ,unsigned char *s, unsigned char  len);

unsigned char PCF_time[6]={ 
0x30,//秒(vl、00~59BCD码)
0x59,//分(-、00~59BCD码)
0x23,//时(-、-、00~23BCD码)
0x31,//日(-、-、01~31BCD码)
0x12,//世纪月(c、-、-、01~12BCD码)
0x99,//年(00~99BCD码)
};

unsigned char time[12];//设定时钟(要求全局声明unsigned char time[8])





void SetTime()
{
  SendStr(PCF8563W,0x02,PCF_time,4);
  SendStr(PCF8563W,0x07,PCF_time+4,2);
}


//读取时钟(要求全局声明unsigned char time[8])
void GetTime()
{
  RecvStr(PCF8563R,0x02,PCF_time,4);
  RecvStr(PCF8563R,0x07,PCF_time+4,2);
}

//组合BCD码到非组合BCD码的转换
//分别为 秒 分 时 日  月  年 
//格式化读取的时间值(入口time数组[6])
//输出 l[12] 高位在高 低位在低

void _FormatTime2BCD(uchar *t,uchar *l)
{	//uchar dat,dat_H,dat_L;
  uchar i,temp0,temp1;
  
  
  //以下分别去掉时间值中的无效位,年位不用换
  *t&=0x7f;
  *(t+1)&=0x7f;
  *(t+2)&=0x3f;
  *(t+3)&=0x3f;
  *(t+4)&=0x1f;
  *(t+5)&=0xff;	    //将BCD码转换为十进制
  
  for(i=0;i<6;i++)
  {
    temp0=t[i];
    temp1=temp0;
    l[2*i]=temp1&0x0f;//低位
    l[2*i+1]=temp0>>4;	//高位
  }
}
//读8563时间
//为得到的时间 数组 格式为非组合BCD每位占二字节 
// l 长度大于16

void PCF8563_get_BCDtime(uchar *l){
  
  GetTime();
  _FormatTime2BCD(PCF_time,l);
  
}

//读8563时间
//为得到的时间 数组 格式为实际数 每位占一字节 
// l 长度大于8
void PCF8563_get_RELtime(uchar *l){
  
  uchar i,temp0,temp1;
  GetTime();
  //以下分别去掉时间值中的无效位,年位不用换
  *PCF_time&=0x7f;
  *(PCF_time+1)&=0x7f;
  *(PCF_time+2)&=0x3f;
  *(PCF_time+3)&=0x3f;
  *(PCF_time+4)&=0x1f;
  *(PCF_time+5)&=0xff;
  
  for(i=0;i<8;i++){
    temp0=PCF_time[i];
    temp1=temp0;
    temp1=temp1&0x0f;
    temp0=temp0>>4;
    temp0=temp0*10;//十位数
    temp0=temp0+temp1;
    
    l[i]=temp0;
  }
}
//得到从00:00:00以来的秒数
//
//
uint  PCF8563_get_RELATtime(void)
{
  uchar i,temp0,temp1,l[3];
  
  GetTime();
  //以下分别去掉时间值中的无效位,年位不用换
  *PCF_time&=0x7f;
  *(PCF_time+1)&=0x7f;
  *(PCF_time+2)&=0x3f;
  *(PCF_time+3)&=0x3f;
  *(PCF_time+4)&=0x1f;
  *(PCF_time+5)&=0xff;
  
  for(i=0;i<3;i++){
    temp0=PCF_time[i];
    temp1=temp0;
    temp1=temp1&0x0f;//得到个位
    temp0=temp0>>4;
    temp0=temp0*10;//十位数
    temp0=temp0+temp1;
    
    l[i]=temp0;
  }
  return l[0]+60*l[1]+3600*l[2];
}

⌨️ 快捷键说明

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