当前位置:网站首页>Alcohol detector based on 51 single chip microcomputer

Alcohol detector based on 51 single chip microcomputer

2022-06-12 22:25:00 Kevin's learning station

1、 The main function

If the actual alcohol value is less than the alarm value and under the normal display state : The green light flashes , Turn off the buzzer and relay ; If the actual alcohol value is greater than the alarm value and in the normal display state : Red light flashing , Turn on buzzer and relay .

2、 Simulation diagram

 Insert picture description here

3、 Experimental verification

be based on 51 Single chip alcohol tester

4、 Program source code

 Insert picture description here

/** ************************************* Copyright ****************************** File name: //  Alcohol detection  Author:Kevin Version: //1.0 Description: //  Used to specify the main functions of this program file  Others: //  Description of other contents  Log: //  official account :Kevin Learning station  ****************************************************************************** */

// Program header function 
#include <reg52.h>
// Show function 
#include <display.h>
#include <intrins.h>
#include "eeprom52.h"
#include "temp.h"

// Macro definition 
#define uint unsigned int 
#define uchar unsigned char
#define Data_ADC0809 P1
 
// Pin declaration 
sbit P34=P3^4;// temperature 
sbit LED_R= P2^2; // Red indicator 
sbit LED_G= P2^0; // Green light 
sbit FENG = P2^5; // Buzzer 
//ADC0809
sbit ST=P3^3;
sbit EOC=P3^6;
sbit OE=P3^2;
// Key 
sbit Key1=P2^6;	// Set button 
sbit Key2=P2^7; // Add 
sbit Key3=P3^7;	// reduce 
bit bdata flag;// The indicator light and buzzer flash the alarm flag bit 
uchar set;	  // Set flag bit 


// Function declaration 
extern uchar ADC0809();
extern void Key();

// Alcohol content variable 
unsigned int temp=0;
unsigned int WARNING=25; //  Initial alarm value 
/****************** Save the data to the MCU eeprom in ******************/
void write_eeprom()
{
    
	SectorErase(0x2000);
	byte_write(0x2000, WARNING);
	byte_write(0x2060, a_a);	
}

/****************** Take the data from the MCU eeprom Read it out *****************/
void read_eeprom()
{
    
	WARNING   = byte_read(0x2000);
	a_a      = byte_read(0x2060);
}

/************** Self checking on startup eeprom initialization *****************/
void init_eeprom() 
{
    
	read_eeprom();		// First reading 
	if(a_a != 1)		// New single chip microcomputer initial single chip microcomputer internal question eeprom
	{
    
		WARNING=25;
		a_a = 1;
		write_eeprom();	   // Save the data 
	}	
}
// Initialization function 
void init()	 
{
    
	TMOD=0x01; // Timer 0 The way 1
 	TL0=0xb0;
 	TH0=0x3c;
	TL1=65000/256;
	TH1=65000/256;  // Assign initial value to 
 	EA=1;	// General interruption 
	ET0=1;	// Allow timer 0 interrupt 
 	TR0=1;	// Timer 0 open 
}
 // The main function 
void main()
{
    
	Init1602();	//1602 initialization 
	init_eeprom();  // Start initializing the saved data 
	init();	 // Initialization function 
	while(1)// Main circulation 
	{
    
		if(set==0) // If you do not press set ( Default set yes 0, Is the normal display status )
		{
    
			temp=ADC0809();	// Read alcohol value 
			Display_1602(temp,WARNING,ReadTemperature());	 // Display alcohol value 
		}
		if(temp<WARNING&&set==0)	// If the actual alcohol value is less than the alarm value and under the normal display state 
		{
    
			flag=0;	 // Do the following flag=0 Of ( The main thing is that the green light flashes , Turn off the buzzer and relay )
		}
		else if(temp>WARNING&&set==0)  // If the actual alcohol value is greater than the alarm value and under the normal display state 
		{
    
			flag=1;	// Do the following flag=1 Of ( The main thing is that the red light flashes , Turn on buzzer and relay )
		}
		Key();// Key scan 
	}
}
//ADC0809 Read information 
uchar ADC0809()
{
    
	uchar temp_=0x00;
	// Initialize high impedance too 

	OE=0;
	// Conversion initialization 
	ST=0;
	// Start conversion 
	ST=1;
	ST=0;
	// External interrupt waiting AD End of conversion 
	while(EOC==0)
	// Read converted AD value 
	OE=1;
	temp_=Data_ADC0809;
	OE=0;
	return temp_;
}
// Key function 
void Key()
{
    
	if(Key1==0)	// If the setting key is pressed 
	{
    
		while(Key1==0);// Wait for the key to release 
		FENG=0;	// Buzzer ring 
		set++;	// Set the variable plus 1
		flag=0;	// The green light flashes 
		TR0=0;	// Turn off timer 0
		write_com(0x0f);// Turn on the display   No cursor   The cursor blinks 
		write_com(0x80+15);// Location 
// write_com(0x06);// When reading or writing a character is one digit after the pointer 
		FENG=1;	// The buzzer is off 
	}
	if(set>=2)	// Press settings again 
	{
    
		set=0;	// Normal display status 
// write_com(0x38);// Screen initialization 
		write_com(0x0c);// Turn on the display   No cursor   No cursor flashing 
		FENG=1;	// The buzzer is off 
		flag=1;	// Red light flashing 
		TR0=1;	// Timer 0 open 
	}
	if(Key2==0&&set!=0)	  // Press add... In the setting state 
	{
    
		while(Key2==0);	  // Wait for the key to release 
		FENG=0;		// Buzzer ring 
		WARNING++;	// Alarm value plus 1
		if(WARNING>=255)  // If the alarm value is greater than or equal to 255
		WARNING=0;		 // The alarm value is set to zero 
		write_com(0x80+13);
		write_data('0'+WARNING/100); 
		write_data('0'+WARNING/10%10);
		write_data('0'+WARNING%10);	   // Display the alarm value 
		//write_com(0x80+0x40+13);// Adjusting position 
		FENG=1;	 // The buzzer is off 
		write_eeprom();			   // Save the data 
	}
	if(Key3==0&&set!=0)	 // Press minus... In the set state 
	{
    
		while(Key3==0);	 // Wait for the key to release 
		FENG=0;		 // Buzzer ring 
		WARNING--;	 // The alarm value decreases 1
		if(WARNING<=0)	// If the alarm value is less than or equal to 0
		WARNING=255;	// Then the alarm value is 255
		write_com(0x80+13);
		write_data('0'+WARNING/100);
		write_data('0'+WARNING/10%10);
		write_data('0'+WARNING%10);
		//write_com(0x80+0x40+13);// Adjusting position 
		FENG=1;	 // The buzzer is off 
		write_eeprom();			   // Save the data 
	}
}

void  time1_int(void) interrupt 1 // Timer interrupt 0
{
    
	uchar count;
	TL0=0xb0;
 	TH0=0x3c;  // Reset the initial value 50ms
  	count++;  /// Overflow value plus 1
	if(count==10)  // If it takes half a second 
	{
    
		if(flag==0)	  // If flag by 0
		{
    
			LED_G=0;  // The green light is on 
			LED_R=1;  // The red light goes out 
			FENG=1;	  // The buzzer is off 
		}
		if(flag==1)	   // If flag by 1
		{
    
			LED_G=1;   // Green light off 
			LED_R=0;   // The red light is on 
			FENG=0;	   // The buzzer is on 
		}
	}

   	if(count==20)	  // If it's time 1 second 
   	{
    
		count=0;	  // The overflow value is cleared 
		if(flag==0)	 // If flag by 0
		{
    
			LED_G=1;	// Green light off 
			LED_R=1;	// The red light goes out 
			FENG=1;	   // The buzzer is off 
		}
		if(flag==1)	   // If flag by 1
		{
    
			LED_G=1;   // Green light off 
			LED_R=1;	// The red light goes out 
			FENG=1;	   // The buzzer is off 
		}
	}
}

Other designs / Curriculum resources
be based on 51 Intelligent temperature control fan based on single chip microcomputer
be based on 51 Intelligent water tank control system based on single chip microcomputer
be based on 51 Smart home security system based on MCU
be based on 51 Single chip computer design
An acoustooptic electronic organ based on single chip microcomputer
Design of automatic flower watering system
be based on 51 Design of single chip microcomputer digital voltmeter
be based on 51 Single chip microcomputer CO Concentration alarm design
be based on 51 Design of temperature alarm based on single chip microcomputer
51 Single chip microcomputer +PM2.5+ Temperature and humidity
be based on 51 Intelligent car with single chip microcomputer
be based on 51 Single chip microcomputer + Obstacle avoidance car of ultrasonic module
be based on 51 The design of four channel traffic lights based on single chip microcomputer

The simulation and program engineering of the project have been placed in the following official account , You can pay attention to the official account. :Kevin Learning station , Enter key :“51 Alcohol Tester ”, You can get it ! It's not easy to create , But your likes 、 Focus on 、 Collection is my greatest encouragement !
 Insert picture description here

原网站

版权声明
本文为[Kevin's learning station]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206122220072272.html