//2009年10月
//王德华 丁鹏
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit beep=P1^2;
/*****12864使能位定义***/
sbit lcdne=P1^5;
sbit lcdrs=P1^7;
sbit lcdrw=P1^6;
/*****DS12CR887时实时钟芯片使能位定义***/
sbit dscs=P2^4;
sbit dsas=P2^5;
sbit dsrw=P2^6;
sbit dsds=P2^7;
/*屏蔽内容****屏蔽内容****/
sbit k1=P2^1;
sbit k2=P2^2;
sbit k3=P2^3;
//sbit k4=P1^3;
/*屏蔽内容****屏蔽内容****/
sbit DQ=P2^0;
sbit zhen=P1^4;
void delay(uchar i)
{
for(;i>0;i--);
}
void delay1(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void didi()
{
beep=1;
delay1(5);
beep=0;
delay1(3);
beep=1;
delay1(5);
beep=0;
}
void key()
{
if(k1==0)
{
delay(5);
if(k1==0)
didi() ;
}
if(k2==0)
{
delay(5);
if(k2==0)
didi() ;
}
if(k3==0)
{
delay(5);
if(k3==0)
didi() ;
}
}
void main()
{
beep=0;
zhen=1;
key();
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
-----------------------------------------------------------------------
//2009年10月
//王德华 丁鹏
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit lcdne=P3^5;
sbit lcdrs=P3^7;
sbit lcdrw=P3^6;
/*屏蔽内容****DS12CR887时实时钟芯片使能位定义*屏蔽内容**屏蔽内容****/
sbit dscs=P1^7;
sbit dsas=P1^6;
sbit dsrw=P1^5;
sbit dsds=P1^4;
/*屏蔽内容**屏蔽内容*按键定义*屏蔽内容**屏蔽内容**屏蔽内容****/
sbit k1=P1^1;
sbit k2=P1^2;
sbit k3=P1^3;
sbit k4=P3^4;
/*屏蔽内容**屏蔽内容**屏蔽内容**屏蔽内容**屏蔽内容**屏蔽内容****/
sbit DQ=P1^0;
sbit beep=P3^0; //蜂鸣器
/*屏蔽内容***屏蔽内容***/
uchar e[]="星期";
uchar f[]="时";
uchar g[]="分";
uchar h[]="秒";
uchar s[]="℃";
uchar k[]="温度";
uchar s1[]="一";
uchar s2[]="二";
uchar s3[]="三";
uchar s4[]="四";
uchar s5[]="五";
uchar s6[]="六";
uchar s7[]="日";
uchar sinum,sinum1,flag;
void write_ds(uchar add,uchar date);
void write_com(uchar com);
void write_date(uchar date);
uchar miao,shi,fen,xq,ri,yue,nian,keysh,amiao,ashi,afen;
uint wd;
/**屏蔽内容**屏蔽内容****/
void delay(uchar i)
{
for(;i>0;i--);
}
/*屏蔽内容**屏蔽内容***/
void delay1(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void didi()
{
beep=0;
delay1(70);
beep=1;
delay1(70);
beep=0;
delay1(70);
beep=1;
}
/*屏蔽内容***18b20初始化***屏蔽内容***/
uchar fv(void)
{
uchar x;
DQ=0;
delay(29);
DQ=1;
delay(3);
x=DQ;
delay(25);
return(x);
}
/*****屏蔽内?*18b20读一个字捷**屏蔽内容***/
uchar readbyte(void)
{
uchar i,dat=0;
for(i=8;i>0;i--)
{
dat>>=1;
DQ=0;
DQ=1;
delay(1);
if(DQ)
dat|=0x80;
delay(6);
}
return(dat);
}
/*屏蔽内容****18B20写一个字节**屏蔽内容***/
void writebyte(uchar dat)
{
uchar i;
for(i=8;i>0;i--)
{
DQ=0;
DQ=dat&0x01;
delay(5);
DQ=1;
dat=dat/2; //dat/2同dat>>=1
}
delay(5);
}
/*屏蔽内容***读温度并计算**屏蔽内容***/
uint tc(void)
{
uchar a,b;
uint t;
float tt;
fv();
writebyte(0xcc);
writebyte(0x44);
fv();
writebyte(0xcc);
writebyte(0xbe);
a=readbyte();
b=readbyte();
t=b*256+a;
tt=t*0.0625;
t=tt*10+0.5;
return(t);
}
/*屏蔽内容****显示温度的地址,数据*屏蔽内容****/
void write_sfc( date)
{
uchar shi,ge,xiao,aa;
shi=date/100;
aa=date%100;
ge=aa/10;
xiao=date%10;
write_com(0x98+4);
write_date(0x30+shi);
write_date(0x30+ge);
write_com(0x98+0x05);
write_date(0x2e);
write_date(0x30+xiao);
// write_date(0x43);
}
/*屏蔽内容*****887intel总线写时序***屏蔽内容***/
void write_ds(uchar add,uchar date)
{
dsas=1;
dsds=1;
dsrw=1;
dscs=0;
P0=add;
dsas=0;
dsrw=0;
P0=date;
dsrw=1;
dsas=1;
dscs=1;
}
void set_time()
{
write_ds(0x0A,0x20);
write_ds(0x0B,0x26);//第一次使用时钟时打开振荡器用的
write_ds(2,18);//初始化分钟
write_ds(4,19);//初始化小时
write_ds(9,9);//初始化年
write_ds(8,3);//初始化月
write_ds(7,30);//初始化日
write_ds(6,1);
}
/*屏蔽内容******887intel总线读时序**屏蔽内容***/
uchar read_ds(uchar add)
{
uchar ds_date;
dsas=1;
dsds=1;
dsrw=1;
dscs=0;
P0=add;
dsas=0;
dsds=0;
P0=0xff;
ds_date=P0;
dsds=1;
dsas=1;
dscs=1;
return ds_date;
}
/*屏蔽内容**12864忙检测***屏蔽内容*/
void buys()
{
P2=0xff;
lcdrs=0;
lcdrw=1;
lcdne=1;
if(P0^7==1)
delay1(2);
lcdne=0;
}
//*屏蔽内容***12864写命令***屏蔽内容*/
void write_com(uchar com)
{
buys();
lcdrw=0;
lcdrs=0;
lcdne=1;
delay1(2);
P2=com;
delay1(2);
lcdne=0;
P2=0xff;
}
//*屏蔽内容***12864写数据***屏蔽内容*/
void write_date(uchar date)
{
buys();
lcdrw=0;
lcdrs=1;
lcdne=1;
delay1(2);
P2=date;
delay1(2);
lcdne=0;
delay1(2);
P2=0xff;
}
/*屏蔽内容****屏蔽内容*/
void init()
{
delay(50);
write_com(0x30);
write_com(0x06);
write_com(0x0c);
write_com(0x00);
write_com(0x06);
// set_time();
// write_ds(0x0a,0x20);
// write_ds(0x0b,0x26);
}
void write_sfs(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x88+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
//*屏蔽内容***星期显示地址,数据***屏蔽内容**//
void write_sfq(uchar add,uchar date)
{
uchar i;
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x90+add);
if(ge==1)
{
for(i=0;i<2;i++)
write_date(s1);
}
else if(ge==2)
{
for(i=0;i<2;i++)
write_date(s2);
}
else if(ge==3)
{
for(i=0;i<2;i++)
write_date(s3);
}
else if(ge==4)
{
for(i=0;i<2;i++)
write_date(s4);
}
else if(ge==5)
{
for(i=0;i<2;i++)
write_date(s5);
}
else if(ge==6)
{
for(i=0;i<2;i++)
write_date(s6);
}
else if(ge==7)
{
for(i=0;i<2;i++)
write_date(s7);
}
}
//*屏蔽内容****日显示地址,数据***屏蔽内容****
void write_sfm(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
void key()
{
if(k1==0)
{
delay1(5);
if(k1==0)
{delay1(50);
didi();
sinum++;
flag=1;
while(!k1);
if(sinum==1)
{
write_com(0x80+2);
write_com(0x0f);
}
if(sinum==2)
{
write_com(0x80+4);
}
if(sinum==3)
{
write_com(0x80+6);
}
if(sinum==4)
{
write_com(0x90+5);
}
if(sinum==5)
{
write_com(0x88+1);
}
if(sinum==6)
{
write_com(0x88+3);
}
if(sinum==7)
{
write_com(0x88+5);
}
if(sinum==8)
{
sinum=0;
write_com(0x0c);
flag=0;
write_ds(0,miao);
write_ds(2,fen);
write_ds(4,shi);
write_ds(6,xq);
write_ds(7,ri);
write_ds(8,yue);
write_ds(9,nian);
}
}
}
if(sinum!=0)
{
if(k2==0)
{
delay1(5);
if(k2==0)
{ delay1(50);
didi();
if(sinum==1)
{
nian++;
if(nian==99)
nian=0;
write_sfm(2,nian);
write_com(0x80+2);
}
if(sinum==2)
{
yue++;
if(yue==13)
yue=1;
write_sfm(4,yue);
write_com(0x80+4);
}
if(sinum==3)
{
ri++;
if(ri==32)
ri=1;
write_sfm(6,ri);
write_com(0x80+6);
}
if(sinum==4)
{
xq++;
if(xq==8)
xq=1;
write_sfq(5,xq);
write_com(0x90+5);
}
if(sinum==5)
{
shi++;
if(shi==24)
shi=0;
write_sfs(1,shi);
write_com(0x88+1);
}
if(sinum==6)
{
fen++;
if(fen==60)
fen=0;
write_sfs(3,fen);
write_com(0x88+3);
}
if(sinum==7)
{
miao++;
if(miao==60)
miao=0;
write_sfs(5,miao);
write_com(0x88+5);
}
}
}
if(k3==0)
{
delay1(5);
if(k3==0)
{delay1(50);
didi();
if(sinum==1)
{
nian--;
if(nian==-1)
nian=99;
write_sfm(2,nian);
write_com(0x80+2);
}
if(sinum==2)
{
yue--;
if(yue==-1)
yue=12;
write_sfm(4,yue);
write_com(0x80+4);
}
if(sinum==3)
{
ri--;
if(ri==-1)
ri=31;
write_sfm(6,ri);
write_com(0x80+6);
}
if(sinum==4)
{
xq--;
if(xq==-1)
xq=7;
write_sfq(5,xq);
write_com(0x90+5);
}
if(sinum==5)
{
shi--;
if(shi==-1)
shi=23;
write_sfs(1,shi);
write_com(0x88+1);
}
if(sinum==6)
{
fen--;
if(fen==-1)
fen=59;
write_sfs(3,fen);
write_com(0x88+3);
}
if(sinum==7)
{
miao--;
if(miao==-1)
miao=59;
write_sfs(5,miao);
write_com(0x88+5);
}
}
}
}
}
/*屏蔽内容**屏蔽内容**屏蔽内容**屏蔽内容**屏蔽内容**屏蔽内容**屏蔽内容**屏蔽内容**/
void main()
{
uchar i;
delay1(50);
init();
write_com(0x90+0x03);
for(i=0;i<4;i++)
write_date(e);
write_com(0x80+1);
write_date(2+48);
write_date(48);
write_com(0x88+0x02);
for(i=0;i<2;i++)
write_date(f);
write_com(0x88+4);
for(i=0;i<2;i++)
write_date(g);
write_com(0x88+6);
for(i=0;i<2;i++)
write_date(h);
write_com(0x98+0x02);
for(i=0;i<4;i++)
write_date(k);
write_com(0x98+0x06);
for(i=0;i<2;i++)
write_date(s);
while(1)
{
key();
if(flag==0)
{
miao=read_ds(0); //读秒
write_sfs(5,miao);
fen=read_ds(2); //读分
write_sfs(3,fen);
shi=read_ds(4); //读时
write_sfs(1,shi);
xq=read_ds(6); //读星期
write_sfq(5,xq);
ri=read_ds(7); //读日
write_sfm(6,ri);
yue=read_ds(8); //读月
write_sfm(4,yue);
nian=read_ds(9); //读年
write_sfm(2,nian);
wd=tc();
write_sfc(wd);
}
}
}
一周热门 更多>