您好,欢迎来到筏尚旅游网。
搜索
您的当前位置:首页多路温度采集系统程序

多路温度采集系统程序

来源:筏尚旅游网
主机程序

#include sbit RS=P2^5; sbit RW=P2^6; sbit EN=P2^7; sbit E=P2^3;

void master(void); unsigned char cort=0;

unsigned char table1[]=\"111111\"; unsigned char table2[]=\"111111\"; unsigned char table3[]=\"111111\"; unsigned char table4[]=\"111111\"; unsigned char num=0;

Delay(unsigned int i) {

while(i--); }

void delay_50us(unsigned int t) { unsigned int j; for(;t>0;t--) for(j=19;j>0;j--); }

void write_com(unsigned char com) {

EN=0; RS=0; RW=0; P1=com;

delay_50us(10); EN=1;

delay_50us(20); EN=0; }

void write_data(unsigned char dat) {

EN=0; RS=1; RW=0; P1=dat;

delay_50us(10); EN=1;

delay_50us(20); EN=0; }

void init_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); }

void main() {

unsigned char j; unsigned char i;

unsigned char k; unsigned char t; TMOD=0x20;

TH1=0xcc;//波特率600 TL1=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;

}

SM2=1; E=1; } //从机三//

write_com(0x); 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;

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() interrupt 0 using 1 {

++cort; }

从机程序

#include

#define uchar unsigned char #define uint unsigned int

unsigned char send_tem1[]=\"00.0^C\"; unsigned char num=0; sbit DQ=P3^3; sbit E=P2^3;

void delay(unsigned int aa) {

while(aa--); }

void ds1820rst() {

unsigned char x=0; DQ=1;

delay(4);

DQ=0; delay(100);

DQ=1; delay(40); }

uchar ds1820rd() { unsigned char i=0; unsigned char dat=0; for (i=8;i>0;i--) { DQ = 0; dat>>=1; DQ = 1; if(DQ) dat|=0x80; delay(10); }

return(dat); }

void ds1820wr(uchar wdata) {unsigned char i=0; for (i=8; i>0; i--) { DQ = 0;

DQ = wdata&0x01; delay(10); DQ = 1; wdata>>=1; } }

uchar readtemperature() {

uchar a,b;

ds1820rst(); ds1820wr(0xcc); ds1820wr(0x44); delay(20);

ds1820rst(); ds1820wr(0xcc); ds1820wr(0xbe); a=ds1820rd(); b=ds1820rd(); b<<=4;

b+=(a&0xf0)>>4; return b; }

void main() {int temp;

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'; } }

void serial(void) interrupt 4 using 1 {

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; }

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- efsc.cn 版权所有 赣ICP备2024042792号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务