Air pump control program based on 51 single chip microcomputer

Publisher:创新思绪Latest update time:2015-07-28 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Use stc89c52 microcontroller to control the air pump, with 2 working modes, the port can be modified by yourself
#include
sbit a=P1^5; // flashing light
sbit b=P1^4; //air pump
sbit c=P3^7; //status indicator light
sbit ss1=P3^2; //One minute working mode
sbit ss4=P3^3; //Four-minute working mode
unsigned int q,w,e,r,y,u,i,n,m,l,h;
csh(); // Initialize subroutine declaration
ys(); //Delay subroutine
ys2(); //Delay subroutine 2 declaration
void main()
{
csh(); //initialization

while(1) //Infinite loop number one
 {
 if(ss1==0){n=1;} //Determine the one-minute working mode and start the second cycle
 if(ss1==1){n=0;b=1;} //Determine if the one-minute working mode is to start the second cycle
 if(ss4==0){m=1;} //Determine the four-minute working mode and start the * cycle
 if(ss4==1){m=0;b=1;} //Determine if the four-minute working mode does not enable the * number cycle

/*...........The following is a one-minute working mode...dividing line......................*/
  while(n) //The second loop works for one minute. n is assigned a value of 1 and enters the loop body.
 {
   if(ss1==0) //Determine whether the one-minute working mode is enabled and execute the statement
   {
    for(l;l>0;l--); //delay judgment
    if(ss4==0){n=0;}//Determine whether the four-minute mode is enabled, disconnect the second loop and exit execution
    for(q;q>0;q--); //Delay determination q
    if(ss4==1) //Determine if the four-minute mode is not enabled and execute downward
     {
     if(q==0) //determine if q is reduced to 0
  {
   b=1; //Disconnect the air pump
   w=1; //Loop body 2 w is 1
   e=1; //Loop body 1 e is assigned to 1
   }
    while(e) //Loop body number 3
   {
   if(P3==0x7b) // Check if the indicator light and one minute start execution
    {
 while(w) //The initial value of w in loop No. 4 is 1
 {
       ys(); // Half-second delay seems not allowed to be changed by yourself
  a=0; //The flashing light turns on
  r++;//Number of seconds plus 1
  if(ss1==1) //Determine when the one-minute working mode is disconnected
  {
        ys2(); //Delay determination
  if(ss1==1) //One minute working mode is indeed disconnected
  {n=0;e=0;w=0;r=0;b=1;}//judgment is established, exit all
  }
    ys(); // Half-second delay seems not allowed to be changed by yourself
  a=1; // Flashing light off
       
 if(r==60) // Wait for the number of seconds to add to 60 before executing
 {  
   w=0; //Disconnect loop body 2
   r=60; //Keep the number of seconds equal to 60
   b=0; //Start the water pump
   h=1; //Loop body No. 5 ()
   while(h) //Loop body No. 5
   if(ss1==1) //Determine that one minute has passed and the execution is down
   { ys2(); //Delay determination
   if(ss1==1) //After a delay, it is determined that the one-minute working mode is disconnected
   {
   b=1; //Disconnect the air pump
      n=0; //Exit loop number 2
   e=0; //Exit loop body No. 4
   r=0; //One minute time reset to zero
   while(1)
   {
   if(m==0);
   {
   h=0;
   break;
   }    
       //Exit the fifth loop itself
   
      }
   }} } } } } }/*Judgment*/ }/*Loop body No. 2*/ }/*Loop body No. 1*/
/*..................The following is a four-minute working mode.......I am the dividing line...........*/
Download address of this program: http://www.51hei.com/ziliao/file/qibang.rar
  while(m) //The second loop works for one minute. n is assigned a value of 1 and enters the loop body.
 {
   if(ss4==0) //Determine whether the four-minute working mode is enabled and execute the statement
   {
    for(l;l>0;l--); //delay judgment
    if(ss1==0){m=0;}//Determine whether the one-minute mode is enabled, disconnect the second loop body and exit execution
    for(q;q>0;q--); //Delay determination q
    if(ss1==1) //Determine if the one-minute mode is not enabled and execute downward
     {
     if(q==0) //determine if q is reduced to 0
  {
   b=1; //Disconnect the air pump
   w=1; //Loop body 2 w is 1
   e=1; //Loop body 1 e is assigned to 1
   }
    while(e) //Loop body number 3
   {
   if(P3==0x77) // Check the indicator light and the four-minute start to execute the following
    {
 while(w) //The initial value of w in loop No. 4 is 1
 {
       ys(); // Half-second delay seems not allowed to be changed by yourself
  a=0; //The flashing light turns on
  r++;//Number of seconds plus 1
  if(ss4==1) //Determine when the four-minute working mode is disconnected
  {
        ys2(); //Delay determination
  if(ss4==1) //The four-minute working mode is indeed disconnected
  {m=0;e=0;w=0;r=0;b=1;}//judgment is established, exit all
  }
     ys(); // Half-second delay seems not allowed to be changed by yourself
  a=1; // Flashing light off
       
 if(r==240) // Wait for the number of seconds to add to 240 before executing
 {  
   w=0; //Disconnect loop body 2
   r=240; //Keep the number of seconds equal to 240
   b=0; //Start the water pump
   h=1; //Loop body No. 5 ()
   while(h) //Loop body No. 5
   if(ss4==1) //Determine that the execution will exit after four minutes
   { ys2(); //Delay determination
   if(ss4==1) //After the delay, it is determined that the four-minute working mode is disconnected
   {
   b=1; //Disconnect the air pump
      n=0; //Exit loop number 2
   e=0; //Exit loop body No. 4
   r=0; //Four minutes time reset to zero
   q=60000;

   
   while(1)
   {
   if(n==0);
   {
   h=0; //Exit loop body No. 5
   break; //Exit the loop
   }    
       
      }
    } } } } }/*Judgement*/ }/*Loop body No. 2*/ }/*Loop body No. 1*/}}}}

/*.......................Initialization subroutine........................................*/
csh() // Initialize subroutine
{
 a=1; //The flashing light does not flash
 b=1; //The air pump is not turned on
 c=0; //status indicator lights up
 ss1=1; //One minute working mode is not started
 ss4=1; //Four-minute working mode is not started
 r=0; //One minute and 60 seconds
 e=0; // loop body e is assigned to 1
 q=60000; //First delay determination q initial value
 l=60000; //delay
 h=0; //Loop body No. 5
}
ys()
{
 for(y=23;y>0;y--)
        for(u=152;u>0;u--)
        for(i=70;i>0;i--); //It seems that you are not allowed to change the half-second delay
}
ys2()
{
 for(y=167;y>0;y--) 
        for(u=171;u>0;u--) 
        for(i=16 ;i>0;i--);
}
 
Reference address:Air pump control program based on 51 single chip microcomputer

Previous article:Super multifunctional electronic clock program
Next article:The microcontroller key is turned on only when the specified time is reached

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号