新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 電子時鐘+測溫+紅外遙控調(diào)時程序

電子時鐘+測溫+紅外遙控調(diào)時程序

作者: 時間:2016-11-29 來源:網(wǎng)絡(luò) 收藏
/*****************************************************************************************************
作者:徐仁俊2011.5.12,采用1602液晶顯示器.紅外調(diào)時采用“海爾”遙控碼 CH+(0xb0),  CH-(0xa0) ,  MENU(0x9c) 分別調(diào)節(jié)時間******************************************************************************************************/#includesbit dula=P2^6;sbit wela=P2^7;sbit lcdwr=P3^6;sbit lcdrs=P3^5;sbit lcden=P3^4;sbit key1=P3^0;sbit key2=P3^1;sbit key3=P3^3;sbit DQ=P2^2;sbit ir=P3^2;#define uchar unsigned char#define uint unsigned intuchar code table0[]=" 2011-04-03 SUN";//16uchar code table1[]="       00:00:00";//10uchar code table9[]="0123456789";uchar code table2[]="MON";uchar code table3[]="TUE";uchar code table4[]="WED";uchar code table5[]="THU";uchar code table6[]="FRI";uchar code table7[]="SAT";uchar code table8[]="SUN";uchar num,m,n,aa,bb,cc,dd,kk,flag,i,j,flag1,pp,flag2;uchar ss[4];char shi,fen,miao,ee,ff,gg;uchar dat=0;uint dd1,temp;void delay(uchar z){uint x,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}void delay1(uchar i){while(i--);}void write_com(uchar com){lcdrs=0;delay(5);P0=com;delay(5);lcden=1;delay(5);lcden=0; }void write_data(uchar date){lcdrs=1;delay(5);P0=date;delay(5);lcden=1;delay(5);lcden=0;}void init(){dula=0;wela=0;lcdwr=0;lcdrs=1;lcden=0;shi=00;fen=00;miao=00;bb=0;cc=0;dd=0;ee=03;ff=04;gg=11;write_com(0x38);write_com(0x0c);write_com(0x06);write_com(0x80);write_com(0x01);for(num=0;num<15;num++){ write_data(table0[num]);delay(5);}write_com(0x80+0x40);for(num=0;num<15;num++){ write_data(table1[num]);delay(5);}ss[0]=0;ss[1]=0;ss[2]=0;ss[3]=0;TMOD=0x11;TH0=(65536-50000)/256;TL0=(65536-50000)%256;TH1=0;TL1=0;EA=1;ET0=1;TR0=1;TR1=0;write_com(0x80+0x40+4);write_data(0xdf);write_com(0x80+0x40+5);write_data(C); }uint low_ir_time(){TH1=0;TL1=0;TR1=1;while(!ir);TR1=0;return TH1*256+TL1;}uint high_ir_time(){TH1=0;TL1=0;TR1=1;while(ir);TR1=0;return TH1*256+TL1;}void init_DS18B20(){uchar x;DQ=1;delay1(8);DQ=0;delay1(80);DQ=1;delay1(14);x=DQ;delay1(20);  }void sfm_date(uchar add,uchar date1){ uchar shi,ge;shi=date1/10;ge=date1%10;write_com(0x80+0x40+add);write_data(0x30+shi);write_data(0x30+ge); }void nyr_date1(uchar add,uchar date1){ uchar shi,ge;shi=date1/10;ge=date1%10;write_com(0x80+add);write_data(0x30+shi);write_data(0x30+ge); }read_DS18B20(void){uchar i=0;uchar dat=0;for(i=8;i>0;i--){DQ=0;dat=dat>>1;DQ=1;if(DQ==1){dat=dat|0x80;}delay1(4);}return (dat); }write_DS18B20(uchar dat){uchar i=0;for(i=8;i>0;i--){DQ=0;DQ=dat&0x01;delay1(5);DQ=1;dat=dat>>1;}delay1(4);  }chuli_dat(void){uchar aa=0;uchar bb=0;uchar cc=0;init_DS18B20();write_DS18B20(0xCC);write_DS18B20(0x44);init_DS18B20();write_DS18B20(0xCC);write_DS18B20(0xBE);aa=read_DS18B20();bb=read_DS18B20();cc=(aa>>4)|(bb<<4);if(cc>128){cc=~cc+1;write_com(0x80+0x40+0x4a);write_data(0x2d);}return(cc);}void ir_key(){if(pp==0x9c){bb++;pp=0;if(bb==1){TR0=0;write_com(0x80+0x40+13);write_com(0x0f);}if(bb==2){write_com(0x80+0x40+10);}if(bb==3){write_com(0x80+0x40+7);}if(bb==4){write_com(0x80+12); }if(bb==5){write_com(0x80+9);}if(bb==6){write_com(0x80+6);}if(bb==7){write_com(0x80+3);}if(bb==8){bb=0;TR0=1;write_com(0x0c);}}if(bb==1){if(pp==0xb0){miao++;pp=0;if(miao==60){miao=0;}sfm_date(13,miao);write_com(0x80+0x40+13); }if(pp==0xa0){miao--;pp=0;if(miao==-1){miao=59;}sfm_date(13,miao);write_com(0x80+0x40+13); }}if(bb==2){if(pp==0xb0){fen++;pp=0;if(fen==60){fen=0;}sfm_date(10,fen);write_com(0x80+0x40+10); }if(pp==0xa0){fen--;pp=0;if(fen==-1){fen=59;}sfm_date(10,fen);write_com(0x80+0x40+10); }}if(bb==3){if(pp==0xb0){shi++;pp=0;if(shi==24){shi=0;}sfm_date(7,shi);write_com(0x80+0x40+7); }if(pp==0xa0){shi--;pp=0;if(shi==-1){shi=23;}sfm_date(7,shi);write_com(0x80+0x40+7); }}if(bb==4){if(pp==0xb0){dd++;pp=0;if(dd==1){for(cc=0;cc<3;cc++){write_data(table2[cc]);}}write_com(0x80+12);if(dd==2){for(cc=0;cc<3;cc++){write_data(table3[cc]);}}write_com(0x80+12);if(dd==3){for(cc=0;cc<3;cc++){write_data(table4[cc]);}}write_com(0x80+12);if(dd==4){for(cc=0;cc<3;cc++){write_data(table5[cc]);}}write_com(0x80+12);if(dd==5){for(cc=0;cc<3;cc++){write_data(table6[cc]);}}write_com(0x80+12);if(dd==6){for(cc=0;cc<3;cc++){write_data(table7[cc]);}}write_com(0x80+12);if(dd==7){dd=0;for(cc=0;cc<3;cc++){write_data(table8[cc]);}}write_com(0x80+12);}if(pp==0xa0){dd++;pp=0;if(dd==1){for(cc=0;cc<3;cc++){write_data(table8[cc]);}}write_com(0x80+12);if(dd==2){for(cc=0;cc<3;cc++){write_data(table7[cc]);}}write_com(0x80+12);if(dd==3){for(cc=0;cc<3;cc++){write_data(table6[cc]);}}write_com(0x80+12);if(dd==4){for(cc=0;cc<3;cc++){write_data(table5[cc]);}}write_com(0x80+12);if(dd==5){for(cc=0;cc<3;cc++){write_data(table4[cc]);}}write_com(0x80+12);if(dd==6){for(cc=0;cc<3;cc++){write_data(table3[cc]);}}write_com(0x80+12);if(dd==7){dd=0;for(cc=0;cc<3;cc++){write_data(table2[cc]);}}write_com(0x80+12);}}if(bb==5){if(pp==0xb0){ee++;pp=0;if(ee==32){ee=1;}nyr_date1(9,ee);write_com(0x80+9); }if(pp==0xa0){ee--;pp=0;if(ee==0){ee=31;}nyr_date1(9,ee);write_com(0x80+9); } }if(bb==6){if(pp==0xb0){ff++;pp=0;if(ff==13){ff=1;}nyr_date1(6,ff);write_com(0x80+6); }if(pp==0xa0){ff--;pp=0;if(ff==0){ff=12;}nyr_date1(6,ff);write_com(0x80+6); } }if(bb==7){if(pp==0xb0){gg++;pp=0;if(gg==41){gg=11;}nyr_date1(3,gg);write_com(0x80+3); }if(pp==0xa0){gg--;pp=0;if(gg==10){gg=41;}nyr_date1(3,gg);write_com(0x80+3); } }}				   
				
            
                
			
							
上一頁 1 2 下一頁

評論


技術(shù)專區(qū)

關(guān)閉