51单片机~DS1302时钟
(一)说明:
(二)SPI总线原理:
(三)日历时钟寄存器:
慢充电:
BCD码:
temp.h
#ifndef __TEMP_H_
#define __TEMP_H_
#include<reg52.h>
//---重定义关键词---//
#ifndef uchar
#define uchar unsigned char
#endif
#ifndef uint
#define uint unsigned int
#endif
//--定义使用的IO口--//
sbit DSPORT=P3^7;
//--声明全局函数--//
void Delay1ms(uint );
uchar Ds18b20Init();
void Ds18b20WriteByte(uchar com);
uchar Ds18b20ReadByte();
void Ds18b20ChangTemp();
void Ds18b20ReadTempCom();
int Ds18b20ReadTemp();
#endif
temp.c
#include"temp.h"
/*******************************************************************************
* 函 数 名 : Delay1ms
* 函数功能 : 延时函数
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/
void Delay1ms(uint y)
{
uint x;
for( ; y>0; y--)
{
for(x=110; x>0; x--);
}
}
/*******************************************************************************
* 函 数 名 : Ds18b20Init
* 函数功能 : 初始化
* 输 入 : 无
* 输 出 : 初始化成功返回1,失败返回0
*******************************************************************************/
uchar Ds18b20Init(