1. Actual photos
2. Schematic diagram and PCB diagram drawn by Altium Designer are as follows: (Project files can be downloaded in the 51hei attachment)
Components list:
1. AT89C52
2. 40P base
3. 8P base
4. 5MM LED*2 (red, green)
5. 3MM LED (yellow)
6. 12M crystal oscillator
7. 30P ceramic capacitor*2
8. 10uf electrolytic capacitor
9. 10K resistor*2
10. 1K resistor*5
11. 16P LCD base
12. 103 potentiometer*2
13. 9*15 multi-purpose board
14. ADC0832 chip
15. 1602 LCD
16. Button*5
17. Relay
18. Buzzer
19. MQ2
20. MQ2 base
21. DS18B20
22. 3P round hole female socket
23. 8550 transistor
24. 8050 transistor
25. Self-locking switch
26. DC power socket
27. Wire
28. USB power cable
3 whole machine program
#include #include #include #include "DS18B20.h" #define uint unsigned int #define uchar unsigned char //macro definition #define BEEP P3_4 //define buzzer #define hujiao P1_3 sbit BEEP=P3^4; sbit hujiao=P1^3; sbit RS=P2^5; sbit RW=P2^6; sbit EN=P2^7; sbit led_h=P1^4; sbit led_l=P1^5; sbit JDQ=P2^0; sbit ADCS = P3^7; sbit ADCLK = P3^5; sbit ADDI = P3^6; sbit ADDO = P3^6; bit shanshuo_st; // flashing interval flag bit beep_st; //Buzzer interval flag bit flag=0; //Emergency call flag sbit DIAN = P2^5; // Decimal point uint abc; uchar x=4; //Counter signed char m; //temperature value global variable uchar n; //temperature value global variable fly data disdata[5]; flying code LEDData[]={0x28,0xeb,0x32,0xa2,0xe1,0xa4,0x24,0xea,0x20,0xa0}; uchar code table[8]={0x0c,0x12,0x12,0x0c,0x00,0x00,0x00,0x00}; // Celsius temperature symbol /*****Initialize timer 0*****/ void InitTimer(void) { TMOD=0x1; TH0=0x4c; TL0=0x00; //50ms (crystal oscillator 11.0592M) } /*****Timer 0 interrupt service routine*****/ void timer0(void) interrupt 1 { TH0=0x4c; TL0=0x00; x++; } /********Read temperature*****/ void check_wendu(void) { uint a,b,c; c=ReadTemperature()-5; //Get the temperature value and subtract the temperature drift error of DS18B20 a=c/100; //Calculate the ten-digit number b=c/10-a*10; //Calculate the unit digit m=c/10; //Calculate the integer n=ca*100-b*10; //Calculate the decimal places if(m<0){m=0;n=0;} //Set the upper limit of temperature display if(m>99){m=99;n=9;} //Set the upper limit of temperature display } /*****************************lcd1602 program******************************/ void delay1ms(uint ms) //delay 1 millisecond (not precise enough) { uint i,j; for(i=0;i } unsigned char rolmove(unsigned char m) { unsigned char a,b,c,d,e,f,g,h; a=(m&0x01)<<7; b=(m&0x02)<<5; c=(m&0x04)<<3; d=(m&0x08)<<1; e=(m&0x10)>>1; f=(m&0x20)>>3; g=(m&0x40)>>5; h=(m&0x80)>>7; m=a|b|c|d|e|f|g|h; return m; } void wr_com(uchar com)//write instruction// { delay1ms(1); RS=0; RW=0; EN=0; P0=rolmove(com); delay1ms(1); EN=1; delay1ms(1); EN=0; } void wr_dat(uchar dat)//write data// { delay1ms(1);; RS=1; RW=0; EN=0; P0=rolmove(dat); delay1ms(1); EN=1; delay1ms(1); EN=0; } void wr_new() //Write new character { flying i; wr_com(0x40); for(i=0;i<8;i++) { wr_dat(table[i]); } } void lcd_init() //initialization settings // { delay1ms(15); wr_com(0x38);delay1ms(5); wr_com(0x08);delay1ms(5); wr_com(0x01);delay1ms(5); wr_com(0x06);delay1ms(5); wr_com(0x0c);delay1ms(5); wr_new(); wr_com(0x80); wr_dat('S');//A wr_com(0x81); wr_dat('m');//: wr_com(0x82); wr_dat('o'); wr_com(0x83); wr_dat('k'); wr_com(0x84); wr_dat('e'); wr_com(0x85); wr_dat(':'); wr_com(0x87); wr_dat('T'); wr_com(0x88); wr_dat('e'); wr_com(0x89); wr_dat('m'); wr_com(0x8a); wr_dat(':'); wr_com(0x8d); wr_dat('.'); wr_com(0x8f); wr_dat('C'); wr_com(0xc0); wr_dat('A'); wr_com(0xc1); wr_dat('l'); wr_com(0xc2); wr_dat('a'); wr_com(0xc3); wr_dat('r'); wr_com(0xc4); wr_dat('m'); wr_com(0xc5); wr_dat(':'); wr_com(0xcb); wr_dat('-'); wr_com(0xce); wr_dat('C'); } /*****************Display function********************************/ void disp()//temperature value display { disdata[0]=m/10+0x30; //ten digits disdata[1]=m%10+0x30; //single digit disdata[2]=n+0x30; //decimal digits disdata[3]=abc+0x30; //smoke density wr_com(0x8b); wr_dat(disdata[0]);//display tens digit wr_com(0x8c); wr_dat(disdata[1]); //Display the unit digit wr_com(0x8e); wr_dat(disdata[2]); //Display decimal places wr_com(0x86); wr_dat(disdata[3]); } void baojing() { wr_com(0xc9); wr_dat(tab[0]+0x30); wr_com(0xca); wr_dat(tab[1]+0x30); wr_com(0xcc); wr_dat(tab[2]+0x30); wr_com(0xcd); wr_dat(tab[3]+0x30); wr_com(0xc6); wr_dat(tab[4]+0x30); } /*****Alarm subroutine*****/ void Alarm() { if((m>=shangxian&&beep_st==1)||(m else BEEP=0; if(m>=shangxian||m else {led_h=1;led_l=0;JDQ=1;} if(x>=10){beep_st=~beep_st;x=0;} } void Alarm1() { led_h=0; led_l=1; if(x>=10){beep_st=~beep_st;x=0;} if(beep_st==1)BEEP=1; else BEEP=0; led_h=0; led_l=1; JDQ=0; } uchar ADC0832 (bit mode, bit channel) //AD conversion, return result { uchar i,dat,ndat; ADCS = 0; // pull down the CS terminal _nop_(); _nop_(); ADDI = 1; //The first falling edge is high level ADCLK = 1; // pull up the CLK terminal _nop_(); _nop_(); ADCLK = 0; // Pull down the CLK end to form a falling edge 1 _nop_(); _nop_(); ADDI = mode; //Low level is differential mode, high level is single channel mode. ADCLK = 1; // pull up the CLK terminal _nop_(); _nop_(); ADCLK = 0; //Pull down the CLK end to form a falling edge 2 _nop_(); _nop_(); ADDI = channel; //Low level is CH0, high level is CH1 ADCLK = 1; // pull up the CLK terminal _nop_(); _nop_(); ADCLK = 0; // Pull down the CLK end to form a falling edge 3 ADDI = 1; //Control command ends (necessary after testing) that = 0; // Start reading the converted data below and output it in sequence starting from the highest bit (D7~D0) for(i = 0;i < 8;i++) { dat <<= 1; ADCLK=1; //Pull up the clock terminal _nop_(); _nop_(); ADCLK=0; //Pull the clock end low to form a clock pulse _nop_(); _nop_(); gives |= ADD; } ndat = 0; //Record D0 if(ADDO == 1) ndat |= 0x80; // Next, continue reading the reverse data (from D1 to D7) for(i = 0;i < 7;i++) { ndat >>= 1; ADCLK = 1; // pull up the clock terminal _nop_(); _nop_(); ADCLK=0; //Pull the clock end low to form a clock pulse _nop_(); _nop_(); if(ADDO==1) ndat |= 0x80; } ADCS=1; //Pull up the CS terminal to end the conversion ADCLK=0; //Pull down the CLK terminal ADDI=1; //Pull up the data terminal and return to the initial state if(that==ndat) return(that); else return 0; } /*****Main function*****/ void main(void) { InitTimer(); //Initialize the timer EA=1; //Global interrupt switch TR0=1; ET0=1; //Start timer 0 BEEP=0; led_h=1; led_l=1; JDQ=1; check_wendu(); check_wendu(); lcd_init(); //Initialize display delay1ms(100); lcd_init(); //Initialize display delay1ms(100); while(1) { if(hujiao==0) { Delay(2000); do{}while(hujiao==0); flag=~flag; } checkkey(); abc = ADC0832(1,0); //Differential mode, CH0-CH1 abc = abc*19.607843; //Convert to actual voltage for easy display abc=abc/1000%10; check_wendu(); disp(); baojing(); if(flag==1){Alarm1();JDQ=0;} else Alarm(); //Alarm detection if(set_st==0) wr_com(0x0c); if(set_st==1) { wr_com(0xc6); wr_com(0x0d); delay1ms(150); } if(set_st==2) { wr_com(0xca); wr_com(0x0d); delay1ms(150); } if(set_st==3) { wr_com(0xcd); wr_com(0x0d); delay1ms(150); } } }/*****END*****/
Previous article:Design of automatic watering system based on single chip microcomputer
Next article:51 single chip PCF8591 AD DA conversion potentiometer control servo rotation source program
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Infineon MERUS Class D Audio Solution | [Read to win gifts, place an order to get a development board]
- 【AT-START-F403A Review】+ Display driver for color OLED screen
- [DWIN Serial Port Screen] Data Storage of Nucleic Acid Sampling and Registration System
- Which software does STM8 use to compile C?
- Regarding the problem that CCS3.3 cannot generate .out, please answer
- This article on Huawei's internal forum has become popular: The real reason for social involution:
- What are the advantages and disadvantages of charging batteries in pulse form?
- MicroPython Hands-on (22) - Wireless Broadcasting of Control Board
- [NXP Rapid IoT Review] + Learning and thinking about hardware schematics
- CircuitPython starts supporting Open Book