hardware design
A. The design is based on 51 single chip microcomputer for smart home control, temperature, light and air monitoring;
B. LCD1602 is used as the display, DS18B20 is used for temperature, photodiode is used for illumination, and it has an audible and visual alarm device. The threshold can be set through three buttons;
The simulation diagram is as follows:
programming:
#include #include "intrins.h" #define u8 unsigned char #define u16 unsigned int #define uchar unsigned char #define uint unsigned int uchar yushe_wendu=50; //temperature preset value uchar yushe_yanwu=100; //Lighting preset value uchar yushe_tianranqi=100; //Natural gas preset value uint wendu; //temperature value global variable uchar yanwu; //Used to read ADC data uchar tianranqi; //Used to read ADC data uint times = 0; //Variable times, count, used for LCD switching display uchar shezhi_flag = 0; //Variable flag, used to switch the display setting of natural gas preset value //Running mode uchar Mode=0; //=1 is to set the temperature threshold =2 is to set the light threshold =0 is the normal monitoring mode uint Buzzer=0; uint count = 0; //Pin declaration sbit Led_Yellow =P2^4; //yellow light sbit speaker =P2^0; //buzzer sbit cg=P2^3; //main switch sbit c1_k=P1^1; //Curtain 1 switch sbit c2_k=P1^4; //Curtain 2 switch /******************************************************************** * Name: delay_1ms() * Function: Delay 1ms function * Input: q * Output: None ***************************************************************************/ void delay_ms(uint q) { uint i,j; for(i=0;i } /*************************************************************************************************************** LCD1602 related functions *******************************************************************************************************************/ //LCD pin declaration (RW pin is directly grounded, because this design only uses LCD write operation, RW pin is always low level) sbit LCDRS = P2^7; sbit LCDEN = P2^6; sbit D0 = P0^0; sbit D1 = P0^1; sbit D2 = P0^2; sbit D3 = P0^3; sbit D4 = P0^4; sbit D5 = P0^5; sbit D6 = P0^6; sbit D7 = P0^7; //LCD delay void LCDdelay(uint z) //The delay is about 100us (not precise, the delay of LCD operation does not require very precise) { uint x,y; for(x=z;x>0;x--) for(y=10;y>0;y--); } void LCD_WriteData(u8 dat) { if(dat&0x01)D0=1;else D0=0; if(dat&0x02)D1=1;else D1=0; if(dat&0x04)D2=1;else D2=0; if(dat&0x08)D3=1;else D3=0; if(dat&0x10)D4=1;else D4=0; if(dat&0x20)D5=1;else D5=0; if(dat&0x40)D6=1;else D6=0; if(dat&0x80)D7=1;else D7=0; } //Write command void write_com(uchar com) { LCDRS=0; LCD_WriteData(com); // DAT=com; LCDdelay(5); LCDEN=1; LCDdelay(5); LCDEN=0; } //Write data void write_data(uchar date) { LCDRS=1; LCD_WriteData(date); // DAT=date; LCDdelay(5); LCDEN=1; LCDdelay(5); LCDEN=0; } /*------------------------------------------------ Select write location ------------------------------------------------*/ void SelectPosition(unsigned char x,unsigned char y) { if (x == 0) { write_com(0x80 + y); // indicates the first line } else { write_com(0xC0 + y); // indicates the second line } } /*------------------------------------------------ Write String Function ------------------------------------------------*/ void LCD_Write_String(unsigned char x,unsigned char y,unsigned char *s) { SelectPosition(x,y) ; while (*s) { write_data( *s); s++; } } Link: https://pan.baidu.com/s/1hfpynLhRsGrz7ThPg0pnIw Withdraw code: 9oo8 for(j=0;j<110;j++);
Previous article:Traffic light control system course design based on 51 single chip microcomputer
Next article:Two-phase stepping motor control system 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?
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Another technical solution for power-type plug-in hybrid: A brief discussion on Volvo T8 plug-in hybrid technology
- Breaking news! The EU will "take action" on Chinese battery technology
- The end-to-end big model swept the Guangzhou Auto Show, a technological leap forward for the intelligent driving industry
- OEM ADAS research: structural adjustment, team integration, D2D, all for leading intelligent driving
- New pattern, new future! 2024 China Automotive Charging and Swapping Ecosystem Conference held in Taiyuan
- Honda solid-state batteries will be used in cars within 5 years: the battery life will be doubled and can travel 1,000 kilometers at a time
- The secret to competing in intelligent driving lies in the latest technology trends
- The first generation of SGT MOSFET series from Qiangmao: innovative trench technology, automotive-grade 60 VN channel, breakthrough in high-efficiency performance of automotive electronics
- USB Type-C® and USB Power Delivery: Designed for extended power range and battery-powered systems
- Simplifying Voltage and Current Measurements in Battery Test Equipment
- Knowledge about op amp and bandwidth
- Application of ProFiBus fieldbus in air conditioning parameter test system
- [MM32 eMiniBoard Review] + SysTick Second Timer
- How to solder resistors on rigid-flex boards
- DSP realizes the source code of the water light style
- Controlling Hardware with Python - Low Voltage Startup and Reliability Testing
- Temperature measurement using thermistor combined with high resolution ∑△AD converter
- HDB3 Codec Design Based on FPGA.pdf
- Data sharing on the transmission power of 2.4G wireless RF chip CC2530