u8 Read1302(u8 addr) { u8 data=0; DS1302_OUT(); DS1302_RST_L(); DS1302_CLK_L(); DS1302_RST_H(); DelayNOP(100); DS1302SendByte(addr|0x01); DS1302_IN(); data = DS1302ReceiveByte(); DelayNOP(100); DS1302_RST_L(); return(data); }
uint8_t Read1302(uint8_t addr) { uint8_t data=0; DS1302_OUT(); DS1302_RST_L(); DS1302_CLK_L(); DS1302_RST_H(); delay_nus(4); DS1302SendByte(addr|0x01); DS1302_IN(); delay_nus(4); data = DS1302ReceiveByte(); delay_nus(4); DS1302_CLK_H(); DS1302_RST_L(); return(data); }
/* 读时间函数,顺序为:年周月日时分秒 */ void ReadDS1302Clock(uint8_t *p) { DS1302_OUT(); DS1302_RST_L(); DS1302_CLK_L(); DS1302_RST_H(); delay_nus(4); DS1302SendByte(0xbf); //突发模式 DS1302_IN(); p[5] = DS1302ReceiveByte(); //秒 p[4] = DS1302ReceiveByte(); //分 p[3] = DS1302ReceiveByte(); //时 p[2] = DS1302ReceiveByte(); //日 p[1] = DS1302ReceiveByte(); //月 DS1302ReceiveByte(); //周 p[0] = DS1302ReceiveByte(); //年 DS1302ReceiveByte(); //保护标志字节 delay_nus(4); DS1302_RST_L(); }
/* 读时间函数,顺序为:年周月日时分秒 */ void ReadDS1302Clock(u8 *p) { DS1302_OUT(); DS1302_RST_L(); DS1302_CLK_L(); DS1302_RST_H(); DelayNOP(100); DS1302SendByte(0xbf); //突发模式 DS1302_IN(); p[5] = DS1302ReceiveByte(); //秒 p[4] = DS1302ReceiveByte(); //分 p[3] = DS1302ReceiveByte(); //时 p[2] = DS1302ReceiveByte(); //日 p[1] = DS1302ReceiveByte(); //月 DS1302ReceiveByte(); //周 p[0] = DS1302ReceiveByte(); //年 DS1302ReceiveByte(); //保护标志字节 DelayNOP(100); DS1302_RST_L(); }