標題: DS18B20溫度傳感器溫度報警,并將溫度上傳到上位機,仿真和程序 [打印本頁]

作者: 1805220100    時間: 2020-12-5 11:52
標題: DS18B20溫度傳感器溫度報警,并將溫度上傳到上位機,仿真和程序
/****
* 【外部晶振】: 11.0592mhz       
* 【主控芯片】: STC89C52
* 【編譯環(huán)境】: Keil μVisio4
* 【程序功能】:                                                                                            
* 【使用說明】: 實時采集當前環(huán)境溫度值,并顯示于數(shù)碼管上。
                  同時,當溫度高于某一值時(此處設為40攝氏度)低于5也會響,蜂鳴器便會發(fā)出報警。
                  而當?shù)陀谠撝禃r,蜂鳴器自動停止報警。以及上傳溫度到pc
               
**********************************************************************************/

#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit DS=P2^2;           //define interface
uint temp;             // variable of temperature
uchar flag1;            // sign of the result positive or negative
sbit dula=P2^6;
sbit wela=P2^7;
sbit beep=P2^3;
uint num;
uchar A1,A2,A2t,A3;
void uart();//函數(shù)聲明

unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
                        0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,
                        0x87,0xff,0xef};



//串口初始化
void uart()
{
        EA=1;//開總中斷
        ES=1;//串口中斷允許位,ES=1允許串口中斷 ES=0禁止串口中斷,IE中斷允許寄存器
        SM0=0;SM1=1;//串口工作方式1,8位uart波特率可變
        REN=1;//串口允許接收
        TR1=1;//啟動定時器1
        TMOD |= 0X20;//定時器1工作模式2,8位自動重裝
        TH1=0XFD;
        TL1=0XFD;//設置波特率9600
}

void delay(uint count)      //delay
{
  uint i;
  while(count)
  {
    i=200;
    while(i>0)
    i--;
    count--;
  }
}
void mx()
{
        TI=1;
        SBUF=0x00;;//送sbuf
        while(!TI);
        TI=0;       
        delay(10);
}
void dsreset(void)       //send reset and initialization command
{
  uint i;
  DS=0;
  i=103;
  while(i>0)i--;
  DS=1;
  i=4;
  while(i>0)i--;
}
............完整代碼在文件中

屏幕截圖(95).png (150.42 KB, 下載次數(shù): 57)

屏幕截圖(95).png

DS18B20--溫度報警器,串口通信.rar

227.04 KB, 下載次數(shù): 54, 下載積分: 黑幣 -5






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1