⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dzz_thesamea.lst

📁 基于单片机的数字时钟
💻 LST
📖 第 1 页 / 共 2 页
字号:
 361   4      				num_hours++;
 362   4      				if(num_hours==3)
 363   4      					num_hours=0;
 364   4      			}
 365   3      			while(!s3);
C51 COMPILER V6.12  DZZ_THESAMEA                                                           05/06/2008 17:16:29 PAGE 7   

 366   3      			umost=16;
 367   3      		}	
 368   2      		if(s2==0)
 369   2      		{
 370   3      			delay(10);
 371   3      			if(s2==0)
 372   3      				yes=1;	
 373   3      		}	
 374   2      		while(!s2);
 375   2      		if((umost==0)|yes)
 376   2      		{
 377   3      			yes=0;
 378   3      			flag=1;
 379   3      			temp=1;
 380   3      			break;
 381   3      		}			
 382   2      	}
 383   1      }
 384          
 385          void settime()		//时间设置子函数 
 386          {
 387   1      	if(s2==0)
 388   1      	{	
 389   2      		delay(10);
 390   2      		if(s2==0)
 391   2      		num_key=1;
 392   2      		key_flag=1;
 393   2      		//while(!s2);	//waiting for relase
 394   2      	}					//工程应用中这种等待的方式一般是不允许的  
 395   1      	if(key_flag==1)		//如果有声音的话,因为,执行while(!s2)语音因为CPUb不能执行而中断了   
 396   1      	{					//本程序中所有的whlie(!s2)或while(!s3)都必须改正  
 397   2      		if(s2==1)
 398   2      		{
 399   3      			delay(10);
 400   3      			if(s2==1)	
 401   3      			{	
 402   4      				key_flag=0;
 403   4      				switch(num_key)
 404   4      				{
 405   5      					case 1:	settime_minig();
 406   5      					case 2: settime_minis();
 407   5      					case 3:	settime_hourg();
 408   5      					case 4: settime_hours();
 409   5      				}
 410   4      			}
 411   3      		}
 412   2      	}
 413   1      }
 414          
 415          void setclock()	//闹钟的设定 ,连击键的问题如何使用?  
 416          {
 417   1      	if(s3==0)
 418   1      	{
 419   2      		delay(10);
 420   2      		if(s3==0)
 421   2      		pres=1;
 422   2      		while(!s3);
 423   2      		
 424   2      		while(1)
 425   2      		{	
 426   3      			upmost1--;
 427   3      			displayclock(num_hoursclock,num_hourgclock,num_minisclock,num_minigclock);
C51 COMPILER V6.12  DZZ_THESAMEA                                                           05/06/2008 17:16:29 PAGE 8   

 428   3      			if(s3==0)
 429   3      			{
 430   4      				delay(10);
 431   4      				if(s3==0)
 432   4      				yes=1;	
 433   4      			}	
 434   3      			while(!s3);
 435   3      			if(upmost1==0|yes==1)
 436   3      			{
 437   4      				upmost1=500;
 438   4      				yes=0;
 439   4      				break;
 440   4      			}
 441   3      		}
 442   2      
 443   2      		switch(pres)
 444   2      		{
 445   3      			case 1:	while(1)
 446   3      					{
 447   4      						upmost2--;
 448   4      						//statedisplay(num_minigclock,0xef);
 449   4      						statedisplay(num_minigclock,0x10);
 450   4      						if(s2==0)
 451   4      						{
 452   5      							delay(10);
 453   5      							if(s2==0)
 454   5      							{
 455   6      								num_minigclock++;
 456   6      								if(num_minigclock==10)
 457   6      									num_minigclock=0;
 458   6      							}
 459   5      							while(!s2);
 460   5      							upmost2=50000;
 461   5      						}
 462   4      						if(s3==0)
 463   4      						{
 464   5      							delay(10);
 465   5      							if(s3==0)
 466   5      							yes=1;	
 467   5      						}	
 468   4      						while(!s3);
 469   4      						if(upmost2==0|yes==1)
 470   4      						{
 471   5      							upmost2=50000;
 472   5      							yes=0;
 473   5      							break;
 474   5      						}
 475   4      					}
 476   3      			case 2:	 while(1)
 477   3      					{
 478   4      						upmost2--;
 479   4      						//statedisplay(num_minisclock,0xf7);
 480   4      						statedisplay(num_minisclock,0x08);
 481   4      						if(s2==0)
 482   4      						{
 483   5      							delay(10);
 484   5      							if(s2==0)
 485   5      							{
 486   6      								num_minisclock++;
 487   6      								if(num_minisclock==6)
 488   6      									num_minisclock=0;
 489   6      							}
C51 COMPILER V6.12  DZZ_THESAMEA                                                           05/06/2008 17:16:29 PAGE 9   

 490   5      							while(!s2);
 491   5      							upmost2=50000;
 492   5      						}
 493   4      						if(s3==0)
 494   4      						{
 495   5      							delay(10);
 496   5      							if(s3==0)
 497   5      							yes=1;	
 498   5      						}	
 499   4      						while(!s3);
 500   4      						if(upmost2==0|yes==1)
 501   4      						{
 502   5      							upmost2=50000;
 503   5      							yes=0;
 504   5      							break;
 505   5      						}
 506   4      					}
 507   3      			case 3: while(1)
 508   3      					{
 509   4      						upmost2--;
 510   4      						//statedisplay(num_hourgclock,0xfd);
 511   4      						statedisplay(num_hourgclock,0x04);
 512   4      						if(s2==0)
 513   4      						{
 514   5      							delay(10);
 515   5      							if(s2==0)
 516   5      							{
 517   6      								num_hourgclock++;
 518   6      								if((num_hourgclock==10)&&(num_hoursclock<2))
 519   6      									num_hourgclock=0;
 520   6      								else if((num_hoursclock==2)&&(num_hourgclock==4))
 521   6      									num_hourgclock=0;
 522   6      							}
 523   5      							while(!s2);
 524   5      							upmost2=50000;
 525   5      						}
 526   4      						if(s3==0)
 527   4      						{
 528   5      							delay(10);
 529   5      							if(s3==0)
 530   5      							yes=1;	
 531   5      						}	
 532   4      						while(!s3);
 533   4      						if(upmost2==0|yes==1)
 534   4      						{
 535   5      							upmost2=50000;
 536   5      							yes=0;
 537   5      							break;
 538   5      						}
 539   4      					}
 540   3      			case 4:	while(1)
 541   3      					{
 542   4      						upmost2--;
 543   4      						//statedisplay(num_hoursclock,0xfe);
 544   4      						statedisplay(num_hoursclock,0x01);
 545   4      						if(s2==0)
 546   4      						{
 547   5      							delay(10);
 548   5      							if(s2==0)
 549   5      							{
 550   6      								num_hoursclock++;
 551   6      								if(num_hoursclock==3)
C51 COMPILER V6.12  DZZ_THESAMEA                                                           05/06/2008 17:16:29 PAGE 10  

 552   6      									num_hoursclock=0;
 553   6      							}
 554   5      							while(!s2);
 555   5      							upmost2=50000;
 556   5      
 557   5      						}
 558   4      						if(s3==0)
 559   4      						{
 560   5      							delay(10);
 561   5      							if(s3==0)
 562   5      							yes=1;	
 563   5      						}	
 564   4      						while(!s3);
 565   4      						if(upmost2==0|yes==1)
 566   4      						{
 567   5      							upmost2=50000;
 568   5      							yes=0;
 569   5      							break;
 570   5      						}
 571   4      					}
 572   3      		}
 573   2      	}	
 574   1      }
 575          
 576          void voice()//整点报时子函数  
 577          {
 578   1      	if((num_minis*10+num_minig==3)&&(!allow))
 579   1      	{
 580   2      		flag_voice=1;
 581   2      		if((num_hours*10+num_hourg)>=13)
 582   2      		num_hourf=num_hours*10+num_hourg-12;
 583   2      		else
 584   2      		num_hourf=num_hours*10+num_hourg;
 585   2      		if(num_voice==20)
 586   2      		{
 587   3      			num_voice=0;
 588   3      			beep_f=~beep_f;
 589   3      			if(beep_f==1)
 590   3      			{
 591   4      				beep=0;
 592   4      				times++;
 593   4      			}
 594   3      			else
 595   3      				beep=1;
 596   3      			if(times-1==num_hourf)//报时次数 
 597   3      			{
 598   4      				times=0;
 599   4      				allow=1;
 600   4      				beep=1;
 601   4      				flag_voice=0;
 602   4      			}
 603   3      		}			
 604   2      	}
 605   1      	if(num_minis*10+num_minig!=3)	
 606   1      		{allow=0;}
 607   1      }
 608          
 609          void voice_clock()//闹钟报时子程序  
 610          {
 611   1      	if((num_hours==num_hoursclock)&&(num_hourg==num_hourgclock)&&(num_minis==num_minisclock)&&(num_minig==num
             -_minigclock))
 612   1      	{
C51 COMPILER V6.12  DZZ_THESAMEA                                                           05/06/2008 17:16:29 PAGE 11  

 613   2      		if(num_secflag<=5)
 614   2      		beep=0;
 615   2      		else 
 616   2      		{
 617   3      			num_secflag=6;
 618   3      			beep=1;
 619   3      		}
 620   2      	}
 621   1      }
 622          void init_sys()		//系统初始化 
 623          {
 624   1      	num_sec=0;
 625   1      	num_hours=0;
 626   1      	num_hourg=0;
 627   1      	num_minis=0;
 628   1      	num_minig=0;
 629   1      }
 630          
 631          void init_timer2()	//定时器2初始化 
 632          {
 633   1      	RCAP2H=0x4c;
 634   1      	RCAP2L=0x00;
 635   1      	EA=1;
 636   1      	ET2=1;
 637   1      	TR2=1;
 638   1      }
 639          
 640          void timer2() interrupt 5 using 0		//定时器2中断函数 
 641          {	
 642   1      	TF2=0;
 643   1      	num++;
 644   1      	if(flag_voice)
 645   1      	{	
 646   2      		num_voice++;
 647   2      	}	
 648   1      	if(num==20)        
 649   1      	{
 650   2      		num=0;
 651   2      		P1=~P1;
 652   2      		num_sec++;
 653   2      		num_secflag++;
 654   2      		if(num_sec==60)
 655   2      		{
 656   3      			num_sec=0;
 657   3      			num_secflag=0;
 658   3      			num_minig++;
 659   3      			if(num_minig==10)
 660   3      			{
 661   4      				num_minig=0;
 662   4      				num_minis++;
 663   4      				if(num_minis==6)
 664   4      				{
 665   5      					num_minis=0;
 666   5      					num_hourg++;
 667   5      					if((num_hours<2)&&(num_hourg==10))
 668   5      					{
 669   6      						num_hourg=0;
 670   6      						num_hours++;
 671   6      					}
 672   5      					else if((num_hours==2)&&(num_hourg<4))
 673   5      						num_hourg=0;
 674   5      					else if((num_hours==2)&&(num_hourg==4))	
C51 COMPILER V6.12  DZZ_THESAMEA                                                           05/06/2008 17:16:29 PAGE 12  

 675   5      					{
 676   6      						num_hours=0;
 677   6      						num_hourg=0;
 678   6      					}	
 679   5      				}
 680   4      			}	
 681   3      		}
 682   2      	}
 683   1      }
 684          
 685          void main()					//主函数 
 686          {	
 687   1      	init_sys();
 688   1      	//delay(3);//0.0013
 689   1      	//delay(10);
 690   1      	while(1)
 691   1      	{
 692   2      		if(!flag)//待机显示P 并闪烁  
 693   2      		{
 694   3      			for(i=0;i<185;i++)
 695   3      				display_wait1();
 696   3      			for(j=0;j<185;j++)
 697   3      				display_wait2();
 698   3      			settime();//时间设置 
 699   3      			if(temp)
 700   3      				init_timer2();
 701   3      		}
 702   2      		else if(flag)//正常显示时间  
 703   2      		{
 704   3      			display_scan();
 705   3      			settime();//时间调整 
 706   3      			setclock();//设置闹钟 
 707   3      			voice_clock();//闹钟报时  
 708   3      			voice();//整点报时 		
 709   3      		}
 710   2      	}
 711   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1612    ----
   CONSTANT SIZE    =     11    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     32       4
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      7    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -