ThedesignofIntelligentTableLampBasedonMicrocomputer2015.5.14re200b4at89s52re200bds12c887ds18b20.1IO251DODODOled3DS12C887DS12C8874DS18B20re200b4BISS0001BISS0001BISS0001OP1OP2VM(0.5VDD)V2COP1COP2VsVH0.7VDDVL0.3VDDVDD=5V1VCOP3VcVR(0.2VDD)COP3U2,VsVcVRCOP3A0TxV2TxTxVoTiTiV2Vo,DS12C887IBMATMC146818BDS1287102100BCD122412AMPMMOTOROLAINTEL/128RAM14114RAM(/IRQ)122ms500msDS18B20DS18B20120.51275055C~+125C(67F~+257F)EEPROM64ROMLED:PSIO#includereg52.h#defineucharunsignedchar#defineuintunsignedintsbitds=P2^4;//sbitbeep=P2^3;//sbitre=P2^2;//sbitgm=P2^7;//sbits0=P1^3;//sbits1=P3^0;//sbits2=P3^1;//sbits3=P3^4;//sbits4=P3^5;//sbits5=P3^6;//sbits6=P3^2;//sbitrs=P1^0;//sbitlcden=P1^2;//sbitwr=P1^1;//sbitled1=P2^0;sbitled2=P2^1;//ledsbitled3=P2^5;sbitled4=P2^6;sbitrd=P3^7;sbitdscs=P1^7;sbitdsas=P1^6;sbitdsrw=P1^5;//sbitdsds=P1^4;sbitdsirq=P3^3;uinttemp;floatf_temp;uchars5num=0,s0num=0,s6num=0;ucharflag1=0,flag_ri;//ucharcount,s1num,flag=0,t0_num;//ucharmiao,shi,fen,year,month,day,week,amiao,afen,ashi;ucharcodetable[]=20--;//ucharcodetable1[]=::;ucharcodetable2[]=WELCOME!;voidwrite_ds(uchar,uchar);//voidset_alarm(uchar,uchar,uchar);voidread_alarm();ucharread_ds(uchar);voidset_time();/************************************************//*led*/voidled(ucharx){switch(x){case0:led1=1;led2=0;led3=1;led4=0;break;case1:led1=0;led2=0;led3=1;led4=0;break;case3:led1=0;led2=0;led3=0;led4=1;break;case2:led1=1;led2=1;led3=0;led4=0;break;case4:led1=0;led2=1;led3=0;led4=1;break;}}/***************************************************/voiddelay(uintz)//{uintx,y;for(x=z;x0;x--)for(y=110;y0;y--);}voiddi()//{beep=0;delay(100);beep=1;}voidwrite_com(ucharcom){//rs=0;lcden=0;P0=com;delay(3);lcden=1;delay(3);lcden=0;}voidwrite_date(uchardate){//rs=1;lcden=0;P0=date;delay(3);lcden=1;delay(3);lcden=0;}voidinit(){//uchari;EA=1;//EX0=1;//1IT0=1;//EX1=1;//1IT1=1;//flag1=0;//t0_num=0;s1num=0;week=1;lcden=0;rd=0;/*DS12C887write_ds(0x0A,0x20);//write_ds(0x0B,0x26);//24//set_time();//-----------------------------------------------------*/write_com(0x38);//1602write_com(0x0c);write_com(0x06);write_com(0x01);write_com(0x80);for(i=0;i15;i++)//{write_date(table[i]);delay(1);}write_com(0x80+0x40);for(i=0;i16;i++){write_date(table1[i]);delay(1);}}voidwrite_sfm(ucharadd,chardate){//16024710charshi,ge;shi=date/10;ge=date%10;write_com(0x80+0x40+add);write_date(0x30+shi);write_date(0x30+ge);}voidwrite_nyr(ucharadd,chardate){//1602369charshi,ge;shi=date/10;ge=date%10;write_com(0x80+add);write_date(0x30+shi);write_date(0x30+ge);}voidwrite_week(charwe){//write_com(0x80+12);switch(we){case1:write_date('M');delay(5);write_date('O');delay(5);write_date('N');break;case2:write_date('T');delay(5);write_date('U');delay(5);write_date('E');break;case3:write_date('W');delay(5);write_date('E');delay(5);write_date('D');break;case4:write_date('T');delay(5);write_date('H');delay(5);write_date('U');break;case5:write_date('F');delay(5);write_date('R');delay(5);write_date('I');break;case6:write_date('S');delay(5);write_date('A');delay(5);write_date('T');break;case7:write_date('S');delay(5);write_date('U');delay(5);write_date('N');break;}}voidkeyscan(){if(flag_ri==1){//if((s1==0)||(s2==0)||(s3==0)||(s4==0)){delay(5);if((s1==0)||(s2==0)||(s3==0)||(s4==0)){while(!(s1&&s2&&s3&&s4));di();flag_ri=0;//}}}if(s1==0)//S1{delay(10);if(s1==0){s1num++;//if(flag1==1)if(s1num==4)s1num=1;flag=1;while(!s1);di();switch(s1num){//case1:write_com(0x80+0x40+10);write_com(0x0f);break;case2:write_com(0x80+0x40+7);break;case3:write_com(0x80+0x40+4);break;case4:write_com(0x80+12);break;case5:write_com(0x80+9);break;case6:write_com(0x80+6);break;case7:write_com(0x80+3);break;case8:s1num=0;write_com(0x0c);flag=0;write_ds(0,miao);write_ds(2,fen);write_ds(4,shi);write_ds(6,week);write_ds(7,day);write_ds(8,month);write_ds(9,year);break;}}}if(s1num!=0)//S1S2S3{if(s2==0){delay(10);if(s2==0){while(!s2);di();switch(s1num){//case1:miao++;if(miao==60)miao=0;write_sfm(10,miao);write_com(0x80+0x40+10);break;case2:fen++;if(fen==60)fen=0;write_sfm(7,fen);write_com(0x80+0x40+7);break;case3:shi++;if(shi==24)shi=0;write_sfm(4,shi);write_com(0x80+0x40+4);break;case4:week++;if(week==8)week=1;write_week(week);write_com(0x80+12);break;case5:day++;if(day==32)day=1;write_nyr(9,day);write_com(0x80+9);break;case6:month++;if(month==13)month=1;write_nyr(6,month);write_com(0x80+6);break;case7:year++;if(year==100)year=0;write_nyr(3,year);write_com(0x80+3);break;}}}if(s3==0){delay(10);if(s3==0){while(!s3);di();switch(s1num){//case1:miao--;if(miao==-1)miao=59;write_sfm(10,miao);write_com(0x80+0x40+10);break;case2:fen--;if(fen==-1)fen=59;write_sfm(7,fen);write_com(0x80+0x40+7);break;case3:shi--;if(shi==-1)shi=23;write_sfm(4,shi);write_com(0x80+0x40+4);break;case4:week--;if(week==0)week=7;write_week(week);write_com(0x80+12);break;case5:day--;if(day==0)day=31;write_nyr(9,day);write_com(0x80+9);break;case6:month--;if(month==0)month=12;write_nyr(6,month);write_com(0x80+6);break;case7:year--;if(year==-1)year=99;write_nyr(3,year);write_com(0x80+3);br