hardware design
Simulation file 1: The function is shown in the
schematic diagram below
Simulation file 2:
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
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
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- Breaking through the intelligent competition, Changan Automobile opens the "God's perspective"
- The world's first fully digital chassis, looking forward to the debut of the U7 PHEV and EV versions
- Design of automotive LIN communication simulator based on Renesas MCU
- When will solid-state batteries become popular?
- Adding solid-state batteries, CATL wants to continue to be the "King of Ning"
- The agency predicts that my country's public electric vehicle charging piles will reach 3.6 million this year, accounting for nearly 70% of the world
- U.S. senators urge NHTSA to issue new vehicle safety rules
- Giants step up investment, accelerating the application of solid-state batteries
- Guangzhou Auto Show: End-to-end competition accelerates, autonomous driving fully impacts luxury...
- Lotus launches ultra-900V hybrid technology "Luyao" to accelerate the "Win26" plan
- Discussion: Issues with using isolated power supplies
- Can I get less points for downloading data?
- Event Preheating - Qinheng's new RISC-V architecture 32-bit general-purpose MCU CH32V103 is launched again
- How to reduce the forward transfer coefficient S of MOS tube
- Repost - I have never seen the cross-section of these cable interfaces before
- Help with digital voltmeter design issues
- Double-fed speed regulation
- Kubo MS6908 perfect PIN2PIN replacement MP6908
- Research and FPGA Design of Image Scaling Algorithm
- Decoding Analysis and Simulation of 315Mhz and 433Mhz Wireless Remote Control Signals