📄 nokia 5110
字号:
//重庆三峡学院电子与信息工程学院创新实验室唐老鸭
#ifndef __DS1302_H__
#define __DS1302_H__
#include<reg52.h>
#include "delay.h"
sbit sck=P1^0;
sbit dio=P1^1;
sbit ce=P1^2;
static shi,fen,miao,nian,yue,ri,xingqi;
//写命令以及地址
void write(uchar add,uchar date)
{
uchar temp,t;
ce=0;
sck=0;
ce=1;
temp=add;
for(t=0;t<8;t++)//写地址命令
{
if((temp&0x01)==1)
dio=1;
else
dio=0;
sck=1;
delay(1);
sck=0;
temp=temp>>1;
}
temp=date;
for(t=8;t>0;t--) //写数据
{
if((temp&0x01)==1)
dio=1;
else
dio=0;
sck=1;
delay(1);
sck=0;
temp=temp>>1;
}
}
uchar read(uchar add)
{
uchar temp,t;
ce=0;
sck=0;
ce=1;
temp=add;
for(t=0;t<8;t++)
{
if((temp&0x01)==1)
dio=1;
else
dio=0;
sck=1;
sck=0;
temp>>=1;
}
temp=0;
for(t=0;t<7;t++)
{
if(dio==1)
temp=temp|0x80;
else
temp=temp&0x7f;
sck=1;
sck=0;
temp>>=1;
}
//传送一个字节需要16个时钟
return temp/16*10+temp%16;//将BCD码转换成10进制码
}
void init_time()
{
write(0x8e,0x00);//写保护,相当于初始化或者缓冲
write(0x80,(miao/10<<4)|(miao%10)); //写秒
write(0x82,(fen/10<<4)|(fen%10));//写分
write(0x84,(shi/10<<4)|(shi%10)); //写时
write(0x86,(ri/10<<4)|(ri%10)); //写日
write(0x88,(yue/10<<4)|(yue%10));//写月
write(0x8a,(xingqi/10<<4)|(xingqi%10)); //写星期
write(0x8c,(nian/10<<4)|(nian%10));//写年
}
//显示时间
void get_time()
{
shi=read(0x85);//读出时间 时
fen=read(0x83);//读出时间 分
miao=read(0x81);//读出时间 秒
nian=read(0x8d);//读出时间 年
yue=read(0x89);//读出时间 月
ri=read(0x87);//读出时间 日
xingqi=read(0x8b);//读出时间 星期
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -