Intelligent Street Lighting Control System Based on 51 Single Chip Microcomputer

Publisher:SecretWhisperLatest update time:2022-01-27 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

hardware design


Simulation file 1: The function is shown in the
insert image description here
schematic diagram below
insert image description here

Simulation file 2:
insert image description here

insert image description here

programming

   /******Define header file****************/

#include 

#include  

#include"lcd.h"

#include "ds1302.h"

/******Type redefinition*************/

typedef unsigned char uchar;

typedef unsigned int  uint;

/******Pin definition***************/

sbit key_1 = P1^0; //define 4 keys

sbit key_2 = P1^1;

sbit key_3 = P1^2;

sbit key_4 = P1^3;

sbit key_5=P3^0; //Manual/automatic mode switch

sbit key_6=P3^1; //Manual mode street light switch


sbit led_1 = P1^4;

sbit Beep = P2^3; //Define sound and light alarm

sbit AD_clk = P3^4; //define ADC0832

sbit AD_do = P3^5; 

sbit AD_di = P3^5;

sbit AD_cs = P3^6; 

sbit red_sr = P3^7; //Infrared detection


/******Define variables*******************/

char hour,min,sec; //define hour, minute, second variables

char time;

char work_time_Start = 16, work_time_End = 5; //Set the start and end time

bit light_flag; 

uchar light; //define light intensity

uchar light_limit; //define the light threshold

volatile Data;

/******Declare function*******************/

void delayms(unsigned int x); //delay function

void display(); //display

void Read_time();

void set_work_time(); //Set working time

void set_limit_light(); //Set the light threshold

void work(); //Working status

void set_time(); //Set time

void delay10ms(int d);

void InitTimer0(void); //T0 timer initialization procedure

uchar AD(bit Channel); //ADC0832 program


void kongzhi()

{

if(key_6==0)

{

led_1=1;

}

else

{

led_1=0;

}

}


 void qiehaun()

 {

  if(key_5==0)

{

kongzhi();

}

else

{

work();

// if(red_sr==1)

// {

// led_1=1;

// }

// if(red_sr==0)

// {

// led_1=0;

// }

}

}

void main()

{

Beep = led_1 = 0; //Sound and light alarm, LED off

InitTimer0(); //T0 timer initialization program

LcdInit(); //lcd1602 initialization

while(1)

{

Ds1302ReadTime(); //Read time

set_work_time(); //Set working time

set_limit_light(); //Set the light threshold

set_time();

light = AD(0); //Read ADC0832 value

display(); //display

qiehaun();

// work(); //Working status

}

}

void Timer0Interrupt(void) interrupt 1

{

static uchar count;

    TH0 = 0x0D8;

    TL0 = 0x0F0;

count ++;

if(count>=100)

{

time ++;

count = 0;

    }

//add your code here

}

/*******************************************************************************

* Function name: InitTimer0()

* Function: T0 timer initialization procedure

* Input : None

* Output: None

*******************************************************************************/

void InitTimer0(void)

{

    TMOD = 0x01;

    TH0 = 0x0D8;

    TL0 = 0x0F0;

    EA = 0;

    ET0 = 1;

    TR0 = 1;

}

/*******************************************************************************

* Function name: work()

* Function: Working status

* Input : None

* Output: None

*******************************************************************************/

void work()

{

Read_time(); //Convert time

if(work_time_End!=0 && work_time_Start!=0) //Working time has been set

{

if(hour >= work_time_Start) //The current time is greater than the start time. For example, if the start time is 19:00 and the current time is 21:00.

{

Data = AD(1);

led_1 = 1; //Turn on the LED

if(Data < 50) //No LED is detected

Beep = 1; //Sound and light alarm

else //Detect that the LED is lit

Beep = 0; // Stop alarm

}

else if(hour < work_time_End) //The current time is less than the end time, such as the end time is 06:00 and the current time is 04:00.

{

if(red_sr) // detect a person or a car

{

time = 0;

light_flag = 1; //Set the LED flag to 1, start T0 timer timing, light up the LED, after 10s, clear the LED flag and turn off the LED

}

if(light_flag) //LED flag is set to 1, a person or car is detected

{

led_1 = 1; //Turn on the LED

EA = 1; // Enable interrupt

if(time > 10) //10 seconds later

{

light_flag = 0; //LED flag clear

EA = 0; //Disable interrupt

time = 0; // reset the timer

}

Data = AD(1);

if(Data < 50) //No LED is detected

Beep = 1; //Sound and light alarm

else //Detect that the LED is lit

Beep = 0; // Stop alarm

    }

else

led_1 = 0;

}

else

{

if(light < light_limit)

{

led_1 = 1;

Data = AD(1);

if(Data < 50) //No LED is detected

Beep = 1; //Sound and light alarm

else //Detect that the LED is lit

Beep = 0; // Stop alarm

}

else

led_1 = Beep = 0;

}

}

}

/*******************************************************************************

* Function name: set_work_time()

* Function: Set working time

* Input : None

* Output: None

*******************************************************************************/


Documents are for reference only


Link: https://pan.baidu.com/s/1Sl6u_BGjrjMKFC8JS90O-A

Extraction code: 67xo

Reference address:Intelligent Street Lighting Control System Based on 51 Single Chip Microcomputer

Previous article:Intelligent temperature control fan based on 51 single chip microcomputer
Next article:Design of GSM intelligent express cabinet based on 51 single chip microcomputer

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号