|
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code str1[]="2019-11-14 week4";
uchar code str2[]="23:59:55 ";
uchar code str3[]="0-22:00 ";
uchar code str4[]="0-23:00 ";
uchar c1=0,c2=0;//???? ?c1=1??c2=1?,?????
sbit RS=P2^0;
sbit RW=P2^1;
sbit E=P2^2;
bit s=0,d=1;// s???????,d=0???????
bit jia,jian;
uchar code string[]={0x0c,0xc7,0xc4,0xc1,0x89,0x86,0x83,0x8f,0x80,0x83,0x86,0xc0,0xc3,0xc6};//??????
uchar second=58,minute=59,hour=23,month=2,day=28,week=7,count=0;
uchar minute1=0,hour1=22,minute2=0,hour2=23;//??
uchar t_symbol; //??????,?1????,?0????
uint T;
unsigned int year=2019; //0-65535
int m=0;
sbit key1=P2^3;//????
sbit key2=P2^4;//???
sbit key3=P2^5;//???
sbit key4=P2^6;//????
sbit key5=P2^7;//???
sbit beep=P1^0;//???
sbit DQ=P3^3;//????
void delayms()
{ uchar i;
for(i=0;i<122;i++);
}
void busy_check()
{ P0=0xff;
RS=0;
RW=1;
E=1;
E=0;
while(P0&0x80)
{E=0;
E=1;
}
delayms();
}
void write_LCD_com(uchar cmd)
{
busy_check();
E=0;
RS=0;
RW=0;
E=1;
P0=cmd;
E=0;
delayms();
}
void write_LCD_data(uchar dat)
{ busy_check();
E=0;
RS=1;
RW=0;
E=1;
P0=dat;
E=0;
delayms();
}
void SET_LCD_pos(uchar x,uchar y)
{ if(y==0)
write_LCD_com(0x80|x);
if(y==1)
write_LCD_com(0xc0|x);
}
void show_LCD(uchar *str)
{ uchar i;
for(i=0;i<16;i++)
write_LCD_data(str);
}
/****???LCD****/
void init_LCD()
{ write_LCD_com(0x01);
write_LCD_com(0x38);
write_LCD_com(0x0c);
write_LCD_com(0x06);
}
void delay_18B20(unsigned int i)//??1-255??
{while(i--);}
uchar ds1820rst() //ds1820??
{ unsigned char g=0;
DQ=1; //DQ??
delay_18B20(8); //??
DQ=0; //??????
delay_18B20(80); //????480us
DQ=1; //DQ??
delay_18B20(8);
g=DQ; //?g=0,?ds1820??,?????
delay_18B20(20);
return(g);
}
uchar ds1820_rd()//???
{ unsigned char e=0;
unsigned char dat = 0; //???????
for (e=8;e>0;e--)
{ DQ = 0; //?????
dat>>=1;
DQ = 1; //?????
if(DQ==1)
dat|=0x80;
delay_18B20(10);
}
return(dat); //??????
}
void ds1820wr(uchar wdate)//???
{unsigned char i=0;
for (i=8; i>0; i--)
{ DQ = 0;
DQ = wdate&0x01; //????
delay_18B20(10);
DQ = 1;
wdate>>=1; //???????
}
}
void read_temp() //????????
{uchar a=0,b=0;
ds1820rst(); //ds1820??
ds1820wr(0xcc); //??????
ds1820wr(0x44); //??????
delay_18B20(150);
ds1820rst(); //ds1820??
ds1820wr(0xcc); //??????
ds1820wr(0xbe); //????
delay_18B20(150);
a=ds1820_rd(); //????????
b=ds1820_rd(); //????????
T=b;
T<<=8;
T=T|a;
if(T<0x0fff) //????
t_symbol=0;
else
{T=~T+1; //???,????
t_symbol=1;}
T=T*(0.625); //?????10? ?????
}
void ds1820_show()//?????
{ uchar flagdat,T0,T1,T2;
T0=T/100+'0';//???
T1=T%100/10+'0';//???
T2=T%10+'0';//???
read_temp();
if(t_symbol==0)
flagdat=0x20;//????????
else
flagdat=0x2d;//???????:-
if(T0==0x30)
{T0=0x20;} //?????0,???
}
/****????****/
void zifushow1()
{ uchar flagdat,T0,T1,T2;
SET_LCD_pos(9,1);
write_LCD_data(flagdat);//?????
SET_LCD_pos(10,1);
write_LCD_data(T0); //????
SET_LCD_pos(11,1);
write_LCD_data(T1); //????
SET_LCD_pos(12,1);
write_LCD_data(0xa5); //?????
SET_LCD_pos(13,1);
write_LCD_data(T2); //?????
SET_LCD_pos(15,1);
write_LCD_data('C');
SET_LCD_pos(14,1);
write_LCD_data(0xdf);
SET_LCD_pos(7,1);
write_LCD_data(second%10+'0');
SET_LCD_pos(6,1);
write_LCD_data(second/10+'0');
SET_LCD_pos(5,1);
write_LCD_data(':');
SET_LCD_pos(4,1);
write_LCD_data(minute%10+'0');
SET_LCD_pos(3,1);
write_LCD_data(minute/10+'0');
SET_LCD_pos(2,1);
write_LCD_data(':');
SET_LCD_pos(1,1);
write_LCD_data(hour%10+'0');
SET_LCD_pos(0,1);
write_LCD_data(hour/10+'0');
SET_LCD_pos(9,0);
write_LCD_data(day%10+'0');
SET_LCD_pos(8,0);
write_LCD_data(day/10+'0');
SET_LCD_pos(7,0);
write_LCD_data('-');
SET_LCD_pos(6,0);
write_LCD_data(month%10+'0');
SET_LCD_pos(5,0);
write_LCD_data(month/10+'0');
SET_LCD_pos(4,0);
write_LCD_data('-');
SET_LCD_pos(3,0);
write_LCD_data(year%10+'0');
SET_LCD_pos(2,0);
write_LCD_data(year/10%10+'0');
SET_LCD_pos(1,0);
write_LCD_data(year/100%10+'0');
SET_LCD_pos(0,0);
write_LCD_data(year/1000+'0');
SET_LCD_pos(11,0);
write_LCD_data('w');
SET_LCD_pos(12,0);
write_LCD_data('e');
SET_LCD_pos(13,0);
write_LCD_data('e');
SET_LCD_pos(14,0);
write_LCD_data('k');
SET_LCD_pos(15,0);
write_LCD_data(week%8+'0');
}
/*******???*******/
void speaker()
{
if(c1==1)
if(hour1==hour&&minute1==minute)
beep=!beep;
if(c2==1)
if(hour2==hour&&minute2==minute)
beep=!beep;
}
/*******??????*******/
void zifushow2()
{
SET_LCD_pos(0,0);
write_LCD_data(c1+'0');
SET_LCD_pos(1,0);
write_LCD_data('-');
SET_LCD_pos(2,0);
write_LCD_data(hour1/10+'0');
SET_LCD_pos(3,0);
write_LCD_data(hour1%10+'0');
SET_LCD_pos(4,0);
write_LCD_data(':');
SET_LCD_pos(5,0);
write_LCD_data(minute1/10+'0');
SET_LCD_pos(6,0);
write_LCD_data(minute1%10+'0');
SET_LCD_pos(0,1);
write_LCD_data(c2+'0');
SET_LCD_pos(1,1);
write_LCD_data('-');
SET_LCD_pos(2,1);
write_LCD_data(hour2/10+'0');
SET_LCD_pos(3,1);
write_LCD_data(hour2%10+'0');
SET_LCD_pos(4,1);
write_LCD_data(':');
SET_LCD_pos(5,1);
write_LCD_data(minute2/10+'0');
SET_LCD_pos(6,1);
write_LCD_data(minute2%10+'0');
}
/***????????*****/
void time_date()
{ if(second==60)
{ second=0;
minute++;}
if(minute==60)
{ minute=0;
hour++ ;}
if(hour==24)
{ hour=0;
day++;
week++;}
if(week==8)
{ week=1;}
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)//?????
{ if(day==32)
{ month++;
day=1;}
}
if(month==4||month==6||month==9||month==11)//?????
{ if(day==31)
{ day=1;
month++; }}
if(month==2)//???????
{
{if(year%400==0||(year%4==0&&year%100!=0))
{if(day==30)
{day=1;
month++;}}
else
{if(day==29)
{day=1;
month++;}
|
|