PCF8563底层驱动程序_第1页
PCF8563底层驱动程序_第2页
PCF8563底层驱动程序_第3页
PCF8563底层驱动程序_第4页
PCF8563底层驱动程序_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、*/ PCF8563底层驱动程序/*/#include <msp430x14x.h>#include <math.h>#include "msp430_m.h"#include "delay.h"/*/#define ADDR_RD 0xa3#define ADDR_WR 0xa2/*#define REG_CTL1 0x00#define REG_CTL2 0x01#define REG_SEC 0x02#define REG_MIN 0x03#define REG_HOUR 0x04#define REG_DAY 0x05#d

2、efine REG_WEEK 0x06#define REG_MON 0x07#define REG_YEAR 0x08#define REG_ALARM_MIN 0x09#define REG_ALARM_HOUR 0x0a#define REG_ALARM_DAY 0x0b#define REG_ALARM_WEEK 0x0c#define REG_FREQ 0x0d#define REG_TMRCTL 0x0e#define REG_TMR 0x0f/*#define sclk_pcf8563 BIT5#define sda_pcf8563 BIT7#define port_rtc P2

3、OUT/*#define set_sclk() bitclr(P2DIR,sclk_pcf8563)#define clr_sclk() bitset(P2DIR,sclk_pcf8563)#define set_sda() bitclr(P2DIR,sda_pcf8563)#define clr_sda() bitset(P2DIR,sda_pcf8563)bit error_bit;/*/*/static void delay_nop8(void)_nop_();_nop_();_nop_();_nop_();/*/static void Start(void) / ok,启动I2C总线s

4、et_sda();set_sclk();clr_sda();clr_sclk();/*/static void Stop(void) / okclr_sda();set_sclk();set_sda();clr_sclk();/*/static void Ack(void) / unused!clr_sda();set_sclk();clr_sclk();set_sda();/*/static void NoAck(void) / okset_sda();set_sclk();clr_sclk();clr_sda();/*/static bit TestAck(void)bit ErrorBi

5、t;set_sda();set_sclk();ErrorBit=0;if (bittest(P2IN,sda_pcf8563)ErrorBit=1; / 0,ok,1,error!clr_sclk();return ErrorBit;/*/static void Write8Bit(unsigned char input)unsigned char i;for(i=0;i<8;+i)if (input&0x80)set_sda();set_sclk();clr_sclk();clr_sda();elseclr_sda();set_sclk();clr_sclk();input&l

6、t;<=1;/*/static unsigned char Read8Bit(void)unsigned char i,rbyte;rbyte=0;for(i=0;i<8;+i)set_sda();set_sclk();rbyte<<=1;if (bittest(P2IN,sda_pcf8563)rbyte|=0x01;clr_sclk();return(rbyte);/*/void pcf8563_wr(uchar addr,uchar *ptr_data1,uchar length)Start();Write8Bit(ADDR_WR);Ack();Write8Bit

7、(addr);for(;length;-length)Ack();Write8Bit(*ptr_data1+);NoAck();Stop();/*/void pcf8563_rd(uchar addr,uchar *ptr_data1,uchar length)Start();Write8Bit(ADDR_WR);Ack();Write8Bit(addr);Ack();Start();Write8Bit(ADDR_RD);for(;length;-length)Ack();*ptr_data1+=Read8Bit();NoAck();Stop();/*/#if 0uint sec;uchar

8、const arr_init_rtc=0x00, / REG_CTL1 0x000x00, / REG_CTL2 0x010x00, / REG_SEC 0x020x00, / REG_MIN 0x030x08, / REG_HOUR 0x040x01, / REG_DAY 0x050x01, / REG_WEEK 0x060x05, / REG_MON 0x070x04, / REG_YEAR 0x08;uchar arr10;bit flag=1;void main(void)uchar i,j=0;uchar secd20;WDTStop();P2DIR = 0x5f; /0101-1111BP2SEL = 0x00;P2OUT = 0x00;for(i=0;i<sizeof(arr_init_rtc);+i)arri=arr_init_rtci;pcf8563_wr(0,arr,sizeof(

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论