本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
#include<reg52.h>
#include<intrins.h>
#include<define.h>
#include<1302.h>
#include<1602.h>
#include<delay.h>
#include<18b20.h>
void write_sfm(uchar add,uchar dat)
{
uchar ge,shi;
ge=dat%16;
shi=dat/16;
write_1602_com(0x80+0x40+add);
write_1602_dat(0x30+shi);
write_1602_dat(0x30+ge);
}
void write_nyr(uchar add,uchar dat)
{
uchar ge,shi;
ge=dat%16;
shi=dat/16;
write_1602_com(0x80+add);
write_1602_dat(0x30+shi);
write_1602_dat(0x30+ge);
}
void write_week(uchar add,uchar dat)
{
write_1602_com(0x80+add);
switch(dat)
{
case 1:
write_1602_dat(ta2[0]);
write_1602_dat(ta2[1]);
write_1602_dat(ta2[2]);
break;
case 2:
write_1602_dat(ta2[4]);
write_1602_dat(ta2[5]);
write_1602_dat(ta2[6]);
break;
case 3:
write_1602_dat(ta2[8]);
write_1602_dat(ta2[9]);
write_1602_dat(ta2[10]);
break;
case 4:
write_1602_dat(ta2[12]);
write_1602_dat(ta2[13]);
write_1602_dat(ta2[14]);
break;
case 5:
write_1602_dat(ta2[16]);
write_1602_dat(ta2[17]);
write_1602_dat(ta2[18]);
break;
case 6:
write_1602_dat(ta2[20]);
write_1602_dat(ta2[21]);
write_1602_dat(ta2[22]);
break;
case 7:
write_1602_dat(ta2[24]);
write_1602_dat(ta2[25]);
write_1602_dat(ta2[26]);
break;
}
}
void write_temp(uchar add,uchar dat)
{
uchar ge,shi;
ge=dat%10;
shi=dat/10;
write_1602_com(0x80+0x40+add);
write_1602_dat(0x30+shi);
write_1602_dat(0x30+ge);
}
void display()
{
write_sfm(9,time_data[6]);
delay(2);
write_sfm(6,time_data[5]);
delay(2);
write_sfm(3,time_data[4]);
delay(2);
write_nyr(3,time_data[0]);
delay(2);
write_nyr(6,time_data[2]);
delay(2);
write_nyr(9,time_data[3]);
delay(2);
write_week(12,time_data[1]);
delay(2);
write_temp(12,temp);
delay(2);
}
void keyscan()
{
uchar num1;
if(k1==0)
{
delay(5);
num1=1;
if(k1==0)
{
num++;
while(!k1);
read_rtc();
write_ds1302(0x8e,0x00);
write_ds1302(0x80,0x80);
write_ds1302(0x8e,0x80);
if(num==1)
{
write_1602_com(0x0f);
write_1602_com(0x80+0x40+10);
}
if(num==2)
{
write_1602_com(0x80+0x40+6);
}
if(num==3)
{
write_1602_com(0x80+0x40+3);
}
if(num==4)
{
write_1602_com(0x80+12);
}
if(num==5)
{
write_1602_com(0x80+9);
}
if(num==6)
{
write_1602_com(0x80+6);
}
if(num==7)
{
write_1602_com(0x80+3);
}
if(num==8)
{
num=0;
write_1602_com(0x0c);
write_ds1302(0x8e,0x00);
write_ds1302(0x80,0x00);
}
}
}
if(k2==0)
{
delay(5);
if(k2==0)
{
while(!k2);
switch(num)
{ case 1:
miao++;
if(miao==60)
miao=0;
break;
case 2:
fen++;
if(fen==60)
fen=0;
break;
case 3:
shi++;
if(shi==24)
shi=0;
break;
case 4:
week++;
if(week==8)
week=1;
break;
case 5:
ri++;
if(ri==32)
ri=1;
break;
case 6:
yue++;
if(yue==13)
yue=1;
break;
case 7:
nian++;
if(nian==100)
nian=0;
break;
}
}
}
if(k3==0)
{
delay(5);
if(k3==0)
{
while(!k3);
switch(num)
{
case 1:
miao--;
if(miao==-1)
miao=59;
break;
case 2:
fen--;
if(fen==-1)
fen=59;
break;
case 3:
shi--;
if(shi==-1)
shi=23;
break;
case 4:
week--;
if(week==0)
week=7;
break;
case 5:
ri--;
if(ri==0)
ri=31;
break;
case 6:
yue--;
if(yue==0)
yue=12;
break;
case 7:
nian--;
if(nian==-1)
nian=99;
break;
}
}
if(k4==0)
{
delay(5);
if(k4==0)
{
while(!k4);
num=8;
}
}
}
}
void main()
{
uchar i;
init();
write_1602_com(0x80);
for(i=0;i<11;i++)
{
write_1602_dat(ta[i]);
delay(2);
}
write_1602_com(0x80+0x40);
for(i=0;i<11;i++)
{
write_1602_dat(ta1[i]);
delay(2);
}
set_rtc();
while(1)
{
read_rtc();;
temp=readtemperature();
display();
keyscan();
}
}
这是1302.h的程序
void write_ds1302_byte(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
sck=0;
io=dat&0x01;
dat=dat>>1;
sck=1;
}
}
void write_ds1302(uchar add,uchar dat)
{
rst=0;
_nop_();
sck=0;
_nop_();
rst=1;
_nop_();
write_ds1302_byte(add);
write_ds1302_byte(dat);
rst=0;
_nop_();
io=1;
sck=1;
}
uchar read_ds1302(uchar add)
{
uchar i,value;
rst=0;
_nop_();
sck=0;
_nop_();
rst=1;
_nop_();
write_ds1302_byte(add);
for(i=0;i<8;i++)
{
value=value>>1;
sck=0;
if(io)
value=value|0x80;
sck=1;
}
rst=0;
_nop_();
sck=0;
_nop_();
sck=1;
io=1;
return value;
}
void set_rtc()
{
uchar i,j;
for(i=0;i<7;i++)
{
j=time_data[i]/10;
time_data[i]=time_data[i]%10;
time_data[i]=time_data[i]+j*16;
}
write_ds1302(0x8e,0x00);
for(i=0;i<7;i++)
{
write_ds1302(write_add[i],time_data[i]);
}
write_ds1302(0x8e,0x80);
}
void read_rtc()
{
uchar i;
for(i=0;i<7;i++)
{
time_data[i]=read_ds1302(read_add[i]);
}
} |