ds1302时钟C程序
来源:互联网 发布:网站域名免费注册 编辑:程序博客网 时间:2024/04/29 11:40
http://weibo.com/GTY55IW
这是1302的C文件,1302.h文件在后来面
#include"1302.h"
code unsigned char write_rtc_address[7]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c}; //秒分时日月周年 最低位读写位
code unsigned char read_rtc_address[7]={0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};
void Write_Ds1302_Byte(unsigned char temp)
{
unsigned char i;
for (i=0;i<8;i++) //循环8次 写入数据
{
sclk=0;
io=temp&0x01; //每次传输低字节
temp>>=1; //右移一位
sclk=1;
}
}
/******************************************************************/
/* 写入DS1302 */
/******************************************************************/
void Write_Ds1302( unsigned char address,unsigned char dat )
{
rst=0;
_nop_();
sclk=0;
_nop_();
rst=1;
_nop_(); //启动
Write_Ds1302_Byte(address); //发送地址
Write_Ds1302_Byte(dat); //发送数据
rst=0; //恢复
}
/******************************************************************/
/* 读出DS1302数据 */
/******************************************************************/
unsigned char Read_Ds1302 ( unsigned char address )
{
unsigned char i,temp=0x00;
rst=1;
_nop_();
_nop_();
Write_Ds1302_Byte(address);
for (i=0;i<8;i++) //循环8次 读取数据
{
if(io)
temp|=0x80; //每次传输低字节
sclk=1;
temp>>=1; //右移一位
_nop_();
_nop_();
_nop_();
sclk=0;
}
rst=0;
_nop_(); //以下为DS1302复位的稳定时间
_nop_();
rst=0;
sclk=0;
_nop_();
_nop_();
_nop_();
_nop_();
/*sclk=1;
_nop_();
_nop_();
io=0;
_nop_();
_nop_();
io=1;
_nop_();
_nop_(); */
return (temp); //返回
}
/******************************************************************/
/* 读时钟数据 */
/******************************************************************/
uchar Read_RTC1(uchar j) //读取 日历
{
uchar c;
unsigned char *p;
p=&read_rtc_address[j]; //地址传递
c=Read_Ds1302(*p);
c=(( c&0x70)>>4)*10 + ( c&0x0F);
return(c);
}
/******************************************************************/
/* 设定时钟数据 */
/******************************************************************/
void Set_RTC(uchar a,uint c) //设定 日历
{
unsigned char *p ,shi,ge ;
Write_Ds1302(0x8E,0X00);
shi=a/10;
ge=a%10;
a=shi*16+ge;
p=&write_rtc_address[c]; //传地址
Write_Ds1302(*p,a) ;
// Write_Ds1302(0x8E,0x80);
} 、
这是头文件:
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit sclk=P1^2; //时钟
sbit io=P1^1; //数
sbit rst = P1^0;
void Set_RTC(uchar a,uint c);
uchar Read_RTC1(uchar j);
- ds1302时钟C程序
- 单片机时钟程序(4)ds1302.c
- 单片机时钟程序(4)ds1302.c
- LCD1602-DS1302时钟程序
- 时钟程序(LED+DS1302+AT89S52)
- ST7920液晶---DS1302时钟程序
- DS1302 时钟芯片的程序
- C语言程序>>DS1302
- 51单片机(AT89C52)DS1302时钟芯片程序
- AVR单片机(ATMEGA16)DS1302时钟芯片程序
- 51单片机DS1302时钟芯片简单程序
- 单片机时钟程序(5)ds1302.h
- 单片机时钟程序(5)ds1302.h
- DS1302时钟
- 单片机复习程序例举005 -- DS1302时钟芯片
- DS1302 时钟操作
- 事无巨细,时钟芯片DS1302
- ds1302-MAX7219时钟
- jdk5.0的11个主要新特性
- 数模、模数转换器
- 《GOF设计模式》—命令(COMMAND)—Delphi源码示例:支持修改日志
- 若干经典的字符串哈希函数
- 一次跳转和两次跳转
- ds1302时钟C程序
- Flex Logger的使用
- birt使用quartz框架实现自动生成报表
- Git 使用说明图
- delphi memo 自动滚动到最底下
- 资源索引Perfect网站
- DOM Xerces类库使用方法
- JVM的内存优化
- AD 转换