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

📄 guhuaji.c

📁 某医用硅胶固化机的程序,用AT89C2051的.
💻 C
字号:
#include <reg51.h>
#include <intrins.h>
#include <absacc.h>
#include <stdio.h>

#define uint unsigned int
#define uchar unsigned char


sbit  P12=P1^2;
sbit  P13=P1^3;
sbit  P14=P1^4;
sbit  P15=P1^5;
sbit  P16=P1^6;
sbit  P17=P1^7;
sbit  P34=P3^4;
sbit  P35=P3^5;


volatile long int counter=0;
volatile uint counter1=0;

volatile uint counter3=0;
volatile uint counter4=0;
volatile int state;
volatile int sleep=0;
volatile int mode=1;
volatile int stop=1;

void delay(void)
{
  uint i;
  for(i=0;i<510;i++);
}

void timeNms (void) interrupt 1 using 1
{
    P13=1;
	TR0=0;

}



void time50ms (void) interrupt 3 using 1
{
    
    TH1=0x9e;			   //重新赋初值
    TL1=0x58;
	counter++;
	
	if(counter==3600)
	   {
	      state=P1;
		  P12=1;P13=1;P15=P16=P17=1;
		  counter=0;
		  counter1=0;
		  counter3=0;
		  counter4=0;
		  sleep=1;
		  TR1=0;
	   }
	if((mode==1)&&(stop==0))
	  {
	    counter1++;
		if((counter1==100)||(counter1==200)||(counter1==300))
		  {
		    P14=0;delay();delay();P14=1;   //蜂鸣器响一下
		  } 
		if(counter1==400)
		   {
		     counter1=0;
		     counter=0; 
			 P13=1;                 //4*5秒后固化灯熄灭
			 stop=1;
		   }
	  }	
	  
	if((mode==2)&&(stop==0))
	  {
	    counter3++;
		
		if((counter3<41)&&(counter3>0))	//前2秒的PWN脉宽为10ms,周期是50ms
		   {
		     P13=0;			   //固化灯亮
		     TH0=0xec;			   //定时器0定时10ms
			 TL0=0x78;
			 TR0=1; 
		   }
		if((counter3<61)&&(counter3>=41))  //第3秒的PWN脉宽为14ms,周期是50ms
		   {
		   	 P13=0;			   //固化灯亮
		     TH0=0xe4;			   //定时器0定时14ms
			 TL0=0xa8;
			 TR0=1; 
		   }
		if((counter3<81)&&(counter3>=61))  //第4秒的PWN脉宽为18ms,周期是50ms
		   {
		   	 P13=0;			   //固化灯亮
		     TH0=0xdc;			   //定时器0定时18ms
			 TL0=0xd8;
			 TR0=1; 
		   }   
		if((counter3<101)&&(counter3>=81))  //第5秒的PWN脉宽为22ms,周期是50ms
		   {
		   	 P13=0;			   //固化灯亮
			 if(counter3==100)
		       {
		         P14=0;delay();delay();P14=1;   //蜂鸣器响一下
		        }
		     TH0=0xd5;			   //定时器0定时22ms
			 TL0=0x08;
			 TR0=1; 
		   }
		if((counter3<121)&&(counter3>=101))  //第6秒的PWN脉宽为26ms,周期是50ms
		   {
		   	 P13=0;			   //固化灯亮
		     TH0=0xcd;			   //定时器0定时26ms
			 TL0=0x38;
			 TR0=1; 
		   } 
		if((counter3<141)&&(counter3>=121))  //第7秒的PWN脉宽为30ms,周期是50ms
		   {
		   	 P13=0;			   //固化灯亮
		     TH0=0xc5;			   //定时器0定时30ms
			 TL0=0x68;
			 TR0=1; 
		   }
		if((counter3<161)&&(counter3>=141))  //第8秒的PWN脉宽为34ms,周期是50ms
		   {
		   	 P13=0;			   //固化灯亮
		     TH0=0xbd;			   //定时器0定时34ms
			 TL0=0x98;
			 TR0=1; 
		   }
		if((counter3<181)&&(counter3>=161))  //第9秒的PWN脉宽为38ms,周期是50ms
		   {
		   	 P13=0;			   //固化灯亮
		     TH0=0xb5;			   //定时器0定时38ms
			 TL0=0xc8;
			 TR0=1; 
		   }
		if((counter3<201)&&(counter3>=181))  //第10秒的PWN脉宽为42ms,周期是50ms
		   {
		   	 P13=0;			   //固化灯亮
			 if(counter3==200)
		       {
		         P14=0;delay();delay();P14=1;   //蜂鸣器响一下
		        }
		     TH0=0xad;			   //定时器0定时42ms
			 TL0=0xf8;
			 TR0=1; 
		   }                 
		if((counter3<221)&&(counter3>=201))  //第11秒的PWN脉宽为46ms,周期是50ms
		   {
		   	 P13=0;			   //固化灯亮
		     TH0=0xa6;			   //定时器0定时46ms
			 TL0=0x28;
			 TR0=1; 
		   }
		if((counter3<241)&&(counter3>=221))
		   {
		     P13=0;			   //固化灯亮
		   }
		if(counter3==300)
		       {
		         P14=0;delay();delay();P14=1;   //蜂鸣器响一下
		        }
		if(counter3==400)
		  {
		     P13=1;			   //固化灯灭
			 counter3=0;
			 counter=0;
			 stop=1;
		  }
	  }

	 if((mode==3)&&(stop==0))
	    {
		    counter4++;
			if(counter4==20)
			   {
			     if(P13==1)P13=0;
				 else P13=1;
				 counter4=0;
			   } 
			if((counter==100)||(counter==200)||(counter==300)) 
			   {
		         P14=0;delay();delay();P14=1;   //蜂鸣器响一下
		       }
			if(counter==400)
			   {
			     P13=1;			   //固化灯灭
			     counter=0;
			     stop=1;
		       }
	    }
			
			     	    	  	           	      	 	 
}			   

main()
{
   int powerkey,modekey;
   P12=0;P13=0;P15=0;     //P1.2为电源指示灯,P1.3为固化灯,P1.4为蜂鸣器开关
   P14=1;delay();delay();
   P13=1;         //P1.5为模式一指示灯,P1.6为模式二指示灯,P1.7为模式三指示灯

   TMOD=0x11;			   //定义T0,T1为定时器
   TH1=0x9e;			   //赋初值,定时50ms,晶振为6M
   TL1=0x58;
   EA=1;				   //开总中断
   ET1=1;				   //允许T1中断   ET0=1;				   //允许T0中断
   mode=1;
   TR1=1;				   //开始T1计时

   while(1)
   {
again:while((P35&P34)==1);
	  powerkey=P35;
   	  modekey=P34;
	  while((P35==0)||(P34==0));
	  
      TR1=0;				   //停止计时
      counter=0;

      if(powerkey==0)			   //电源按钮按下时
        {
		
		stop=0;
		if(sleep==1)
         {
            P1=state&0xe0;
			P14=1;
			sleep=0;
         }
		 switch(mode)
		    {
			   case 1:{	 
		                 P13=0;			   //固化灯亮
		                 TH1=0x9e;			   //赋初值,定时50ms
                         TL1=0x58;
		                 TR1=1;				   //开始T1计时
						 while(stop==0);	   //等待定时20s结束
						 goto again;
					  }
				case 2:{   
						  TH1=0x9e;			   //赋初值,定时50ms
                          TL1=0x58;
						  TH0=0xec;			   //定时器0定时10ms
						  TL0=0x78;
						  P13=0;
						  TR0=1;				   //开始T0计时
						  TR1=1;				   //开始T1计时
						  while(stop==0);		   //等待定时20s结束
						  goto again;
					   }
				case 3:{   
				          TH1=0x9e;			   //赋初值,定时50ms
                          TL1=0x58; 
						  P13=0;
						  TR1=1;				   //开始T1计时
						  while(stop==0);		   //等待定时20s结束
						  goto again;
					   }
				default:break;
			}
	    }

	   if(modekey==0)			  //模式键按下时
	    {
		   if(sleep==0)
		   {
		    mode++;
			if(mode==4)mode=1;
			switch(mode)
		    {
			   case 1:{	 if(sleep==1)
			                  {
                                P1=state&0xe0;
						       	P14=1;
							    sleep=0;
					          }
						 else {
						        P16=1;
						        P17=1;			   
			                    P15=0;			   //亮模式一指示灯
							  }
					   }break;
				case 2:{   if(sleep==1)
			                    {
                                 P1=state&0xe0;
						 	     P14=1;
							     sleep=0;
					            }
						 else {
						        P16=0;
						        P17=1;			   
			                    P15=1;			   
							  }			   //亮模式二指示灯
					   }break;
				 case 3:{   if(sleep==1)
			                    {
                                 P1=state&0xe0;
							     P14=1;
							     sleep=0;
					            }
						   else {
						        P16=1;
						        P17=0;			   
			                    P15=1;			   
							    }			   //亮模式三指示灯
						 }break;
		     }
		  }
			goto again;
		}
     
   	}
}   












⌨️ 快捷键说明

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