?? 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 + -