Single chip intelligent lighting system program

Publisher:czc天天Latest update time:2020-11-10 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Main functions of intelligent aisle lighting system

⑴The system is equipped with 2 key function keys (mode switch key and power key), and a microcontroller reset key;

(2) The system is equipped with 1 power indicator light and 5 status indicator lights, namely: light detection signal indicator light (the indicator light is on when the light is dark), infrared pyroelectric sensor signal indicator light (the indicator light is on when the human body signal is detected), automatic mode relay working status indicator light (in automatic mode, the relay is connected and the indicator light is on), mode indicator light (in manual mode, the indicator light is on), manual mode relay working status indicator light (in manual mode, the relay is connected and the indicator light is on);

⑶ The system has two working modes: automatic working mode and manual working mode. The default mode is automatic mode when it is turned on, and the mode can be switched through the "mode switch key";

⑷ In automatic mode, the relay on time is controlled by the delay variable. When the delay variable is > 0, the relay is on, and when the delay variable is = 0, the relay is off. The delay variable is controlled by the detected signal. When the light is dark and someone is detected, the delay variable is equal to the set delay time, so that the light bulb automatically turns off after a period of time after the person leaves, which saves energy.

⑸The set delay time can be modified. In automatic mode, long press the "power key". Every 5 seconds, the delay time will increase by 10 seconds, and 5 status indicators will be displayed, one indicator light from left to right every 5 seconds. The maximum delay time is 50 seconds.

⑹ In manual mode, the relay switch can be controlled by the "on/off key";


The microcontroller source program is as follows:

#include

#include

#define uchar unsigned char

#define uint unsigned int

sbit renti=P2^1; //Define human feeling

sbit guangming=P2^0; //define the light detection pin

sbit jdq=P2^7; //relay

sbit L1=P2^6; //define indicator light

sbit L2=P2^5;

sbit L3=P2^4;

sbit L4=P2^3;

sbit L5=P2^2;

sbit K1=P1^0; //define switch

sbit K2=P1^1;                          

int count;rt,gm,qd,shijian,sj=10,moshi=1,shijian1,count1,shezhi=0; //variables

void qudou(void) //debounce delay                                                                                  

{ int i;

   for(i=0;i<2400;i++);

}

void key() //Key scan

{if(K1==0) //debounce   

   { qudou();

     if(K1==0) //Mode button is pressed

    {moshi++; //moshi=1 is automatic, =0 is manual

         if(moshi>=2) moshi=0;

         jdq=1;

    }while(K1==0);

        }

if(moshi==1) //in automatic mode

{if(K2==0) //Switch button pressed   

   { qudou();

     if(K2==0)

    {shezhi=1; //Long press the switch button to set the delay time, see the interrupt

         shijian1=0;

    }while(K2==0);

        }

        else shezhi=0; //Exit the setting without pressing the switch button

  }

}

void rentijiance() //Infrared human body detection subroutine

{ if(renti==0) rt=1; //When no human body is detected, the sensor sends a low level to the microcontroller, and rt is 1 rt=0 (someone), rt=1 (no one)

   else rt=0;

}

void guangzhaoqiangdu() //Light intensity subroutine

{ if(guangming==0) gm=1; //When the light is bright, the sensor sends a low level to the microcontroller, and gm is 1 gm=0 (dark light), gm=1 (bright light)

   else gm=0;

}               

void panduan() //judgment

{if(moshi==1)

{if(gm==0)

  {if(rt==0)

   shijian=sj;

   else

   shijian=shijian;}

  else

  shijian=shijian;

}

else

shijian=0;

}

void zhishideng() //Indicator light function

{L5=gm;

L4=rt;

if(moshi==1)

L3=jdq;

else

L3=1;

L2=moshi;

if(moshi==0)

L1=jdq;

else

L1=1;

}

void qudong() //Relay drive

{if(moshi==1) //In automatic mode

{if(shijian>0) jdq=0; //Control the relay according to the delay time

  else jdq=1;

}

else //In manual mode

{if(K2==0)                   

   { qudou();

     if(K2==0) //Turn on the switch to control the relay

    {jdq=!jdq;

    }while(K2==0);

        }

}

}

void main() //Main program

{ TMOD=0x1; //Interrupt enabled

       TH0=0xb1;

       TL0=0xe0;

       TR0=1;      

       ET0=1;                                                        

       EA=1;                     

       while(1) // infinite loop

       {key(); //Key scan

            rentijiance(); //Human body

            guangzhaoqiangdu(); //lighting

                panduan(); //judgment

                zhishideng(); //Indicator light

                qudong(); //Driver

           }

}

void time0(void) interrupt 1 //interrupt

{ TH0=0xb1;                                                  

      TL0=0xe0;

     if(shijian>0) // used to time delay

         { count++;

      if(count==50)  

        { count=0;

              shijian--;

        }

         }


          if(shezhi==1) //Used to set the delay time in automatic mode

          {count1++;

      if(count1==50)  

        { count1=0;

              shijian1++;

                  if(shijian1<=5) //Press and hold for 5 seconds, the delay time is 10s, and there is 1 indicator light

                  {sj=10; L5=0;L4=1;L3=1;L2=1;L1=1;}

                  else if(shijian1<=10) //Press and hold for 10 seconds, the delay time is 20s, and there are 2 indicator lights

                  {sj=20; L5=0;L4=0;L3=1;L2=1;L1=1;}

                  else if(shijian1<=15) //Press and hold for 15 seconds, the delay time is 30 seconds, and there are 3 indicator lights

                  {sj=30; L5=0;L4=0;L3=0;L2=1;L1=1;}

                  else if(shijian1<=20) //Press and hold for 20 seconds, the delay time is 40s, and there are 4 indicator lights

                  {sj=40; L5=0;L4=0;L3=0;L2=0;L1=1;}

                  else if(shijian1>25) //Press and hold for 25 seconds, the delay time is 50s, and 5 indicator lights are displayed

                  {sj=50; L5=0;L4=0;L3=0;L2=0;L1=0;}


        }

           }

         

}


Reference address:Single chip intelligent lighting system program

Previous article:LCD12864 key menu setting with Chinese character library, single chip microcomputer experimental program
Next article:51 single chip microcomputer controls stepper motor and DC reduction motor

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号