单片机万年历 时钟 闹钟 温度程序..

} if(s1num==4) { } if(s1num==5) { write_com(0x80+0x40+4);

write_com(0x80+9);

write_com(0x80);

} if(s1num==6) { } } }

if(s1num!=0) { if(w2==0) { delay(5); if(w2==0) {

write_date(0x30);

s1num=0;

write_com(0x0c);

while(!w2); if(s1num==1) { miao1++; if(miao1==60) miao1=0; write_sfm(10,miao1); write_com(0x80+0x40+10); } if(s1num==2) { fen1++; if(fen1==60) fen1=0; write_sfm(7,fen1); write_com(0x80+0x40+7); } if(s1num==3)

{ } if(s1num==4) shi1++; if(shi1==24) shi1=0;

write_sfm(4,shi1);

write_com(0x80+0x40+4);

} if(w4==0) { delay(5); if(w4==0) {

}

while(!w4); if(s1num==1) { } if(s1num==2) { } if(s1num==3) {

{ ri1++; if(ri1==32) ri1=1; write_sfr(9,ri1); write_com(0x80+9);

}

miao1--;

if(miao1==-1) miao1=59;

write_sfm(10,miao1);

write_com(0x80+0x40+10);

fen1--;

if(fen1==-1) fen1=59; write_sfm(7,fen1);

write_com(0x80+0x40+7);

shi1--;

if(shi1==-1)

shi1=23; write_sfm(4,shi1); write_com(0x80+0x40+4); } if(s1num==4) { ri1--; if(ri1==0) ri1=31; write_sfr(9,ri1); write_com(0x80+9); } } } } return miao1,fen1,shi1,ri1; }

//************************************************* //************DS18b20程序********************

//**************************************************

/*void delay1(uint t) //2 {

while(t--); //延时 }

void init_ds18b20(void) //3 {

uchar n; DQ=1; delay1(8); DQ=0;

delay1(80); //延时大约600us DQ=1; delay1(8); n=DQ; //主机采样0表示传感正常 1表示无传感或传感已坏 delay1(4); }

void write_byte(uchar dat) //写一个字节 //4 {

uchar i;

for(i=0;i<8;i++) {

DQ=0;

DQ=dat&0x01; //低位在前 delay1(4); DQ=1; dat>>=1; }

delay1(4); }

uchar read_byte(void) //读一个字节 {

uchar i,value; for(i=0;i<8;i++) {

DQ=0; //先将DQ拉低 value>>=1; DQ=1; if(DQ)

value|=0x80; //置1 delay1(4); }

return value; }

uchar readtemperature(void) {

uchar a,b;

init_ds18b20(); //初始化18b20 write_byte(0xcc); //跳过ROM write_byte(0x44); //启动温度测量 delay1(300);

init_ds18b20();

write_byte(0xcc); //跳过ROM write_byte(0xbe); //读温度 a=read_byte(); // 读温度低八位 按顺序读寄存器 b=read_byte(); //读温度高八位 if(b>0x80) { b=0x00;

//5 //6

联系客服:779662525#qq.com(#替换为@)