数字万年历简易C语言程序源代码

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
display_nt(ads_s,time);
}
void set_time()//三按键设置时间
{
if(s0==0)
{
write_com(0x0f);//开闪烁
write_com(0x80+ads_m+1);
while(s0==0);
delay_1302(30000);
while(s0==1)
{
if(s1==0)
#include"reg52.h"
#define uchar unsigned char
#define uint unsigned int
sbit rs=P2^0;// lcd控制端
sbit en=P2^2;// lcd控制端
sbit all=P2^1;// lcd控制端
sbit s0=P1^5;//时间调节
write_byte(ge+'0');
}
void display_nt2(char ads,uchar t)//将读出星期显示
{
write_com(0x80+ads);
write_byte(t+'0');
}
void get_dis()//获得时间并显示
{
DS1302_GetTime(DS1302_YEAR);
sbit s1=P1^6;
sbit s2=P1^7;
sbit voice=P2^7;
int nt;
sbit DQ=P2^6;
sbit DS1302_CLK = P2^3; //实时时钟时钟线引脚
sbit DS1302_IO = P2^4; //实时时钟数据线引脚
sbit DS1302_RST = P2^5; //实时时钟复位线引脚
for(i=0;i<n;i++)
for(j=0;j<10;j++);
}
void write_com(char com)//lcd comond in LCD控制字写入函数
{
en=0;
P3=com;
rs=0;
delay(1);
en=1;
delay(2);
en=0;
delay(2);
}
void write_byte(char byte)//lcd data inLCD数据写入函数
b=read_ds();
nt=0;
nt=nt+b;
nt=nt<<8;
nt=nt+a;
nt=nt*0.625;//此ds18b20最低位为0.5扩大十倍
}
void delay_1302(uint n)//按键长延时
{
while(n--);
}
void delay(uchar n)//lcd延时子程序
{
uchar i,j;
time--;
DS1302_SetTime(DS1302_MINUTE,time);
display_nt(ads_m,time);
write_com(0x80+ads_m+1);
delay_1302(30000);
}
}
write_com(0x80+ads_h+1);
while(s0==0);
delay_1302(30000);
#define DS1302_YEAR 0x8C
void delay1(unsigned int i)//ds延时函数放在前边是为了让EP两次存储之间延时可以调用
{
while(i--);
}
void init_ds()//ds初始化函数
{
unsigned char x=0;
DQ=1; //DQ复位
delay1(8); //稍做延时
{
DS1302_RST = 0;
DS1302_CLK = 0;
DS1302_RST = 1;
DS1302InputByte(ucAddr); //地址,命令
DS1302InputByte(ucDa); //写1Byte数据
DS1302_CLK = 1;
DS1302_RST = 0;
}
unsigned char Read1302(unsigned char ucAddr) //读取DS1302某地址的数据
{
DS1302_SetProtect(0);
Write1302(Address, ((Value/10)<<4 | (Value%10)));
}
void DS1302_GetTime(unsigned char xy)//关键函数向外读出时间
{
unsigned char ReadValue;
ReadValue = Read1302(xy);
}
if(s2==0)
{
DS1302_GetTime(DS1302_HOUR);
time--;
DS1302_SetTime(DS1302_HOUR,time);
display_nt(ads_h,time);
write_com(0x80+ads_h+1);
delay_1302(30000);
}
}
write_com(0x80+ads_w);
DS1302_RST = 0;
return(ucData);
}
void DS1302_SetProtect(bit flag) //是否写保护
{
if(flag)
Write1302(0x8E,0x10);
else
Write1302(0x8E,0x00);
}
void DS1302_SetTime(unsigned char Address, unsigned char Value) //关键函数向内写入时间
}
}
write_com(0x80+ads_d+1);
while(s0==0);
delay_1302(30000);
while(s0==1)
{
if(s1==0)
{
DS1302_GetTime(DS1302_DAY);
time++;
unsigned char dat=0;
for(i=8;i>0;i--)
{
DQ=0; //给脉冲信号
dat>>=1;
DQ=1; //给脉冲信号
if(DQ)
dat|=0x80;
delay1(5);
}
return(dat);
}
void write_ds(unsigned char dat) ///写一个字节
{
DS1302_GetTime(DS1302_MINUTE);
time++;
DS1302_SetTime(DS1302_MINUTE,time);
display_nt(ads_m,time);
write_com(0x80+ads_m+1);
delay_1302(30000);
}
if(s2==0)
{
DS1302_GetTime(DS1302_MINUTE);
#define DS1302_SECOND 0x80//写入ds地址宏定义
#define DS1302_MINUTE 0x82
#define DS1302_HOUR 0x84
#define DS1302_WEEK 0x8A
#define DS1302_DAY 0x86
#define DS1302_MONTH 0x88
time=((ReadValue&0x70)>>4)*10+(ReadValue&0x0F);
}
void display_nt(char ads,uchar t)//将读出时间显示
{
char ge,shi;
write_com(0x80+ads);
shi=t%100/10;
ge=t%10;
write_byte(shi+'0');
while(s0==1)
{
if(s1==0)
{
DS1302_GetTime(DS1302_HOUR);
time++;
DS1302_SetTime(DS1302_HOUR,time);
display_nt(ads_h,time);
write_com(0x80+ads_h+1);
delay_1302(30000);
write_ds(0xCC); //跳过读序号列号的操作
write_ds(0x44); //启动温度转换
delay1(10);
init_ds();
write_ds(0xCC); //跳过读序号列号的操作
write_ds(0xBE); //读取温度寄存器等(共可读9个寄存器)前两个就是温度
a=read_ds();
{
en=0;
P3=byte;
rs=1;
delay(1);
en=1;
delay(2);
en=0;
delay(2);
}
void init_lcd_com()//lcd initLCD初始化
{
all=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
}
void DS1302InputByte(unsigned char d) //实时时钟写入一字节(内部函数)
{
unsigned char i;
ACC = d;
for(i=8; i>0; i--)
{
DS1302_IO = ACC0; //相当于汇编中的RRC
DS1302_CLK = 1;
DS1302_CLK = 0;
ACC = ACC >> 1;
}
}
unsigned char DS1302OutputByte(void) //实时时钟读取一字节(内部函数)
{
unsigned char ucData;
DS1302_RST = 0;
DS1302_CLK = 0;
DS1302_RST = 1;
DS1302InputByte(ucAddr|0x01); //地址,命令
ucData = DS1302OutputByte(); //读1Byte数据
DS1302_CLK = 1;
delay_1302(30000);
}
if(s2==0)
{
DS1302_GetTime(DS1302_WEEK);
time--;
DS1302_SetTime(DS1302_WEEK,time);
display_nt2(ads_w,time);
write_com(0x80+ads_w);
delay_1302(30000);
{
unsigned char i=0;
for(i=8;i>0;i--)
{Fra Baidu bibliotek
DQ=0;
DQ=dat&0x01;
delay1(5);
DQ=1;
dat>>=1;
}
delay1(5);
}
void get_nt()//获取温度
{
unsigned char a=0;
unsigned char b=0;
init_ds();
sbit ACC0 = ACC^0;
sbit ACC7 = ACC^7;
unsigned char time;
#define ads_y 0
#define ads_mo 3
#define ads_d 6
#define ads_w 9
#define ads_h 65
#define ads_m 68
#define ads_s 71
DQ=0; //单片机将DQ拉低
delay1(80); //精确延时大于480us
DQ=1; //拉高总线
delay1(10);
x=DQ; //稍做延时后如果x=0则初始化成功x=1则初始化失败
delay1(5);
}
unsigned char read_ds()///ds读一个字节
{
unsigned char i=0;
while(s0==0);
delay_1302(30000);
while(s0==1)
{
if(s1==0)
{
DS1302_GetTime(DS1302_WEEK);
time++;
DS1302_SetTime(DS1302_WEEK,time);
display_nt2(ads_w,time);
write_com(0x80+ads_w);
display_nt2(ads_w,time);
DS1302_GetTime(DS1302_HOUR);
display_nt(ads_h,time);
DS1302_GetTime(DS1302_MINUTE);
display_nt(ads_m,time);
DS1302_GetTime(DS1302_SECOND);
{
unsigned char i;
for(i=8; i>0; i--)
{
ACC = ACC >>1; //相当于汇编中的RRC
ACC7 = DS1302_IO;
DS1302_CLK = 1;
DS1302_CLK = 0;
}
return(ACC);
}
void Write1302(unsigned char ucAddr, unsigned char ucDa) //ucAddr: DS1302地址, ucData:要写的数据
display_nt(ads_y,time);
DS1302_GetTime(DS1302_MONTH);
display_nt(ads_mo,time);
DS1302_GetTime(DS1302_DAY);
display_nt(ads_d,time);
DS1302_GetTime(DS1302_WEEK);
相关文档
最新文档