实验十六 基于单片机的风扇控制器模拟(综合实验).doc_第1页
实验十六 基于单片机的风扇控制器模拟(综合实验).doc_第2页
实验十六 基于单片机的风扇控制器模拟(综合实验).doc_第3页
实验十六 基于单片机的风扇控制器模拟(综合实验).doc_第4页
实验十六 基于单片机的风扇控制器模拟(综合实验).doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验十六 风扇控制器模拟(综合实验)一、实验目的1. 掌握PROTEUS ISIS软件仿真单片机原理的方法2. 温度传感器DS18B20、PWM实验方法等的综合运用,控制电机转速二、实验内容基于单片机的温控风扇系统,采用单片机作为控制器,利用温度传感器DS18B20作为温度采集元件,并根据采集到的温度,通过一个达林顿反向驱动器ULN2803驱动风扇电机。根据检测到的温度与系统设定的温度的比较实现风扇电机的自动启动和停止,并能根温度的变化自动改变风扇电机的转速,同时用LED八段数码管显示检测到的温度与设定的温度。三、实验电路图16.1 电路原理图打开Proteus ISIS编辑环境,按表16.1所列元件清单添加元件。表16.1元件清单元件清单所属类所属子类AT89C52Microprocessor ICs8051 FamilyULN2803AnalogMiscellaneousDS18B20Data ConvertersTemperature SensorsMOTOR-DCElectromechanical7SEG-MPX6-CCOptoelectronics7-Segment DisplaysCAPCapacitorsGenericCAP.ELECCapacitorsGenericCRYSTALMiscellaneous.RESResistorsGenericBUTTONSwitches&RelaysSwitchesRESPACK-8ResistorsResistor Packs元件全部添加完后,在Proteus ISIS编辑环境中按图16.1所示连接硬件原理图。四、实验程序#include #define uchar unsigned char#define uint unsigned intsbit DQ=P17;sbit key1=P13;sbit key2=P14;sbit dianji=P31;float ff;uint y3;uchar shi,ge,xiaoshu,sheding=20,gaonum,dinum;uchar code dispcode= /段码0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71;uchar code table= /带小数点的段码0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef;uchar dispbitcode= /位选0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f;uchar dispbuf8=0,0,0,0,0,0,0,0;void Delay (uint num)/ 延时函数 while (-num);void digitalshow(uchar a4,uchar a3,uchar a2,uchar a1,uchar a0) dispbuf0=a0;dispbuf1=a1;dispbuf2=a2;dispbuf3=a3;dispbuf4=a4;P2=0xff;P0=dispcodedispbuf0;P2=dispbitcode5;Delay(1);P2=0xff;P0=dispcodedispbuf1;P2=dispbitcode4;Delay(1); P2=0xff;P0=dispcodedispbuf2;P2=dispbitcode2;Delay(1);P2=0xff;P0=tabledispbuf3;P2=dispbitcode1;Delay(1);P2=0xff;P0=dispcodedispbuf4;P2=dispbitcode0;Delay(1);void dmsec(uint count) uint i; /1ms延时while(count-) for(i=0;i125;i+)void tmreset(void) DQ=0; Delay(90); /精确延时 大于480us DQ=1; Delay(4); /90,4 可以小范围变化void tmpre(void) while(DQ);while(DQ);Delay(4);bit tmrbit(void) uint i;bit dat;DQ=0;i+; /i+;大概1usDQ=1;i+;i+;dat=DQ;Delay(8);return(dat);uchar tmrbyte(void) /读一个比特 uchar i,j,dat;dat=0;for(i=1;i=8;i+) j=tmrbit();dat=(j1);return(dat);void tmwbyte(uchar dat) /写一个比特 uint i;uchar j;bit testb;for(j=1;j1; /从低位开始if(testb) /Write 1 DQ=0; /先拉低i+;i+; /1usDQ=1;Delay(4);else /Write 0 DQ=0;Delay(4);DQ=1;i+;i+; /再拉高void tmstart(void) /DS18B20开始转换 dmsec(1);tmreset();tmpre();dmsec(1);tmwbyte(0xcc); /skip romtmwbyte(0x44); /转换uchar tmrtemp(void) /读取温度 uchar a,b;tmreset();tmpre();dmsec(1);tmwbyte(0xcc); /skip romtmwbyte(0xbe); /转换a=tmrbyte(); /MSB高8位b=tmrbyte();y3=b;y3=y3|a;ff=y3*0.0625;y3=ff*10+0.5;return(y3);void keyscan(void) if(key1=0) dmsec(5);if(key1=0) sheding+;if(sheding=100)sheding=20;while(!key1);else if(key2=0) dmsec(5);if(key2=0) sheding-;if(sheding=0) sheding=20;while(!key2);void deal(uint tmp) /温度处理 if(tmpsheding)&(tmp(sheding+5)&(tmp(sheding+10)&(tmp=(sheding+15) gaonum=3;dinum=1;else gaonum=4; dinum=0;void dianjik() /电机控制 uchar q,i;for(q=0;q0;i-) digitalshow(shi,ge,xiaoshu,sheding/10,sheding%10);for(q=0;q0;i-) digitalshow(shi,ge,xiaoshu,sheding/10,sheding%10); void main(void) uint last;dianji=0;tmstart();dmsec(450); /初始化DS18B20while(1) tmstart();/DS18B20开始转换dmsec(2);last=tmrtemp()+

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论