文章目錄
- 1 簡介
- 2 緒論
- 2.1 課題背景與目的
- 3 系統設計
- 詳細設計描述
- 3.2 硬體部分
- 溫度測量電路
- 其他電路部分
- 3.3 軟體部分
- 主程式
- 子系統程式
- 溫濕度程式流程
- 鍵盤顯示子程式
- 3.4 實作效果
- 3.5 部分相關代碼
- 4 最后
1 簡介
Hi,大家好,這里是丹成學長,今天向大家介紹一個 單片機專案
基于單片機的智能溫控農業大棚系統
大家可用于 課程設計 或 畢業設計
技術解答、畢設幫助、開題指導
print("Q 746876041")

2 緒論
2.1 課題背景與目的
近年來我國的溫室控制取得了 長足的進步, 首先在溫室群控制方面, 進行了初步的探索和理論研究, 其次在溫室控制中引入了 人工智能和先進的控制演算法, 當前溫室控制系統研究熱點己由簡單的DDC(直接數字控制) 發展到分布式控制系統, 如 DCS(分布式控制) 、 FCS(柔性控制) 等網路化的控制系統,實施遠程控制, 雖然國內溫室規模有限, 還沒有形成規模經濟, 另外構建的費用也較高, 但從長遠來看,溫室監控系統分布式和網路化將是一種必然的趨勢, 本方案以 AT89C51 單片機系統為核心來對溫度,濕度和二訊訓碳濃度進行實時控制和檢測, 檢測單元能獨立完成各自功能, 并根據單片機的指令對溫度進行實時或定時采集, 單片機負責控制指令的發送, 并控制各機構進行溫度采集, 手機測量資料, 同時對測量結果進行處理及顯示,

3 系統設計
本設計是基于AT89C51單片機的溫濕度智能控制采集系統,主要完成以下功能:
(1)選擇AT89C51單片機,了解其基本特性和功能,使用AT89C51實作對溫濕度及二訊訓碳濃度的智能控制,
(2)使用溫度傳感器測量現場環境溫度,進行資料的采集及傳到單片機處理,
(3)使用濕度傳感器對現場時讀資料采集,由單片機進行資料處理和控制,實作范圍為1%—99%RH的濕度控制,
(4)設計人機對話介面,鍵盤顯示和報警系統,
(5)設計執行機構電路,是單片機能夠自動控制執行機構作業,
(6)在完成以上功能時,要確保系統的可靠性和穩定性,是系統能夠長期穩定的工
作,

詳細設計描述
采用的芯片主要有:ATMEL公司生產的AT89C51單片機,AD公司生產的AD590集成溫度傳感器,電容式濕度傳感器HS1101,
單片機通過AD0809A\D轉換器把從傳感器輸出的模擬信號轉換成數字信號,通過單片機對脈沖寬值的計算得到濕度值,
選用的二訊訓碳傳感器是FIGARO(弗加羅)公司生產的固態電化學型氣體敏感元件TGS4160,通過監測S(+)、S(-)兩個電極之間所產生的電勢值EMF,就可以測量CO2的濃度值,
在這里溫度及二訊訓碳濃度需要模數轉換,
在執行機構中,可以通過單片機直接控制來達到需要的數值,
顯示部分由單片機分時把溫度濕度及二訊訓碳濃度值送到數碼管顯示,通過鍵盤可以設定引數的上限值下限值,當當前引數超過設定值時,由單片機控制報警電路報警,
同時單片機控制相應的執行機構運行相應的動作,使得溫度濕度及二訊訓碳濃度恢復到正常水平,

3.2 硬體部分
溫度測量電路
AD590 封裝圖簡介

溫度測量電路

其他電路部分
非關鍵點,略
3.3 軟體部分
主程式
主程式是整個測控系統中最重要的程式, 各個子程式都在主程式的協調指揮下運行, 是一個順序執行的無限回圈程式, 可以被任何優先級的中斷請求所打斷,
主程式的初始化作業主要完成對 X25045、 HS1101、 LED、 ADC0809、 測驗資料暫存器、 串行口、 定時/計數器等的初始化, 在程式的開始, 撰寫一段簡短的程式, 執行該程式并與預定結果進行比較, 如果不同, 則跳轉到錯誤處理子程式;如果相同, 則證明 CPU 及其它部件作業正常, 程式繼續向下執行,

子系統程式

溫濕度程式流程
選用電容式傳感器 HS1101, 根據其電容的改變而改變了 555 定時器的輸出脈沖的寬度,

鍵盤顯示子程式

3.4 實作效果

過熱驅動風扇

換上LED屏,并且模擬溫室環境(加上個盒子)

3.5 部分相關代碼
/************************************************
作者:丹成學長,Q746876041
************************************************/
/*********************************************************************
* INCLUDES
*/
#include "ZComDef.h"
#include "OSAL.h"
#include "OSAL_Nv.h"
#include "OnBoard.h"
#include "ZMAC.h"
#ifndef NONWK
#include "AF.h"
#endif
/* Hal */
#include "hal_lcd.h"
#include "hal_led.h"
#include "hal_adc.h"
#include "hal_drivers.h"
#include "hal_assert.h"
#include "hal_flash.h"
/*********************************************************************
* MACROS
*/
/*********************************************************************
* CONSTANTS
*/
// Maximun number of Vdd samples checked before go on
#define MAX_VDD_SAMPLES 3
#define ZMAIN_VDD_LIMIT HAL_ADC_VDD_LIMIT_4
/*********************************************************************
* TYPEDEFS
*/
/*********************************************************************
* GLOBAL VARIABLES
*/
/*********************************************************************
* EXTERNAL VARIABLES
*/
/*********************************************************************
* EXTERNAL FUNCTIONS
*/
extern bool HalAdcCheckVdd (uint8 limit);
/*********************************************************************
* LOCAL VARIABLES
*/
/*********************************************************************
* LOCAL FUNCTIONS
*/
static void zmain_dev_info( void );
static void zmain_ext_addr( void );
static void zmain_vdd_check( void );
#ifdef LCD_SUPPORTED
static void zmain_lcd_init( void );
#endif
/*********************************************************************
* @fn main
* @brief First function called after startup.
* @return don't care
*/
int main( void )
{
// Turn off interrupts
osal_int_disable( INTS_ALL );
// Initialization for board related stuff such as LEDs
HAL_BOARD_INIT();
// Make sure supply voltage is high enough to run
zmain_vdd_check();
// Initialize board I/O
InitBoard( OB_COLD );
// Initialze HAL drivers
HalDriverInit();
// Initialize NV System
osal_nv_init( NULL );
// Initialize the MAC
ZMacInit();
// Determine the extended address
zmain_ext_addr();
// Initialize basic NV items
zgInit();
#ifndef NONWK
// Since the AF isn't a task, call it's initialization routine
afInit();
#endif
// Initialize the operating system
osal_init_system();
// Allow interrupts
osal_int_enable( INTS_ALL );
// Final board initialization
InitBoard( OB_READY );
// Display information about this device
zmain_dev_info();
/* Display the device info on the LCD */
#ifdef LCD_SUPPORTED
zmain_lcd_init();
#endif
#ifdef WDT_IN_PM1
/* If WDT is used, this is a good place to enable it. */
WatchDogEnable( WDTIMX );
#endif
osal_start_system(); // No Return from here
return 0; // Shouldn't get here.
} // main()
/*********************************************************************
* @fn zmain_vdd_check
* @brief Check if the Vdd is OK to run the processor.
* @return Return if Vdd is ok; otherwise, flash LED, then reset
*********************************************************************/
static void zmain_vdd_check( void )
{
uint8 vdd_passed_count = 0;
bool toggle = 0;
// Repeat getting the sample until number of failures or successes hits MAX
// then based on the count value, determine if the device is ready or not
while ( vdd_passed_count < MAX_VDD_SAMPLES )
{
if ( HalAdcCheckVdd (ZMAIN_VDD_LIMIT) )
{
vdd_passed_count++; // Keep track # times Vdd passes in a row
MicroWait (10000); // Wait 10ms to try again
}
else
{
vdd_passed_count = 0; // Reset passed counter
MicroWait (50000); // Wait 50ms
MicroWait (50000); // Wait another 50ms to try again
}
/* toggle LED1 and LED2 */
if (vdd_passed_count == 0)
{
if ((toggle = !(toggle)))
HAL_TOGGLE_LED1();
else
HAL_TOGGLE_LED2();
}
}
/* turn off LED1 */
HAL_TURN_OFF_LED1();
HAL_TURN_OFF_LED2();
}
/**************************************************************************************************
* @fn zmain_ext_addr
*
* @brief Execute a prioritized search for a valid extended address and write the results
* into the OSAL NV system for use by the system. Temporary address not saved to NV.
*
* input parameters
*
* None.
*
* output parameters
*
* None.
*
* @return None.
**************************************************************************************************
*/
static void zmain_ext_addr(void)
{
uint8 nullAddr[Z_EXTADDR_LEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
uint8 writeNV = TRUE;
// First check whether a non-erased extended address exists in the OSAL NV.
if ((SUCCESS != osal_nv_item_init(ZCD_NV_EXTADDR, Z_EXTADDR_LEN, NULL)) ||
(SUCCESS != osal_nv_read(ZCD_NV_EXTADDR, 0, Z_EXTADDR_LEN, aExtendedAddress)) ||
(osal_memcmp(aExtendedAddress, nullAddr, Z_EXTADDR_LEN)))
{
// Attempt to read the extended address from the location on the lock bits page
// where the programming tools know to reserve it.
HalFlashRead(HAL_FLASH_IEEE_PAGE, HAL_FLASH_IEEE_OSET, aExtendedAddress, Z_EXTADDR_LEN);
if (osal_memcmp(aExtendedAddress, nullAddr, Z_EXTADDR_LEN))
{
// Attempt to read the extended address from the designated location in the Info Page.
if (!osal_memcmp((uint8 *)(P_INFOPAGE+HAL_INFOP_IEEE_OSET), nullAddr, Z_EXTADDR_LEN))
{
osal_memcpy(aExtendedAddress, (uint8 *)(P_INFOPAGE+HAL_INFOP_IEEE_OSET), Z_EXTADDR_LEN);
}
else // No valid extended address was found.
{
uint8 idx;
#if !defined ( NV_RESTORE )
writeNV = FALSE; // Make this a temporary IEEE address
#endif
/* Attempt to create a sufficiently random extended address for expediency.
* Note: this is only valid/legal in a test environment and
* must never be used for a commercial product.
*/
for (idx = 0; idx < (Z_EXTADDR_LEN - 2);)
{
uint16 randy = osal_rand();
aExtendedAddress[idx++] = LO_UINT16(randy);
aExtendedAddress[idx++] = HI_UINT16(randy);
}
// Next-to-MSB identifies ZigBee devicetype.
#if ZG_BUILD_COORDINATOR_TYPE && !ZG_BUILD_JOINING_TYPE
aExtendedAddress[idx++] = 0x10;
#elif ZG_BUILD_RTRONLY_TYPE
aExtendedAddress[idx++] = 0x20;
#else
aExtendedAddress[idx++] = 0x30;
#endif
// MSB has historical signficance.
aExtendedAddress[idx] = 0xF8;
}
}
if (writeNV)
{
(void)osal_nv_write(ZCD_NV_EXTADDR, 0, Z_EXTADDR_LEN, aExtendedAddress);
}
}
// Set the MAC PIB extended address according to results from above.
(void)ZMacSetReq(MAC_EXTENDED_ADDRESS, aExtendedAddress);
}
/**************************************************************************************************
* @fn zmain_dev_info
*
* @brief This displays the IEEE (MSB to LSB) on the LCD.
*
* input parameters
*
* None.
*
* output parameters
*
* None.
*
* @return None.
**************************************************************************************************
*/
static void zmain_dev_info(void)
{
#ifdef LCD_SUPPORTED
uint8 i;
uint8 *xad;
uint8 lcd_buf[Z_EXTADDR_LEN*2+1];
// Display the extended address.
xad = aExtendedAddress + Z_EXTADDR_LEN - 1;
for (i = 0; i < Z_EXTADDR_LEN*2; xad--)
{
uint8 ch;
ch = (*xad >> 4) & 0x0F;
lcd_buf[i++] = ch + (( ch < 10 ) ? '0' : '7');
ch = *xad & 0x0F;
lcd_buf[i++] = ch + (( ch < 10 ) ? '0' : '7');
}
lcd_buf[Z_EXTADDR_LEN*2] = '\0';
HalLcdWriteString( "IEEE: ", HAL_LCD_LINE_1 );
HalLcdWriteString( (char*)lcd_buf, HAL_LCD_LINE_2 );
#endif
}
#ifdef LCD_SUPPORTED
/*********************************************************************
* @fn zmain_lcd_init
* @brief Initialize LCD at start up.
* @return none
*********************************************************************/
static void zmain_lcd_init ( void )
{
#ifdef SERIAL_DEBUG_SUPPORTED
{
HalLcdWriteString( "TexasInstruments", HAL_LCD_LINE_1 );
#if defined( MT_MAC_FUNC )
#if defined( ZDO_COORDINATOR )
HalLcdWriteString( "MAC-MT Coord", HAL_LCD_LINE_2 );
#else
HalLcdWriteString( "MAC-MT Device", HAL_LCD_LINE_2 );
#endif // ZDO
#elif defined( MT_NWK_FUNC )
#if defined( ZDO_COORDINATOR )
HalLcdWriteString( "NWK Coordinator", HAL_LCD_LINE_2 );
#else
HalLcdWriteString( "NWK Device", HAL_LCD_LINE_2 );
#endif // ZDO
#endif // MT_FUNC
}
#endif // SERIAL_DEBUG_SUPPORTED
}
#endif
/*********************************************************************
*********************************************************************/
/*******************************************************************
篇幅有限,只展示部分代碼
作者:丹成學長,Q746876041
********************************************************************/
4 最后
技術解答、畢設幫助、開題指導
print("Q 746876041")

單片機畢設專案大全:
https://blog.csdn.net/huawei123444/article/details/119822845
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/348502.html
標籤:其他
上一篇:工業物聯網
下一篇:物聯網快速入門指南
