欢迎来到天天文库
浏览记录
ID:38662311
大小:49.50 KB
页数:4页
时间:2019-06-17
《多路温度采集系统程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
主机程序#includesbitRS=P2^5;sbitRW=P2^6;sbitEN=P2^7;sbitE=P2^3;voidmaster(void);unsignedcharcort=0;unsignedchartable1[]="111111";unsignedchartable2[]="111111";unsignedchartable3[]="111111";unsignedchartable4[]="111111";unsignedcharnum=0;Delay(unsignedinti){while(i--);}voiddelay_50us(unsignedintt){unsignedintj;for(;t>0;t--)for(j=19;j>0;j--);}voidwrite_com(unsignedcharcom){EN=0;RS=0;RW=0;P1=com;delay_50us(10);EN=1;delay_50us(20);EN=0;}voidwrite_data(unsignedchardat){EN=0;RS=1;RW=0;P1=dat;delay_50us(10);EN=1;delay_50us(20);EN=0;}voidinit_1602(void){delay_50us(300);write_com(0x38);delay_50us(100);write_com(0x38);delay_50us(100);write_com(0x38);write_com(0x08);write_com(0x01);write_com(0x06);write_com(0x0c);}voidmain(){unsignedcharj;unsignedchari;unsignedchark;unsignedchart;TMOD=0x20;TH1=0xcc;//波特率600TL1=0xcc;TR1=1;SCON=0xf8;EA=1;PCON=0x00;EX0=1;//外部中断0允许IT0=1;//外部中断0下降沿触发E=1;init_1602();delay_50us(2);while(1){//从机一// write_com(0x81);for(j=0;j<6;j++){write_data(table2[j]);}Delay(200);if(cort==1){SBUF=0X01;while(TI!=1);TI=0;E=0;SM2=0;Delay(2000);for(num=0;num<6;num++){while(RI!=1);RI=0;table2[num]=SBUF;}SM2=1;E=1;}//从机二//write_com(0x80+0X41);for(i=0;i<6;i++){write_data(table1[i]);}Delay(2000);if(cort==2){SBUF=0X02;while(TI!=1);TI=0;E=0;SM2=0;Delay(200);for(num=0;num<6;num++){while(RI!=1);RI=0;table1[num]=SBUF;}SM2=1;E=1;}//从机三//write_com(0x89);for(k=0;k<6;k++){write_data(table3[k]);}Delay(2000);if(cort==3){SBUF=0X03;while(TI!=1);TI=0;E=0;SM2=0;Delay(200);for(num=0;num<6;num++){while(RI!=1);RI=0;table3[num]=SBUF;}SM2=1;E=1;}//从机四//write_com(0x80+0x49);for(t=0;t<6;t++){write_data(table4[t]);}Delay(2000);if(cort==4){SBUF=0X04;while(TI!=1);TI=0;E=0; SM2=0;Delay(200);for(num=0;num<6;num++){while(RI!=1);RI=0;table4[num]=SBUF;}SM2=1;E=1;cort=0;}}}key_serial()interrupt0using1{++cort;}从机程序#include#defineucharunsignedchar#defineuintunsignedintunsignedcharsend_tem1[]="00.0^C";unsignedcharnum=0;sbitDQ=P3^3;sbitE=P2^3;voiddelay(unsignedintaa){while(aa--);}voidds1820rst(){unsignedcharx=0;DQ=1;delay(4);DQ=0;delay(100);DQ=1;delay(40);}uchards1820rd(){unsignedchari=0;unsignedchardat=0;for(i=8;i>0;i--){DQ=0;dat>>=1;DQ=1;if(DQ)dat|=0x80;delay(10);}return(dat);}voidds1820wr(ucharwdata){unsignedchari=0;for(i=8;i>0;i--){DQ=0;DQ=wdata&0x01;delay(10);DQ=1;wdata>>=1;}}ucharreadtemperature(){uchara,b;ds1820rst();ds1820wr(0xcc);ds1820wr(0x44);delay(20);ds1820rst();ds1820wr(0xcc);ds1820wr(0xbe);a=ds1820rd();b=ds1820rd();b<<=4;b+=(a&0xf0)>>4; returnb;}voidmain(){inttemp;TMOD=0x20;TH1=0xcc;TL1=0xcc;TR1=1;SCON=0xf0;EA=1;ES=1;E=0;PCON=0x00;delay(50000);while(1){delay(200);temp=readtemperature();send_tem1[0]=temp/10+'0';send_tem1[1]=temp%10+'0';}}voidserial(void)interrupt4using1{ES=0;RI=0;if(SBUF==0X01){E=1;SM2=0;for(num=0;num<6;num++){SBUF=send_tem1[num];while(!TI);TI=0;delay(50000);}}SM2=1;ES=1;E=0;}
此文档下载收益归作者所有
举报原因
联系方式
详细说明
内容无法转码请点击此处