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

📄 pcf8563_for_msp430.c

📁 pcf8563_for_msp430.cIAR2。31调试
💻 C
字号:
/**********************************Copyright (c)*********************************
 *										
 *					    西安.兰特水电测控技术有限责任公司
 *
 *							    	开发部
 *
 *----------------------------------文件信息-------------------------------------
 * 文件名称: pcf8563_for_msp430.c
 * 创 建 人: 李良福
 * 创建时间: 2006/03/08
 * 修改时间: 2006/03/08
 * 当前版本: v1.0: 针对于MSP430单片机的C语言 
 * 描    述:本模块定义了操作时钟芯片PCF8563的相关函数。
 ********************************************************************************/
 #include <msp430x14x.h>
 #include "I2c_for_msp430.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
 #include <string.h>
  
//每分钟产生一次中断,单片机读取PCF8563的时间。
//*******************************************************************************

//********************************************************
// 说明:PCF8563驱动程序
// SCL=P6。2
// SDA=P6。3
//********************************************************

unsigned char Timedata;

 /*******************************************************************************
 * name: delay()
 * description: delay time.
 * input parameter: The times that need to delay.
 * output parameter: Null
 ********************************************************************************/
static void delay(unsigned int tt)
{
  int i;
  for (i=0; i<tt; i++);
//    WDTCTL = WDTPW + WDTCNTCL + 0x04;
}

/*******************************************************************************
 * name: GetPCF8563()  
 * description: 读取时钟芯片PCF8563的时间,设置要读的第一个时间类型firsttype,
 * 并设置读取的字节数,则会一次把时间读取到buff中。顺序是:
 * 0x02:秒/0x03:分/0x04:小时/0x05:日/0x06:星期/0x07:月(世纪)/0x08:年
 * input parameter: firsttype, count, *buff
 * output parameter: buff
 ********************************************************************************/
void GetPCF8563(unsigned char firsttype,unsigned char count,unsigned char *buff)
{
  unsigned char i;
  I2C_START();   // 启动总线
  I2C_WriteByte(0xA2);  // 发送器件写地址,A2H为写PCF8563的地址
  I2C_GetACK();  // 主机发送完数据后等待从应答
  I2C_WriteByte(firsttype);
  I2C_GetACK();  // 主机发送完数据后等待从应答
  I2C_START();   // 启动总线
  I2C_WriteByte(0xA3); // 发送器件读地址,A3H为读PCF8563的地址
  I2C_GetACK();  // 主机发送完数据后等待从应答
  for(i=0;i<count;i++)
  {
    *buff=I2C_ReadByte();
    if(i!=count-1)// 除最后一个字节外,其他都要从主机发应答。
     {
      I2C_SetACK(); // 主机接收完数据后发送主应答
      }
    buff++;
  }
  I2C_SetNAK(); //主机接收最后一个字节时返回无需应答NO_ACK
  I2C_STOP();  // 停止总线
}

/*******************************************************************************
 * name: Adjust_PCF8563()  
 * description: 调整时钟。timetype是需要修改的时间类型,value是新设置的时间值(BCD格式)。
 * 

⌨️ 快捷键说明

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