您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > 其它相关文档 > 51单片机智能温度监控系统
51单片机智能温度监控系统(含上位机和单片机源代码)上位机部分:#regionNamespaceInclusionsusingSystem;usingSystem.Data;usingSystem.Text;usingSystem.Drawing;usingSystem.IO.Ports;usingSystem.Windows.Forms;usingSystem.ComponentModel;usingSystem.Collections.Generic;usingSystem.IO;usingSerialPortTerminal.Properties;#endregionnamespaceSerialPortTerminal{#regionPublicEnumerationspublicenumDataMode{Text,Hex}publicenumLogMsgType{Incoming,Outgoing,Normal,Warning,Error};#endregionpublicpartialclassfrmTerminal:Form{#regionLocalVariables[System.Runtime.InteropServices.DllImport(user32.dll)]publicstaticexternboolReleaseCapture();[System.Runtime.InteropServices.DllImport(user32.dll)]publicstaticexternboolSendMessage(IntPtrhwnd,intwMsg,intwParam,intlParam);publicconstintWM_SYSCOMMAND=0x0112;publicconstintSC_MOVE=0xF010;publicconstintHTCAPTION=0x0002;privateSerialPortcomport=newSerialPort();privateColor[]LogMsgTypeColor={Color.Blue,Color.Green,Color.Black,Color.Orange,Color.Red};privateboolKeyHandled=false;privateboolreceivesu=false;privateint[]Temperature={-1,-1};//recordTemperatureprivatedouble[]TbiaoDU={0,5,10,15,20,25,30,35,40,45,50};privateint[]TemDrawLine=newint[11];privatestring[]TemDrawLineTime=newstring[11];privateintcount=-1;privateintBiLi=25;//比例privateintTemBase=0;privateintHTA=30;//高温报警privateintLTA=20;//低温报警值privateDoubleknownHt=-100;//已知的最高温度privateDoubleknownLt=100;//已知的最低温度privateintfangdaFlag=1;//huabiprivatePenbluepen=newPen(Color.FromArgb(76,76,76),1);privatePenredpen=newPen(Color.Red,2);privatePenYellowpen=newPen(Color.Yellow,2);privatePenapen=newPen(Color.FromArgb(0,255,255),1);privatePenNOMEL=newPen(Color.FromArgb(0,255,0),1);privateSolidBrushyellowbr=newSolidBrush(Color.Yellow);privateSolidBrushblackbr=newSolidBrush(Color.Black);privateSolidBrushbluebr=newSolidBrush(Color.Blue);privateSolidBrushLightblue=newSolidBrush(Color.FromArgb(0,255,255));privateSolidBrushredbr=newSolidBrush(Color.Red);privateinttemCount=1;#endregion#regionConstructorpublicfrmTerminal(){this.DoubleBuffered=true;deflult();InitializeComponent();InitializeControlValues();comport.DataReceived+=newSerialDataReceivedEventHandler(port_DataReceived);}#endregion#regionLocalMethodsprotectedoverridevoidOnPaint(PaintEventArgse){base.OnPaint(e);Graphicsdc=e.Graphics;dc.FillRectangle(blackbr,1,1,1185,601);//绘制背景dc.DrawRectangle(apen,0,0,1186,602);if(this.checkBoxautoAda.Checked){AutoAda();}else{this.fangdaFlag=1;}dc.DrawLine(bluepen,newPoint(32,180),newPoint(770,180));for(inti=0;i=10;i++)//绘制网格{dc.DrawLine(bluepen,newPoint(32,200+20*i),newPoint(770,200+20*i));e.Graphics.DrawString(TbiaoDU[10-i]+,newFont(Arial,9),redbr,newRectangleF(0,193+20*i,40,20),newStringFormat());dc.DrawLine(bluepen,newPoint(32+67*i,180),newPoint(32+67*i,400));}dc.DrawLine(bluepen,newPoint(770,180),newPoint(770,400));for(inti=0;i=count;i++){if(this.TemDrawLine[i]=HTA*100){dc.DrawLine(redpen,newPoint(32+67*i,400-(this.TemDrawLine[i]*this.fangdaFlag-this.TemBase)/this.BiLi),newPoint(32+67*(i+1),400-(this.TemDrawLine[i]*this.fangdaFlag-this.TemBase)/this.BiLi));}elseif(this.TemDrawLine[i]=LTA*100){dc.DrawLine(apen,newPoint(32+67*i,400-(this.TemDrawLine[i]*this.fangdaFlag-this.TemBase)/this.BiLi),newPoint(32+67*(i+1),400-(this.TemDrawLine[i]*this.fangdaFlag-this.TemBase)/this.BiLi));}else{dc.DrawLine(NOMEL,newPoint(32+67*i,400-(this.TemDrawLine[i]*this.fangdaFlag-this.TemBase)/this.BiLi),newPoint(32+67*(i+1),400-(this.TemDrawLine[i]*this.fangdaFlag-this.TemBase)/this.BiLi));}e.Graphics.DrawString(this.TemDrawLineTime[i],newFont(Arial,9),yellowbr,newRectangleF(i*70,410,66,20),newStringFormat());//dc.FillRectangle(bluebr,810+27*i,200,27,200);//绘制背景}}privatevoidAutoAda(){doubletemBd;if(this.knownHt-this.knownLt=0.2){temBd=(this.knownHt-this.knownLt)/10.0;for(inti=0;i=10;i++)TbiaoDU[i]=Math.Round(temBd*i+this.knownLt,2);this.BiLi=(int)(this.knownHt*1000-this.knownLt*1000)/200;this.TemBase=(int)(this.knownLt*1000);//做到像素点级别的定位this.fangdaFlag=10;}}privatevoidExcuseBd_Click(objectsender,EventArgse){intHighT=0,LowT=0;doubletemBd;HighT=Int32.Parse(this.textBoxHigh.Text);LowT=Int32.Parse(this.textBoxLow.Text);if(HighTLowT){temBd=(HighT-LowT)/10.0;for(inti=0;i=10;i++)TbiaoDU[i]=Math.Round(temBd*i+LowT,2);this.BiLi=(HighT-LowT)*100/200;this.TemBase=LowT*100;//做到像素点级别的定位this.checkBoxautoAda.Checked=false;this.Refresh();}else{MessageBox.Show(输入错误,请重新输入!,提示信息);}}privatevoiddeflult(){for(inti=0;i=10;i++){TemDrawLine[i]=-100;TemDrawLineTime[i]=;}}privatevoidfrmTerminal_Load(objectsender,EventArgse){}privatevoidSaveSettings(){Settings.Default.BaudRate=int.Parse(cmbBaudRate.Text);Settings.Default.DataBits=int.Parse(cmbDataBits.Text);Settings.Default.Parity=(Parity)Enum.Parse(typeof(Parity),cmbParity.Text);Settings.Default.StopBits=(StopBits)Enum.Parse(typeof(StopBits),cmbStopBits.Text);Settings.Default.PortName=cmbPortName.Text;Settings.Default.Save();}privatevoidInitializeControlValues(){cmbParity.Items.Clear();cmbParity.Items.AddRange(Enum.GetNames(typeof(Parity)));cmbStopBits.Items.Clear();cmbStopBits.Items.AddR
本文标题:51单片机智能温度监控系统
链接地址:https://www.777doc.com/doc-3319351 .html