Schematic diagram of single chip intelligent temperature control fan PCB file and source program

Publisher:RainbowDreamerLatest update time:2020-02-17 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The main chip is 89c51, with motor, temperature sensor, infrared pyroelectric, LCD1602 as peripherals. The main function is to automatically adjust the motor speed according to the room temperature, and recognize the human body, open it when someone is on, and turn off the power when no one is on. The indoor temperature and the upper and lower limits can be adjusted by keystrokes and displayed on the 1602.
The compressed package contains the schematic, PCB board, and library. There are also codes and documents.

The schematic and PCB diagram drawn by Altium Designer are as follows:

The microcontroller source program is as follows:

#include //Call the MCU header file

#define uchar unsigned char //unsigned character macro definition variable range 0~255

#define uint unsigned int //Unsigned integer macro definition variable range 0~65535

#include


sbit dq = P2^4; //18b20 IO port definition

sbit BGVCC = P2^7;

uint temperature ; //

bit flag_200ms;


bit flag_lj_en; //key-on enable

bit flag_lj_3_en; // Press the button three times in a row to enable the added number. 

uchar key_time,key_value; //Used as intermediate variable for continuous addition

bit key_500ms;

sbit hw = P2^5;

uchar miao = 30;

uchar flag_en;

sbit buzz=P1^3;

uchar code table_num[]="0123456789abcdefg";


sbit rs=P1^2; //Register selection signal H: data register L: instruction register

sbit rw=P1^1; //Register selection signal H: data register L: instruction register

sbit e =P1^0; //Chip select signal falling edge trigger


sbit pwm = P2^3;  

uchar f_pwm_l; //


uchar menu_1; //Menu design variables

uint t_high = 300, t_low = 200;



/**************************1ms delay function********************************/

void delay_1ms(uint q)

{

        uint i,j;

        for(i=0;i                for(j=0;j<110;j++);

}


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

* Name: delay_uint()

* Function: small delay.

* Input: None

* Output: None

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

void delay_uint(uint q)

{

        while(q--);

}


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

* Name: write_com(uchar com)

* Function: 1602 command function

* Input: Input command value

* Output: None

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

void write_com(uchar com)

{

        e=0;

        rs=0;

        rw=0;

        P0=com;

        delay_uint(25);

        e=1;

        delay_uint(100);

        e=0;

}


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

* Name: write_data(uchar dat)

* Function: 1602 write data function

* Input: Data to be written to 1602

* Output: None

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

void write_data(uchar dat)

{

        e=0;

        rs=1;

        rw=0;

        P0=dat;

        delay_uint(25);

        e=1;

        delay_uint(100);

        e=0;        

}


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

* Name: write_string(uchar hang,uchar add,uchar *p)

* Function: Change the value of a certain bit in the LCD. If you want the fifth character in the first line to start displaying "ab cd ef", call this function as follows

                  write_string(1,5,"ab cd ef;")

* Input: row, column, need to enter 1602 data

* Output: None

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

void write_string(uchar hang,uchar add,uchar *p)

{

        if(hang==1)   

                write_com(0x80+add);

        else

                write_com(0x80+0x40+add);

        while(1)

        {

                if(*p == '') break;

                write_data(*p);

                p++;

        }        

}


/***********************Display specific characters on lcd1602****************************/

void write_zifu(uchar hang,uchar add,uchar date)

{

        if(hang==1)   

                write_com(0x80+add);

        else

                write_com(0x80+0x40+add);

        write_data(date);        

}


/***********************LCD1602 displays two decimal numbers************************/

void write_sfm3_18B20(uchar hang,uchar add,uint date)

{

        if(hang==1)   

                write_com(0x80+add);

        else

                write_com(0x80+0x40+add);

        write_data(0x30+date/100%10);

         

        write_data(0x30+date/10%10);

          write_data('.');

        write_data(0x30+date%10);        

}


/***********************lcd1602 initialization settings****************************/

void init_1602()

{

        write_com(0x38); //

        write_com(0x0c);

        write_com(0x06);

        delay_uint(1000);

        write_string(1,0,"temp: ");        

        write_string(2,0,"H: L: ");

        write_sfm3_18B20(2,2,t_high);        

        write_sfm3_18B20(2,10,t_low);                                

        write_zifu(1,9,0xdf); //display degree        

}


/***************************18b20 initialization function*********************************/

void init_18b20()

{          

        bit q;

                EA=0;

        dq = 1; //Put the bus high

        delay_uint(1); //15us

        dq = 0; // give reset pulse

        delay_uint(80); //750us

        dq = 1; //Put the bus high and wait

        delay_uint(10); //110us

        q = dq; //Read 18b20 initialization signal

        delay_uint(20); //200us

        dq = 1; //Pull the bus high to release the bus

        EA=1 ;

}


/*************Write the data in 18b20***************/

void write_18b20(uchar dat)

{         

        uchar i;

                 EA=0;

        for(i=0;i<8;i++)

        { //Write data starts from low bit

                dq = 0; // Pull the bus low to start the write time interval 

                dq = dat & 0x01; //Write data to the 18b20 bus

                delay_uint(5); // 60us

                dq = 1; //Release the bus

                dat >>= 1;

        }

        EA=1;        

}


/****************Read the data in 18b20****************/

uchar read_18b20()

{         

        uchar i,value;

                         EA=0 ;

        for(i=0;i<8;i++)

        {

                dq = 0; //Put the bus low to start the read time interval 

                value >>= 1; //Read data starting from low bit

                dq = 1; //Release the bus

                if(dq == 1) //Start reading and writing data 

                        value |= 0x80;

                delay_uint(7); //60us Reading a time gap requires at least 60us

        }

        EA=1 ;

        return value; //Return data

}



/****************The temperature value read is a decimal***************/

uint read_temp()

{          

        uint value;

        uchar low; //If the interrupt is too frequent when reading the temperature, the interrupt should be turned off, otherwise it will affect the timing of 18b20

           EA=0;

        init_18b20(); //Initialize 18b20


        write_18b20(0xcc); //Skip 64-bit ROM

        write_18b20(0x44); //Start a temperature conversion command

         delay_uint(50); //500us


        init_18b20(); //Initialize 18b20


        write_18b20(0xcc); //Skip 64-bit ROM

        write_18b20(0xbe); //Issue a command to read the temporary register


        low = read_18b20(); //Read temperature low byte

        value = read_18b20(); //Read temperature high byte


        value <<= 8; //Shift the high bit of the temperature left by 8 bits

        value |= low; //Put the low bit of the temperature read into the low eight bits of value

        value *=0.625 ; //Convert to decimal temperature value

        EA=1;

        return value; //Return the read temperature with decimals

}


/*************Timer 0 initialization procedure****************/

void time_init()          

{

        EA = 1; // Enable general interrupt

        TMOD = 0X21; //Timer 0, Timer 1 working mode 1

        ET0 = 1; // Enable timer 0 interrupt 

        TR0 = 1; // Allow timer 0 to start timing

        ET1 = 1; // Enable timer 0 interrupt 

        TR1 = 1; // Allow timer 0 to start timing

}


/************************Independent key program*****************/

uchar key_can; //key value


void key() //Independent key program

{          

        static uchar key_new;

         

        key_can = 20; //key value restoration

         P1 |= 0xf0;

        if(key_500ms == 1) //Continuous addition

        {

                key_500ms = 0;

                key_new = 1;

        }

        if((P1 & 0xf0) != 0xf0) //button pressed

        {

                delay_1ms(1); //key debounce

                if(((P1 & 0xf0) != 0xf0) && (key_new == 1))

                { //Confirm that the button was pressed

                        key_new = 0;

                        switch(P1 & 0xf0)

                        {

                                case 0xe0: key_can = 1; break; //Get the k1 key value

                                case 0xd0: key_can = 2; break; //Get the K2 key value

                                case 0xb0: key_can = 3; break; //Get the k3 key value

                        }

                        flag_lj_en = 1; //Continuous addition enable

                }                        

        }

        else 

        {

                        if(key_new == 0)

                {

                        key_new = 1;

                        flag_lj_en = 0; //Disable continuous addition enable

                        flag_lj_3_en = 0; //Enable after 3 seconds of shutdown

                        key_value = 0; // clear

                        key_time = 0;

                        key_500ms = 0;

                }

        }


}



/********************Button display function***************/

void key_with()

{          

        

        if(key_can == 1) //Set key

        {         

                menu_1++;

                if(menu_1 >= 3)

                {

                        menu_1 = 0;

                }

                if(menu_1 == 0)

                {

                        write_com(0x0c); //Close the cursor

                }

        }

        if(menu_1 == 1) //Set high temperature alarm

        {

                if(key_can == 2)

                {

                        if(flag_lj_3_en == 0)

                                t_high ++ ; //The button is pressed but not released, and the value is automatically increased three times        

[1] [2]
Keywords:MCU Reference address:Schematic diagram of single chip intelligent temperature control fan PCB file and source program

Previous article:Simple 8-key electronic keyboard program for single chip microcomputer
Next article:Based on the AD conversion program of STC15w microcontroller series

Recommended ReadingLatest update time:2024-11-25 13:30

How to add PWM/analog channels to a microcontroller
A microcontroller is a single-chip microcomputer that integrates the main parts of a microcomputer on a single chip. Low-cost 8-bit single-chip microcontrollers are very stingy when it comes to on-chip PWM (pulse width modulation) resources. Designers are often forced to sacrifice a capture/compare channel or a ti
[Power Management]
How to add PWM/analog channels to a microcontroller
Application of single chip microcomputer in the brightness adjustment system of full automatic CCFL film viewer
introduction Since the beginning of the 21st century, the world of information has changed rapidly. Maybe a high-tech product will be released today and a better similar product will be released tomorrow. The update cycle of electronic computer science and technology is about 2 to 3 years. With the development
[Microcontroller]
MSP430 microcontroller has built-in watchdog and reset circuit
Some popular single-chip microcomputers on the market are mostly embedded with internal WDT, such as TI's MSP430 series, Philips' P87XXX and P89XXX series, MICroChip's PIC series, Atmel's AT89SXX series and Holtek's Htxxx series. However, these internal watchdogs often have certain errors when working. Some engineers
[Microcontroller]
MSP430 microcontroller has built-in watchdog and reset circuit
Design of temperature acquisition system based on 89C51 and DS18B20
  With the progress and development of the times, single-chip microcomputers have been popularized in all areas of our lives, work, and scientific research, and temperature is one of the main controlled parameters in industrial control, especially in metallurgy, chemical industry, building materials, food, machinery, p
[Microcontroller]
Design of temperature acquisition system based on 89C51 and DS18B20
51 MCU C programming (VIII. DC motor relay control forward and reverse rotation)
Program name: DC motor relay control forward and reverse Programming       : jumpmysoul Program function: Use two buttons to control the forward and reverse rotation of the DC motor #include reg51.h sbit zheng=P1^0;     //Forward button sbit fan=P1^1;       //Reverse button sbit JD=P3^0;       //Relay cont
[Microcontroller]
C51 MCU serial communication RX&TX
Drawing The simplest serial communication code *It is difficult to explain. If you don’t understand how the microcontroller works internally, you may not understand it * #include reg52.h #include stdio.h sbit led=P1^0; void initUart() //The most basic *Serial port communication initialization* must be remembered
[Microcontroller]
C51 MCU serial communication RX&TX
PIC16F877 MCU DS18B20 digital tube thermometer simulation program can display negative temperature
The circuit diagram is as follows: //************************************************************ // Function implemented: Digital tube displays real-time temperature, supports negative temperature // Chip PIC16F877 // XT:4MHZ //************************************************************ #include pic.h //Includes th
[Microcontroller]
PIC16F877 MCU DS18B20 digital tube thermometer simulation program can display negative temperature
Temperature transmitter based on ICL7135 and PIC microcontroller
Intelligent control of A/D conversion data. This article takes the actual engineering application of PIC microcontroller and ICL7135 as an example to introduce the application of an intelligent temperature control instrument in the temperature transmitter . 1 PIC microcontroller
[Microcontroller]
Temperature transmitter based on ICL7135 and PIC microcontroller
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号