ImageVerifierCode 换一换
格式:DOCX , 页数:31 ,大小:20.31KB ,
资源ID:5459056      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/5459056.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(基于51单片机的温度测试系统+有VB上位机.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

基于51单片机的温度测试系统+有VB上位机.docx

1、基于51单片机的温度测试系统+有VB上位机简介:这是我学完51单片机的第一个作品,单片机型号为89c52,时钟芯片用的是DS1302,温度传感器用的是DS18B20,USB供电,掉电后时钟芯片继续工作,且已经设置好的温度上下限和闹钟数据不会丢失。上位机是用VB语言写的,只是一个模型,从上位机上可以观察当前温度值以及温度上下限,以后会更加完善其功能。下面是下位机程序和上位机程序,程序比较长,而且下位机程序的键盘部分写得有点麻烦。/*作者:江苏科技大学 电子信息科学与技术二班 吴亚迪注:此程序可以实现万年历闹钟温度测定 温度超过上下限发出警报断电后时钟不停,且已设好的温度上下限和闹钟数据不会丢失*

2、/#include#define uchar unsigned char#define uint unsigned intuchar code table=20 / / DAY- ; uchar code table1= : : ;uchar code table2=0123456789;uchar code table3= alarm clock ;sbit ds_clk=P36; sbit ds_io=P37;sbit ds_rst=P14;sbit lcdrs=P10;sbit lcdrw=P11;sbit lcden=P12;sbit scl=P32;sbit sda=P33;sbit

3、 ACC_7=ACC7;sbit P34=P34;bit alarm=0;/闹钟标志位bit stop_alarm=0;/停止闹钟标志位uchar i,j;uchar th,tl; /温度上下限uint th1,th2,tl1,tl2;uchar min,hour,sec; /闹钟时分秒uint min1,min2,hour1,hour2,sec1,sec2;void delay(uint i)uint j;for(;i0;i-)for(j=0;j0; i- ) ds_clk = 0; temp = add; ds_io= temp&0x01; add = 1; ds_clk = 1; for

4、 ( i=8; i0; i- ) ds_clk = 0; temp = date; ds_io =temp&0x01; date = 1; ds_clk = 1; ds_rst= 0; uchar read_ds(uchar add ) /ds1302指定地址读数据 unsigned char i,temp,date1; ds_rst=0; ds_clk=0; ds_rst= 1; for ( i=8; i0; i- ) ds_clk = 0; temp = add; ds_io=temp&0x01; add = 1; ds_clk = 1; for ( i=8; i0; i- ) /这里要注

5、意 ACC_7=ds_io; ds_clk = 1; ACC=1; ds_clk = 0; ds_rst=0; date1=ACC; return date1;void init_ds() /初始化ds1302write_ds(0x8e,0x00); /关闭写保护write_ds(0x80,0x22); /初始化秒write_ds(0x82,0x59); /分write_ds(0x84,0x23); /时write_ds(0x86,0x21); /日write_ds(0x88,0x05); /月write_ds(0x8a,0x06); /星期write_ds(0x8c,0x11); /年wri

6、te_ds(0x8e,0x80); /开写保护void read_all() /读s,m,h,date,mon,year,days=read_ds(0x81);s1=s/16;s2=s%16;m=read_ds(0x83);m1=m/16;m2=m%16;h=read_ds(0x85);h1=h/16;h2=h%16;date=read_ds(0x87);date1=date/16;date2=date%16;mon=read_ds(0x89);mon1=mon/16;mon2=mon%16;day=read_ds(0x8b);year=read_ds(0x8d);year1=year/16;

7、year2=year%16;/* 1602部分*/void write_com(uchar com) /写命令lcdrs=0;lcden=0;P0=com;delay(5);lcden=1;delay(5);lcden=0;void write_date(uchar date)/写数据lcdrs=1;lcden=0;P0=date;delay(5);lcden=1;delay(5);lcden=0;void init_1602() /初始化1602lcdrw=0;write_com(0x01);write_com(0x38);write_com(0x0f);write_com(0x06);fo

8、r(i=0;i16;i+)write_date(tablei);delay(10);write_com(0x80+0x40);for(i=0;i16;i+)write_date(table1i);delay(10);write_com(0x80+0x40+0x0e);write_date(0xdf);delay(10);write_date(c);/* EEPROM部分*/void delay1() ; ; void init()/初始化总线sda=1;delay1();scl=1;delay1();void start()/开始函数sda=1;delay1();scl=1;delay1();

9、sda=0;delay1();void stop()/停止函数sda=0;delay1();scl=1;delay1();sda=1;delay1();void respons()/应答uchar i;sda=1;delay1();scl=1;while(sda=1&i250) i+;scl=0;delay1();void write_byterom(uchar date)/向eeprom中写一字节数据uchar i;for(i=0;i8;i+)date=date1;scl=0;delay1();sda=CY;delay1();scl=1;delay1();scl=0;delay1();uch

10、ar read_byterom()/从eeprom中读一字节数据uchar i,temp;scl=0;delay1();for(i=0;i8;i+)scl=1;delay1();temp=1;temp|=sda;scl=0;delay1();return temp;void write_add(uchar add,uchar date)/指定地址写数据start();write_byterom(0xa0);respons();write_byterom(add);respons();write_byterom(date);respons();stop();uchar read_add(ucha

11、r add)/指定地址读数据uchar temp;start();write_byterom(0xa0);respons();write_byterom(add);respons();start();write_byterom(0xa1);respons();temp=read_byterom();stop();return temp;/* ds18b20部分*/sbit DQ=P35;void delay2(uchar i)while(i-);void init_ds18b20()/初始化ds18b20uchar i;DQ=1;delay2(8);DQ=0;delay2(80);DQ=1;w

12、hile(DQ=1&i255) i+;delay2(35);delay2(20);void write_byte(uchar dat)/向ds18b20中写一字节uchar i;for(i=0;i=1;delay2(4);uchar read_byte()/从ds18b20中读一字节uchar i,dat=0;for(i=0;i=1;DQ=1;if(DQ)dat=dat|0X80;delay2(4);return dat;uchar read_temp() /读温度函数uchar a,b,c;init_ds18b20();write_byte(0xcc);write_byte(0x44);in

13、it_ds18b20();write_byte(0xcc);write_byte(0xbe);a=read_byte();b=read_byte();c=(b4);return c;uchar read_th()/读上限函数uchar a,b,c;init_ds18b20();write_byte(0xcc);write_byte(0x44);init_ds18b20();write_byte(0xcc);write_byte(0xbe);a=read_byte();b=read_byte();c=read_byte();return c;uchar read_tl()/读下限函数uchar

14、a,b,c;init_ds18b20();write_byte(0xcc);write_byte(0x44);init_ds18b20();write_byte(0xcc);write_byte(0xbe);a=read_byte();b=read_byte();a=read_byte();c=read_byte();return c;/* 键盘部分(P20P23)*/void keyscan()uchar temp,num1,num2;temp=P2;temp&=0x0f;if(temp!=0x0f) /消抖delay(5);if(temp!=0x0f)temp=P2;temp&=0x0f;

15、if(temp=0x0e)num1=1;write_ds(0x8e,0x00); write_ds(0x80,s|0x80);/禁止写保护while(temp=0x0e)/松手检测temp=P2;temp&=0x0f;while(1)temp=P2;temp&=0x0f;if(temp=0x0e) delay(5);temp=P2;temp&=0x0f;if(temp=0x0e)num1+;while(temp=0x0e)/松手检测temp=P2;temp&=0x0f;if(num1=1)write_com(0x80+0x40+0x08);write_com(0x0f);/光标闪烁temp=P

16、2;temp&=0x0f;if(temp=0x0d)delay(5);if(temp=0x0d)while(temp=0x0d)/松手检测temp=P2;temp&=0x0f;s=read_ds(0x81);s1=s/16;s2=s%16;s2+=1;if(s2=10)s2=0;s1+=1;if(s1=6) s1=0;write_com(0x80+0x40+0x07);write_date(table2s1);write_date(table2s2);write_ds(0x80,s1*16+s2);/向ds1302中写入秒else if(temp=0x0b)delay(5);if(temp=0

17、x0b)while(temp=0x0b)/松手检测temp=P2;temp&=0x0f;s=read_ds(0x81);/读ds1302秒 s1=s/16;s2=s%16;s2-=1;if(s2=-1)s2=9;s1-=1;if(s1=-1) s1=5;write_com(0x80+0x40+0x07);write_date(table2s1);write_date(table2s2);write_ds(0x80,s1*16+s2);if(num1=2)write_com(0x80+0x40+0x05);write_com(0x0f);temp=P2;temp&=0x0f;if(temp=0x0d)delay(5);if(temp=0x0d)while(temp=0x0d)/松手检测temp=P2;temp&=0x0f;m=read_ds(0x83);/从ds1302中读分 m1=m/16;m2=m%16;m2+=1;if(m2=10)m2=0;m1+=

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1