当前位置:网站首页>Intelligent temperature control system
Intelligent temperature control system
2022-07-29 08:11:00 【Half life fireworks I blurred】
Single chip microcomputer reading DS18B20 The temperature is displayed on the LCD1602 On , When the temperature is higher than 30℃ Less than 35℃ The buzzer makes a sound , When the temperature is higher than 35℃ When the motor rotates
DS18b20 Single bus digital thermometer , Buzzer module low level active , For motor (L298N) drive , If you don't understand, you can read the motor drive I wrote before (L298) Their usage is the same
The main function
#include <REGX52.H>
#include "LCD1602.h"
#include "DS18B20.h"
#include "MOTOR.h"
#include "Delay.h"
sbit BEEP=P1^5;
int i=0;
float T;
void main()
{
DS18B20_ConvertT();
Delay(1000);
LCD_Init();
LCD_ShowString(1,1,"Temperature:");
while(1)
{
DS18B20_ConvertT();
T=DS18B20_ReadT();
if(T<0)
{
LCD_ShowChar(2,1,'-');
T=-T;
}
else
{
LCD_ShowChar(2,1,'+');
}
LCD_ShowNum(2,2,T,3);
LCD_ShowChar(2,5,'.');
LCD_ShowNum(2,6,(unsigned long)(T*10000)%10000,4);
if(T<30)
{
i=0;
}
while(T>30&&T<35)
{
BEEP=i;
i=1;
Delay(1000);
BEEP=1;
break;
}
while(T>35)
{
BEEP=0;
MOTOR();
break;
}
if(T<35)
{
MOTOR_step();
}
}
}
Single bus transceiver data function ( By a station up The main reference can be written together with temperature conversion )
#include <REGX52.H>
// Pin definition
sbit OneWire_DQ=P3^7;
// Single bus initialization
unsigned char OneWire_Init(void)
{
unsigned char i;
unsigned char AckBit;
OneWire_DQ=1;
OneWire_DQ=0;
i = 247;while (--i); //Delay 500us
OneWire_DQ=1;
i = 32;while (--i); //Delay 70us
AckBit=OneWire_DQ;
i = 247;while (--i); //Delay 500us
return AckBit;
}
// Single bus sends one bit
void OneWire_SendBit(unsigned char Bit)
{
unsigned char i;
OneWire_DQ=0;
i = 4;while (--i); //Delay 10us
OneWire_DQ=Bit;
i = 24;while (--i); //Delay 50us
OneWire_DQ=1;
}
// Single bus receives one bit
unsigned char OneWire_ReceiveBit(void)
{
unsigned char i;
unsigned char Bit;
OneWire_DQ=0;
i = 2;while (--i); //Delay 5us
OneWire_DQ=1;
i = 2;while (--i); //Delay 5us
Bit=OneWire_DQ;
i = 24;while (--i); //Delay 50us
return Bit;
}
// Single bus sends a byte
void OneWire_SendByte(unsigned char Byte)
{
unsigned char i;
for(i=0;i<8;i++)
{
OneWire_SendBit(Byte&(0x01<<i));
}
}
// One byte received
unsigned char OneWire_ReceiveByte(void)
{
unsigned char i;
unsigned char Byte=0x00;
for(i=0;i<8;i++)
{
if(OneWire_ReceiveBit()){Byte|=(0x01<<i);}
}
return Byte;
}
DS18b20 Temperature conversion
#include <REGX52.H>
#include "OneWire.h"
#define DS18B20_SKIP_ROM 0xCC
#define DS18B20_CONVERT_T 0x44
#define DS18B20_READ_SCRATCHPAD 0xBE
// Temperature conversion
void DS18B20_ConvertT(void)
{
OneWire_Init();
OneWire_SendByte(DS18B20_SKIP_ROM);
OneWire_SendByte(DS18B20_CONVERT_T);
}
// Extraction temperature
float DS18B20_ReadT(void)
{
unsigned char TLSB,TMSB;
int Temp;
float T;
OneWire_Init();
OneWire_SendByte(DS18B20_SKIP_ROM);
OneWire_SendByte(DS18B20_READ_SCRATCHPAD);
TLSB=OneWire_ReceiveByte();
TMSB=OneWire_ReceiveByte();
Temp=(TMSB<<8)|TLSB;
T=Temp/16.0;// Equivalent to temperature *0.0625
return T;
}
LCD Display driver function
#include <REGX52.H>
// Pin configuration :
sbit LCD_RS=P3^5;
sbit LCD_RW=P3^4;
sbit LCD_EN=P3^6;
#define LCD_DataPort P2
// Function definition :
/**
* @brief LCD1602 The time delay function ,12MHz Call can be delayed 1ms
* @param nothing
* @retval nothing
*/
void LCD_Delay()
{
unsigned char i, j;
i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}
/**
* @brief LCD1602 Write orders
* @param Command Command to write
* @retval nothing
*/
void LCD_WriteCommand(unsigned char Command)
{
LCD_RS=0;
LCD_RW=0;
LCD_DataPort=Command;
LCD_EN=1;
LCD_Delay();
LCD_EN=0;
LCD_Delay();
}
/**
* @brief LCD1602 Writing data
* @param Data The data to be written
* @retval nothing
*/
void LCD_WriteData(unsigned char Data)
{
LCD_RS=1;
LCD_RW=0;
LCD_DataPort=Data;
LCD_EN=1;
LCD_Delay();
LCD_EN=0;
LCD_Delay();
}
/**
* @brief LCD1602 Set cursor position
* @param Line Row position , Range :1~2
* @param Column Column position , Range :1~16
* @retval nothing
*/
void LCD_SetCursor(unsigned char Line,unsigned char Column)
{
if(Line==1)
{
LCD_WriteCommand(0x80|(Column-1));
}
else if(Line==2)
{
LCD_WriteCommand(0x80|(Column-1+0x40));
}
}
/**
* @brief LCD1602 Initialization function
* @param nothing
* @retval nothing
*/
void LCD_Init()
{
LCD_WriteCommand(0x38);// Eight bit data interface , Two lines show ,5*7 Lattice
LCD_WriteCommand(0x0c);// Show on , The cursor is off , Flashing off
LCD_WriteCommand(0x06);// After data reading and writing , The cursor automatically adds one , The picture doesn't move
LCD_WriteCommand(0x01);// Cursor reset , Clear the screen
}
/**
* @brief stay LCD1602 Display a character at the specified position
* @param Line Row position , Range :1~2
* @param Column Column position , Range :1~16
* @param Char Characters to display
* @retval nothing
*/
void LCD_ShowChar(unsigned char Line,unsigned char Column,char Char)
{
LCD_SetCursor(Line,Column);
LCD_WriteData(Char);
}
/**
* @brief stay LCD1602 Start displaying the given string at the specified position
* @param Line Start line position , Range :1~2
* @param Column Start column position , Range :1~16
* @param String String to display
* @retval nothing
*/
void LCD_ShowString(unsigned char Line,unsigned char Column,char *String)
{
unsigned char i;
LCD_SetCursor(Line,Column);
for(i=0;String[i]!='\0';i++)
{
LCD_WriteData(String[i]);
}
}
/**
* @brief Return value =X Of Y Power
*/
int LCD_Pow(int X,int Y)
{
unsigned char i;
int Result=1;
for(i=0;i<Y;i++)
{
Result*=X;
}
return Result;
}
/**
* @brief stay LCD1602 Start displaying the given number at the specified position
* @param Line Start line position , Range :1~2
* @param Column Start column position , Range :1~16
* @param Number Number to display , Range :0~65535
* @param Length The length of the number to display , Range :1~5
* @retval nothing
*/
void LCD_ShowNum(unsigned char Line,unsigned char Column,unsigned int Number,unsigned char Length)
{
unsigned char i;
LCD_SetCursor(Line,Column);
for(i=Length;i>0;i--)
{
LCD_WriteData(Number/LCD_Pow(10,i-1)%10+'0');
}
}
/**
* @brief stay LCD1602 Displays the given number in signed decimal starting at the specified position
* @param Line Start line position , Range :1~2
* @param Column Start column position , Range :1~16
* @param Number Number to display , Range :-32768~32767
* @param Length The length of the number to display , Range :1~5
* @retval nothing
*/
void LCD_ShowSignedNum(unsigned char Line,unsigned char Column,int Number,unsigned char Length)
{
unsigned char i;
unsigned int Number1;
LCD_SetCursor(Line,Column);
if(Number>=0)
{
LCD_WriteData('+');
Number1=Number;
}
else
{
LCD_WriteData('-');
Number1=-Number;
}
for(i=Length;i>0;i--)
{
LCD_WriteData(Number1/LCD_Pow(10,i-1)%10+'0');
}
}
/**
* @brief stay LCD1602 The given number is displayed in hexadecimal from the specified position
* @param Line Start line position , Range :1~2
* @param Column Start column position , Range :1~16
* @param Number Number to display , Range :0~0xFFFF
* @param Length The length of the number to display , Range :1~4
* @retval nothing
*/
void LCD_ShowHexNum(unsigned char Line,unsigned char Column,unsigned int Number,unsigned char Length)
{
unsigned char i,SingleNumber;
LCD_SetCursor(Line,Column);
for(i=Length;i>0;i--)
{
SingleNumber=Number/LCD_Pow(16,i-1)%16;
if(SingleNumber<10)
{
LCD_WriteData(SingleNumber+'0');
}
else
{
LCD_WriteData(SingleNumber-10+'A');
}
}
}
/**
* @brief stay LCD1602 The given number is displayed in binary from the specified position
* @param Line Start line position , Range :1~2
* @param Column Start column position , Range :1~16
* @param Number Number to display , Range :0~1111 1111 1111 1111
* @param Length The length of the number to display , Range :1~16
* @retval nothing
*/
void LCD_ShowBinNum(unsigned char Line,unsigned char Column,unsigned int Number,unsigned char Length)
{
unsigned char i;
LCD_SetCursor(Line,Column);
for(i=Length;i>0;i--)
{
LCD_WriteData(Number/LCD_Pow(2,i-1)%2+'0');
}
}
Motor drive function ( A simpler way to use ) You can add a timer by yourself pwm Number adjustment function
#include <REGX52.H>
sbit EB=P1^0;
sbit L1=P1^1;
sbit L2=P1^2;
void MOTOR_step()
{
EB=0;
}
void MOTOR()
{
EB=1;
L1=1;
L2=0;
}
I have to say this up The Lord is really powerful , The object made before was later dismantled , There are no pictures now
边栏推荐
- Inclination monitoring solution of Internet of things
- Chapter contents of the romance of the Three Kingdoms
- Very practical shell and shellcheck
- STM32 detection signal frequency
- Low cost 2.4GHz wireless transceiver chip -- ci24r1
- Use the cloud code to crack the problem of authentication code encountered during login
- Data unit: bit, byte, word, word length
- Operator overloading
- Unicode私人使用区域(Private Use Areas)
- [lecture notes] how to do in-depth learning in poor data?
猜你喜欢

Useful websites

Unity多人联机框架Mirro学习记录(一)

(Video + graphic) machine learning introduction series - Chapter 5 machine learning practice
![[cryoelectron microscope | paper reading] a feature guided, focused 3D signal permutation method for subtogram averaging](/img/50/594dfc9affbcca97166d475fe09ad3.png)
[cryoelectron microscope | paper reading] a feature guided, focused 3D signal permutation method for subtogram averaging

Cs5340 domestic alternative dp5340 multi bit audio a/d converter

Redshift 2.6.41 for maya2018 watermark removal

Compare three clock circuit schemes of single chip microcomputer

Simplefoc parameter adjustment 1-torque control

Implementation of simple cubecap+fresnel shader in unity

TCP——滑动窗口
随机推荐
Mysql rownum 实现
Unity beginner 2 - tile making and world interaction (2D)
Privacy is more secure in the era of digital RMB
Processes and threads
Chapter contents of the romance of the Three Kingdoms
TCP - sliding window
Arduino uno error analysis avrdude: stk500_ recv(): programmer is not responding
Limitations of push down analysis
Data unit: bit, byte, word, word length
Unity beginner 1 - character movement control (2D)
C language data type
The difference between torch.tensor and torch.tensor
Alibaba political commissar system - Chapter III, Alibaba political commissar and cultural docking
Dynamic Thresholds Buffer Management in a Shared Buffer Packet Switch论文总结
Some simple uses of crawler requests Library
Security baseline of network security
[密码学实验] 0x00 安装NTL库
阿里巴巴政委体系-第一章、政委建在连队上
Dp4301-sub-1g highly integrated wireless transceiver chip
Cs5340 domestic alternative dp5340 multi bit audio a/d converter