📄 ds12887.c
字号:
#include<reg52.h>
#include<all.h>
#define uchar unsigned char
#define uint unsigned int
/*定义DS12CR887数据线--------------------------------------------------------*/
//sbit DS_CS = P3^4; //片选 直接接地
sbit DS_AS = P3^5;//地址选通
sbit DS_RW = P3^6;
sbit DS_DS = P3^7;
#define Ds_Bus P0 //DS12CR887数据总线
//uchar p[7]=0x00; //定义时间数组为全局变量
/*DS12CR887驱动程序----------------------------------------------------------*/
//往DS12CR887写数据函数
void ds_write(uchar add,uchar date)
{
DS_RW=0; // 写地址
DS_AS=1;
Ds_Bus=add;
DS_AS=0;
DS_DS=1;
Ds_Bus=date; //写数据,数据由RW上升沿锁存
DS_DS=0; //DS下降沿锁存数据
}
//读取DS12CR887的数据
uchar ds_read(uchar add)
{ uchar z;
DS_RW=0; // 写地址
DS_AS=1;
Ds_Bus=add;
DS_AS=0;
DS_RW=1; //读数据
DS_DS=1;
Ds_Bus=0xff;
z=Ds_Bus;
DS_DS=0;
return z;
}
//DS12CR887初始化
void ds_int()
{
uchar i;
i=ds_read(0x0d);
ds_write(0x0a,0x70);
ds_write(0x0b,0xa2); //DS12CR887寄存器A功能设置,开启时钟振荡器
ds_write(0x0b,0x06);
ds_write(0x0a,0x20);
i=ds_read(0x0c); //读c后,c清零
}
/****************************/
//日期和星期显示
/***************************/
void day_time_display()
{ uchar p[7]={0,0,0,0,0,0,0};
p[0]=ds_read(0x00);
p[1]=ds_read(0x02);
p[2]=ds_read(0x04);
p[3]=ds_read(0x06);
p[4]=ds_read(0x07);
p[5]=ds_read(0x08);
p[6]=ds_read(0x09);
LCD_write_shu(0,0,2); //2
LCD_write_shu(1,0,0); //0
LCD_write_shu(2,0,p[6]/10); //年十位
LCD_write_shu(3,0,p[6]%10); //年个位
// _____________
LCD_write_shu(4,0,12); // / |2009/04/02 |
LCD_write_shu(5,0,p[5]/10); //月十位 | 13:06:25 |
LCD_write_shu(6,0,p[5]%10); //月个位 |星期四 17.2℃|
LCD_write_shu(7,0,12); // / |_____________|
LCD_write_shu(8,0,p[4]/10); //日十位
LCD_write_shu(9,0,p[4]%10); //日个位
LCD_write_hanzi(0,4,11); //星
LCD_write_hanzi(1,4,12); //期
LCD_write_hanzi(2,4,p[3]); //×
LCD_write_shu(0,2,13); //写空格,消除干扰
LCD_write_shu(1,2,p[2]/10); //时十位
LCD_write_shu(2,2,p[2]%10); //时个位
LCD_write_shu(3,2,10); //:
LCD_write_shu(4,2,p[1]/10); //分十位
LCD_write_shu(5,2,p[1]%10); //分个位
LCD_write_shu(6,2,10); //:
LCD_write_shu(7,2,p[0]/10); //秒十位
LCD_write_shu(8,2,p[0]%10); //秒个位
LCD_write_shu(9,2,13); //写空格,消除干扰
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -