/*程序调试的使用用使用keil51,可以在网上下个,也不知道你会用不,便宜好后生产hex文件,可以烧到单片机里面,也可以用protues
在电脑上面调试,我给你的截图就是我在线调试的使用的图片。
作者 :袁洋洋
安阳工学院06电子信息与电气工程系
e_mail: yangyang860214@sina.com*/
#include<reg52.h>
#include<1602.h>
#include<ds1302.h>
#include<ds18b20.h>
#define uint unsigned int
#define uchar unsigned char
uchar tflag;
uint tvalue;
uchar sec,min,hour,date,month,day,year;
uchar code table1[]={"date: : : "};
uchar code table2[]={"time: : : "};
sbit s1=P3^0;
sbit s2=P3^1;
sbit s3=P3^5;
uchar flag;
uchar s1num;
/*void init_ds1302()
{
settime_ds1302(0x80,23);
settime_ds1302(0x82,23);
settime_ds1302(0x84,23);
settime_ds1302(0x86,23);
settime_ds1302(0x88,9);
settime_ds1302(0x8a,3);
settime_ds1302(0x8c,9);//该段程序是对ds1302芯片的初次写入日期和时间,在调试的时候可以不要
}*/
void keyscan()//实现日期和时间的调整。由于水平太菜,写的程序太长,网上高手写的就短多了。
{
if(s1==0)
{
delay(5);
if(s1==0)
{
while(!s1);
s1num++;
if(s1num==1)
{
write_com(0x0f);
gotoxy(2,12);//按一次键,时间停止,秒光标闪烁
flag=1;
}
if(s1num==2)
{
gotoxy(2,9);//分光标闪烁
}
if(s1num==3)
{
gotoxy(2,6);
}
if(s1num==4)
gotoxy(1,15);
if(s1num==5)
gotoxy(1,12);
if(s1num==6)
gotoxy(1,9);
if(s1num==7)
gotoxy(1,6);
if(s1num==8)
{
s1num=0;
write_com(0x0c);
settime_ds1302(0x80,sec);
settime_ds1302(0x82,min);
settime_ds1302(0x84,hour);
settime_ds1302(0x86,date);
settime_ds1302(0x88,month);
settime_ds1302(0x8a,day);
settime_ds1302(0x8c,year);
flag=0;
}
}
}
if(s1num!=0)
{
if(s2==0)
{
delay(5);
if(s2==0)
{
while(!s2);
if(s1num==1)
{
sec++;
if(sec==60)
{
sec=0;
}
gotoxy(2,11);
write_num(sec);
gotoxy(2,12);
}
if(s1num==2)
{
min++;
if(min==60)
{
min=0;
}
gotoxy(2,8);
write_num(min);
gotoxy(2,9);
}
if(s1num==3)
{
hour++;
if(hour==24)
{
hour=0;
}
gotoxy(2,5);
write_num(hour);
gotoxy(2,6);
}
if(s1num==4)
{
day++;
if(day==8)
day=0;
gotoxy(1,14);
write_num(day);
gotoxy(1,15);
}
if(s1num==5)
{
date++;
if(date==32)
date=0;
gotoxy(1,11);
write_num(date);
gotoxy(1,12);
}
if(s1num==6)
{
month++;
if(month==13)
month=0;
gotoxy(1,8);
write_num(month);
gotoxy(1,9);
}
if(s1num==7)
{
year++;
gotoxy(1,5);
write_num(year);
gotoxy(1,6);
}
}
}
if(s3==0)
{
delay(5);
if(s3==0)
{
while(!s3);
if(s1num==1)
{
sec--;
if(sec==-1)
{
sec=59;
}
gotoxy(2,11);
write_num(sec);
gotoxy(2,12);
}
if(s1num==2)
{
min--;
if(min==-1)
{
min=59;
}
gotoxy(2,8);
write_num(min);
gotoxy(2,9);
}
if(s1num==3)
{
hour--;
if(hour==-1)
{
hour=23;
}
gotoxy(2,5);
write_num(hour);
gotoxy(2,6);
}
if(s1num==4)
{
day--;
if(day==0)
day=7;
gotoxy(1,14);
write_num(day);
gotoxy(1,15);
}
if(s1num==5)
{
date--;
if(date==0)
date=31;
gotoxy(1,11);
write_num(date);
gotoxy(1,12);
}
if(s1num==6)
{
month--;
if(month==0)
month=12;
gotoxy(1,8);
write_num(month);
gotoxy(1,9);
}
if(s1num==7)
{
year--;
gotoxy(1,5);
write_num(year);
gotoxy(1,6);
}
}
}
}
}
void main()
{
init_lcd();
gotoxy(1,0);
write_str(&table1);
gotoxy(2,0);
write_str(&table2);
//init_ds1302();
while(1)
{ keyscan();
if(flag==0)
{
read_temp();
ds1820disp();
sec=gettime_1302(0x81);
gotoxy(2,11);
write_num(sec);
min=gettime_1302(0x83);
gotoxy(2,8);
write_num(min);
hour=gettime_1302(0x85);
gotoxy(2,5);
write_num(hour);
date=gettime_1302(0x87);
gotoxy(1,11);
write_num(date);
month=gettime_1302(0x89);
gotoxy(1,8);
write_num(month);
year=gettime_1302(0x8d);
gotoxy(1,5);
write_num(year);
day=gettime_1302(0x8b);
gotoxy(1,14);
write_num(day);
}
}
}