《测控仪器设计 实验4--PC机与单片机串行通讯实验.docx》由会员分享,可在线阅读,更多相关《测控仪器设计 实验4--PC机与单片机串行通讯实验.docx(7页珍藏版)》请在优知文库上搜索。
1、实验报告(理工类)开课学院及实验室:机械工程学院实验时间:年月日学生姓名学号成绩学生所在学院年级/专业/班12级/自动化/西华理1课程名称测控仪器设计课程代码实验项目名称PC机与单片机串行通讯实验(3)项目代码指导教师项目学分一、实验目的二、实验原理三、实验设备、仪器及材料四、实验步骤(按照实际操作过程)五、实验过程记录(数据、图表、计算等)读取DS18B20温度,通过LCDI602显示出来,并发送给上位机#include# IncIude#include# defineuintunsignedint# defineucharunsignedchar# define_Nop()_nop_()f
2、loatftemp;564p C - 333t Ppp r -_p 111 a r r r t Joooa 2 P Ppd 2 S W nd Prrec -I ddd Qccce IA Ix IA n 111 tf 1 1 1 1 bbbbd Sss s#voiddelayl(void)intk;for(k=0;k1lvu-IiOwt=00)8TXXlXda11Oo=OnWrr-a-OOSSOOS-O+rtOt-port-OrtOlPOu-SCbyO-rsrwendaenenPDYXPdddddddd-F-CcCCCCCCvoiddelay(unsignedinti)while(i-);Ini
3、t_DS18B20(void)x=0;C;7177d)O4Oe,8;8i2l(o(l(/(gyyy;y1=a=a=aQaS1111nQCQeQe-CUDdDdDdXdReadOneChar(void)unsignedchari=0;unsignedchardat=0;for(i=8;i0;i)DQ=0;dat=l;DQ=1;if(DQ)datI=0x80;delay(4);return(dat);WriteOneChar(unsignedchardat)unsignedchari=0;for(i=8;i0;i-)DQ=0;DQ=dat&OxOl;delay(5);dat=l;DQ=1;Read
4、Temperature(void)unsignedchara=0;unsignedcharb=0;unsignedintt=0;floattt-O*Init-DS18B0();WriteOneChar(OxCC);WriteOneChar(0x44);Init_DS18B20();WriteOneChar(OxCC);WriteOneChar(xBE);a=ReadOneChar();B=ReadOneChar();t=b;t=8;t=ta;tt=t*O.0625:t=tt*10+0.5;f-temp=(tt*100.5)/10;return(t):unsignedcharmun-char-t
5、ableLJ=z0123456789abcdef;unsignedchartemptablet-z,Temp:.C;voiddelay_lms(uchar x)5211j X r (O r ef al hi Ch U W1JvoidInit(void)TMOD=0x20;THl=Oxfd;TLl=Oxfd;SCON=0x50;PCON&=0x00;JRl=1;voidsendchar(char*ch)doSBUF=*ch+;while(!TI);TI=O;jwhile(*ch);main()unsignedint,i-0;ucharbuffL4;Init();ReadTemperature()
6、;ledsystemresetO;deyz(2)delay(2);WELA=O;for(i=0;i O ,f off If U (Ub sb( m( r 1-f a-th y n C aid 1 r n e Pe d S sPrivateSubCommand!ClickOMSComml.Settings=*9600,N,8,1MSComml.CommPort=Com.ListIndcx+1MSComml.InBufferSize=8MSComml.OutBufferSize=2IfMSComml.PortOpcn=TrueThenMSComml.PortOpen=FalseMSComml.RT
7、hreshold=4MSComml.SThreshold=1MSComml.InputLen=OMSComml.InputMode=comlnputModeTextTfMSComml.PortOpen=FalseThenMSComml.PortOpen=TrueMSComml.InBuffcrCount=OEndSubPrivateSubMSCommlOnComm()DimrecAsStringSelectCaseMSComml.CommEventCaseComEvReceiverec=MSComml.InputTpvt1TPXt=ppMSComml.InBufferCount二OEndSelectEndSubPIMDP(LUMMP02AD2PD3D3PO3D4POSftDSP0j6D6P01D?F2118f2MP2210P2311PZRXDP3.VTXDP32NTDP33rtNTP3.4JfTDns,P3SWRP37而六、实验结果分析及问题讨论