加入星計(jì)劃,您可以享受以下權(quán)益:

  • 創(chuàng)作內(nèi)容快速變現(xiàn)
  • 行業(yè)影響力擴(kuò)散
  • 作品版權(quán)保護(hù)
  • 300W+ 專(zhuān)業(yè)用戶
  • 1.5W+ 優(yōu)質(zhì)創(chuàng)作者
  • 5000+ 長(zhǎng)期合作伙伴
立即加入

基于STM32單片機(jī)DS18B20溫度監(jiān)控報(bào)警proteus仿真設(shè)計(jì)

08/06 09:15
1681
服務(wù)支持:
技術(shù)交流群

完成交易后在“購(gòu)買(mǎi)成功”頁(yè)面掃碼入群,即可與技術(shù)大咖們分享疑惑和經(jīng)驗(yàn)、收獲成長(zhǎng)和認(rèn)同、領(lǐng)取優(yōu)惠和紅包等。

虛擬商品不可退

當(dāng)前內(nèi)容為數(shù)字版權(quán)作品,購(gòu)買(mǎi)后不支持退換且無(wú)法轉(zhuǎn)移使用。

加入交流群
掃碼加入
獲取工程師必備禮包
參與熱點(diǎn)資訊討論
放大
實(shí)物圖
相關(guān)方案
  • 方案介紹
  • 相關(guān)文件
  • 推薦器件
  • 相關(guān)推薦
  • 電子產(chǎn)業(yè)圖譜
申請(qǐng)入駐 產(chǎn)業(yè)圖譜

Proteus仿真版本:proteus 8.9

原理圖Altium Designer

程序編譯器:keil 5

編程語(yǔ)言:C語(yǔ)言

設(shè)計(jì)編號(hào):C0054

功能要求

運(yùn)用所學(xué)知識(shí),完成基于STM32的溫控系統(tǒng)設(shè)計(jì)?;竟δ馨?/p>

  1. LCD1602屏幕顯示當(dāng)前溫度及上限閾值;
  2. 當(dāng)溫度超過(guò)上限值時(shí)LED紅燈亮,蜂鳴器報(bào)警,風(fēng)扇開(kāi)始轉(zhuǎn)動(dòng);
  3. 可通過(guò)按鍵調(diào)節(jié)溫度上限閾值;
  4. 溫度過(guò)高時(shí)啟動(dòng)繼電器控制的風(fēng)扇,實(shí)現(xiàn)自動(dòng)保護(hù)。

注意:

本設(shè)計(jì)是proteus仿真設(shè)計(jì),并未做實(shí)物驗(yàn)證,意味著不確定源程序和原理圖是否能在實(shí)物上正常使用,可能有BUG,故原理圖及PCB僅供參考。

仿真圖

開(kāi)始仿真:LCD屏顯示實(shí)時(shí)溫度和檢測(cè)值,同時(shí)工作指示燈點(diǎn)亮。
在這里插入圖片描述

實(shí)時(shí)溫度大于監(jiān)測(cè)值,馬達(dá)轉(zhuǎn)動(dòng),紅燈亮起,蜂鳴器報(bào)警。
在這里插入圖片描述

原理圖

注意,此原理圖由仿真圖繪制而來(lái),沒(méi)做實(shí)物驗(yàn)證,僅供參考

PCB

注意,此PCB圖由仿真圖繪制而來(lái),沒(méi)做實(shí)物驗(yàn)證,僅供參考

源程序

img

main函數(shù)

int main(void)
{
	short temperature = 0;

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
  /* Configure the system clock */
  SystemClock_Config();
	delay_init(10);               		//初始化定時(shí)器
  TIM3_Init(2400-1, 72-1); // 10ms
	
	Key_Init();
	JDQ_Init();
	LCD_Init();

	LCD_write_string(0, 0, "Temp Value:");
	LCD_write_string(0, 1, "Temp High :");

  while(1)
  {
		do
		{
			DS18B20_Init();
			HAL_Delay(100);		
			temperature = DS18B20_Get_Temp();
			HAL_Delay(200);		
		}
		while(temperature == 0 || temperature > 999 || temperature == 850);
		temp_table[0] = temperature % 1000 / 100 + 0x30;
		temp_table[1] = temperature % 100 / 10 + 0x30;
		temp_table[2] = '.';
		temp_table[3] = temperature % 10 + 0x30;
		
		limt_table[0] = temp_max / 10 + 0x30;
		limt_table[1] = temp_max % 10 + 0x30;

		LCD_write_string(12, 0, (char*)temp_table);
		LCD_write_string(12, 1, (char*)limt_table);

  }
}

DS18B20驅(qū)動(dòng)程序

#include "ds18b20.h"
#include "delay.h"


//復(fù)位DS18B20
void DS18B20_Rst(void)	   
{                 
	DS18B20_IO_OUT();   //設(shè)置為輸出
	DS18B20_DQ_OUT(0);  	//拉低DQ
	delay_us(740);      //拉低750us
	DS18B20_DQ_OUT(1);  	//DQ=1 
	delay_us(15);       //15US
}

//等待DS18B20的回應(yīng)
//返回1:未檢測(cè)到DS18B20的存在
//返回0:存在
uint8_t DS18B20_Check(void) 	   
{   
	uint8_t retry = 0;
	
	DS18B20_IO_IN();    //設(shè)置為輸入 
	
  while (DS18B20_DQ_IN&&retry < 200)
	{
		retry ++;
		delay_us(2);
	};	 
	if(retry >= 200)
		return 1;
	else 
		retry = 0;
	
  while (!DS18B20_DQ_IN&&retry < 240)
	{
		retry++;
		delay_us(2);
	};
	if(retry>=240)
		return 1;	
	
	return 0;
}

//從DS18B20讀取一個(gè)位
//返回值:1/0
uint8_t DS18B20_Read_Bit(void) 
{
	uint8_t data = 0;
	
	DS18B20_IO_OUT();   //設(shè)置為輸出
	DS18B20_DQ_OUT(0); 
	delay_us(2);
	
	DS18B20_DQ_OUT(1); 
	DS18B20_IO_IN();    //設(shè)置為輸入
	delay_us(13);
	
	if(DS18B20_DQ_IN)
		data=1;
	else 
		data=0;
	
	delay_us(50);
	
	return data;
}

//從DS18B20讀取一個(gè)字節(jié)
//返回值:讀到的數(shù)據(jù)
uint8_t DS18B20_Read_Byte(void)   
{        
	uint8_t i, j = 0, dat = 0;
		
	for (i=1;i<=8;i++) 
	{
		j=DS18B20_Read_Bit();
		dat=(j<<7)|(dat>>1);
  }						    
	return dat;
}

//寫(xiě)一個(gè)字節(jié)到DS18B20
//dat:要寫(xiě)入的字節(jié)
void DS18B20_Write_Byte(uint8_t dat)     
{             
	uint8_t j;
	uint8_t testb = 0;
 
	DS18B20_IO_OUT();     //設(shè)置為輸出
 
	for (j=1;j<=8;j++) 
	{
		testb = dat&0x01;
		dat = dat>>1;
		if(testb)       // 寫(xiě)1
		{
			DS18B20_DQ_OUT(0);
			delay_us(2);                            
			DS18B20_DQ_OUT(1);
			delay_us(49);             
		}
		else            //寫(xiě)0
		{
			DS18B20_DQ_OUT(0);
			delay_us(49);             
			DS18B20_DQ_OUT(1);
			delay_us(2);                          
		}
	}
}
 
//開(kāi)始溫度轉(zhuǎn)換
void DS18B20_Start(void)
{   						               
	DS18B20_Rst();	   
	DS18B20_Check();	 
	DS18B20_Write_Byte(0xcc);// skip rom
	DS18B20_Write_Byte(0x44);// convert
}

//初始化DS18B20的IO口 DQ 同時(shí)檢測(cè)DS的存在
//返回1:不存在
//返回0:存在    	 
uint8_t DS18B20_Init(void)
{
	GPIO_InitTypeDef GPIO_Initure;
	DS18B20_DATA_CLK();			//開(kāi)啟GPIOA時(shí)鐘

	GPIO_Initure.Pin=DS18B20_DATA_PIN;           	//PA0
	GPIO_Initure.Mode=GPIO_MODE_OUTPUT_PP;  //推挽輸出
	GPIO_Initure.Pull=GPIO_PULLUP;          //上拉
	GPIO_Initure.Speed=GPIO_SPEED_FREQ_LOW;//高速
	HAL_GPIO_Init(DS18B20_DATA_PORT,&GPIO_Initure);     //初始化
 
	DS18B20_Rst();
	return DS18B20_Check();
}

//從ds18b20得到溫度值
//精度:0.1C
//返回值:溫度值 (-550~1250) 
short DS18B20_Get_Temp(void)
{
	uint8_t temp = 0;
	uint8_t TL = 0,TH = 0;
	short tem = 0;

	DS18B20_Start ();           //開(kāi)始轉(zhuǎn)換
	DS18B20_Rst();
	DS18B20_Check();	 
	DS18B20_Write_Byte(0xcc);   // skip rom
	DS18B20_Write_Byte(0xbe);   // convert	    
	TL=DS18B20_Read_Byte();     // LSB   
	TH=DS18B20_Read_Byte();     // MSB  
	
	if(TH > 7)
	{
			TH = ~TH;
			TL = ~TL; 
			temp = 0;//溫度為負(fù)  
	}
	else 
		temp = 1;//溫度為正	
	
	tem = TH; //獲得高八位
	tem <<= 8;    
	tem += TL;//獲得底八位
	tem=(double)tem*0.625;//轉(zhuǎn)換  
	
	if(temp)
		return tem; //返回溫度值
	else 
		return -tem;    
}
 

LCD1602顯示函數(shù)

#include "lcd1602.h"
                             
#define DELAY_2N     0

void lcd_delay_us(unsigned int t)
{
	unsigned int i, j;
	
	for(i = 10; i > 0; i--)
		for(j = t; j > 0; j--);
}

void lcd_delay_ms(unsigned int t)
{	
	unsigned int i;
	
	for(i = t; i > 0; i--)
		lcd_delay_us(10);
}

//==================================================
void LCD_Init(void)
{
		GPIO_InitTypeDef GPIO_Initure;   

		LCD_CTRL_CLK();
		LCD_DATA_CLK();
		
		GPIO_Initure.Pin = LCD_RS_PIN|LCD_RW_PIN|LCD_EN_PIN; 				
		GPIO_Initure.Mode = GPIO_MODE_OUTPUT_PP;  	
		GPIO_Initure.Pull = GPIO_PULLUP;          
		GPIO_Initure.Speed = GPIO_SPEED_FREQ_MEDIUM;   
		HAL_GPIO_Init(LCD_CTRL_PORT, &GPIO_Initure);

		GPIO_Initure.Pin = LCD_DATA0_PIN|LCD_DATA1_PIN|LCD_DATA2_PIN|LCD_DATA3_PIN|LCD_DATA4_PIN|LCD_DATA5_PIN|LCD_DATA6_PIN|LCD_DATA7_PIN; 				
		HAL_GPIO_Init(LCD_DATA_PORT, &GPIO_Initure);
	

    LCD_RW(0);			//讀寫(xiě)位直接低電平,只寫(xiě)不讀

    /*********************液晶初始化**************************/        
    lcd_delay_us(340); 
		LCD_RS(0);
   
    LCD_write_cmd(0x38);          // 8bit顯示模式,2行,5x7字體
    lcd_delay_ms(4);  
    LCD_write_cmd(0x08);         // 顯示關(guān)閉 
    lcd_delay_ms(4); 
    LCD_write_cmd(0x01);         // 顯示清屏 
    lcd_delay_ms(4); 
    LCD_write_cmd(0x06);         // 顯示光標(biāo)移動(dòng)設(shè)置 
    lcd_delay_ms(4);
    LCD_write_cmd(0x0c);         // 顯示開(kāi),光標(biāo)開(kāi),光標(biāo)閃爍
    lcd_delay_ms(4);
		LCD_write_cmd(0x01);         //清屏
		lcd_delay_ms(4);
}
/*--------------------------------------------------
函數(shù)說(shuō)明:寫(xiě)命令到液晶


---------------------------------------------------*/
void LCD_write_cmd(unsigned char cmd)
{
    LCD_RS(0);
    LCD_Write_byte(cmd);
    lcd_delay_us(340);
}
/*--------------------------------------------------
函數(shù)說(shuō)明:寫(xiě)數(shù)據(jù)到液晶


---------------------------------------------------*/
void LCD_write_data(unsigned char w_data)
{
    LCD_RS(1);
    LCD_Write_byte(w_data);
    lcd_delay_us(340);
}
/*--------------------------------------------------
函數(shù)說(shuō)明:寫(xiě)4bit到液晶
--------------------------------------------------*/
void LCD_Write_byte(unsigned char num)
{  
		if (num&0x01)
				data0(1);
		else
				data0(0);

		if (num&0x02)
				data1(1);
		else
				data1(0);

		if (num&0x04)
				data2(1);
		else
				data2(0);

		if (num&0x08)
				data3(1);
		else
				data3(0);

		if (num&0x10)
				data4(1);
		else
				data4(0);

		if (num&0x20)
				data5(1);
		else
				data5(0);

		if (num&0x40)
				data6(1);
		else
				data6(0);
		
		if (num&0x80)
				data7(1);
		else
				data7(0);
		
		lcd_delay_us(340);
    LCD_EN(1);
    lcd_delay_us(340);
    LCD_EN(0); 
    lcd_delay_us(340);
}

/*----------------------------------------------------
LCD_set_xy        : 設(shè)置LCD顯示的起始位置
輸入?yún)?shù):x、y    : 顯示字符串的位置,X:0-15,Y:0-1                
-----------------------------------------------------*/
void LCD_set_xy( unsigned char x, unsigned char y )
{
    unsigned char address = 0;
    if (y==0) 
    {
        address=0x80+x;
    }
    else 
    {
        address=0xc0+x;
    }
//		y ? (address=0xc0+x): (address=0x80+x) ;
    LCD_write_cmd(address);
}
/*---------------------------------------------------
LCD_write_string  : 英文字符串顯示函數(shù)
輸入?yún)?shù):*s      :英文字符串指針;
          X、Y    : 顯示字符串的位置                
---------------------------------------------------*/
void LCD_write_string(unsigned char X,unsigned char Y, char *s)
{
    LCD_set_xy(X,Y);   
    while (*s) 
    {
        LCD_write_data(*s);
        s++;
    }
}

//=======================================================
void LCD_wstring(unsigned char X,unsigned char *s)
{
    LCD_write_cmd(X);   
    while (*s) 
    {
        LCD_write_data(*s);
        s++;
    }
}

開(kāi)發(fā)資料

在這里插入圖片描述
0.常見(jiàn)使用問(wèn)題及解決方法–必讀?。。?!

  1. 程序源碼
  2. Proteus仿真
  3. 原理圖
  4. PCB
  5. 源文件截圖
  6. 參考文檔
  7. 講解視頻
    8.功能要求
    Altium Designer 軟件資料
    DS18B20(中文).pdf
    KEIL軟件資料
    Proteus軟件資料
    單片機(jī)學(xué)習(xí)資料
    答辯技巧
    設(shè)計(jì)報(bào)告常用描述
    鼠標(biāo)雙擊打開(kāi)查找更多51 STM32單片機(jī)課程畢業(yè)設(shè)計(jì).url

百度網(wǎng)盤(pán)下載鏈接

  • 設(shè)計(jì)資料獲取聯(lián)系方式.doc

推薦器件

更多器件
器件型號(hào) 數(shù)量 器件廠商 器件描述 數(shù)據(jù)手冊(cè) ECAD模型 風(fēng)險(xiǎn)等級(jí) 參考價(jià)格 更多信息
ATXMEGA192D3-MH 1 Atmel Corporation RISC Microcontroller, 16-Bit, FLASH, AVR RISC CPU, 32MHz, CMOS, 9 X 9 MM, 1 MM HEIGHT, 0.50 MM PITCH, GREEN, MO-220VMMD, MLF-64
$5.62 查看
LPC4357FET256,551 1 NXP Semiconductors LPC4357FET256 - Dual-core Cortex-M4/M0, 1 MB Flash, 136 kB SRAM, 2 HS USB with on-chip PHY, Ethernet, LCD, CAN, AES, SPIFI, SGPIO, SCT BGA 256-Pin

ECAD模型

下載ECAD模型
$15.87 查看
MK70FN1M0VMJ12R 1 Freescale Semiconductor 32-BIT, FLASH, 120MHz, RISC MICROCONTROLLER, PBGA256, 17 X 17 MM, MAPBGA-256
暫無(wú)數(shù)據(jù) 查看

相關(guān)推薦

電子產(chǎn)業(yè)圖譜