NRF905发射温度(2022年)

时间:2022-08-15 13:10:03 浏览量:

下面是小编为大家整理的NRF905发射温度(2022年),供大家参考。

NRF905发射温度(2022年)

 

  #include<reg51.h> #include<ABSACC.h> #include<stdio.h> #include<intrins.h> #defineGPIO_DIGP0//‐‐定义使用的 IO‐‐ #defineuint unsignedint #defineucharunsignedchar sbitLSA=P2^2; sbitLSB=P2^3; //‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐数码管显示‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐// unsignedcharcodeDIG_CODE[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//0、1、2、3、4、5、6、7、8、9、A、b、C、d、E、F 的显示码unsignedcharDisplayData[3];//用来存放要显示的 4 位数的值 voidDigDisplay(){ unsignedchari; unsignedintj; for(i=0;i<4;i++) { switch(i) //位选,选择点亮的数码管, { case(0): LSA=0;LSB=0;break;//显示第 0 位 case(1): LSA=1;LSB=0;break;//显示第 1 位 case(2): LSA=0;LSB=1;break;//显示第 2 位 case(3): LSA=1;LSB=1;break;//显示第 3 位 } GPIO_DIG=DisplayData[i];//发送段码 j=50; //扫描间隔时间设定 while(j‐‐); GPIO_DIG=0x00;//消隐 }} voidLcdDisplay(inttemp) //lcd 显示{ floattp; tp=temp;//因为数据处理有小数点所以将温度赋给一个浮点型变量 //如果温度是正的那么,那么正数的原码就是补码它本身

  temp=tp*0.0625*100+0.5; //留两个小数点就*100,+0.5 是四舍五入,因为 C 语言浮点数转换为整型的时候把小数点 //后面的数自动去掉,不管是否大于 0.5,而+0.5 之后大于 0.5 的就是进 1 了,小于 0.5 的就 //算加上 0.5,还是在小数点后面。 DisplayData[0]=DIG_CODE[temp/1000]; DisplayData[1]=DIG_CODE[temp%1000/100]|0x80; DisplayData[2]=DIG_CODE[temp%100/10]; DisplayData[3]=DIG_CODE[temp%10]; DigDisplay(); //扫描显示}//‐‐‐‐‐‐‐‐‐‐‐‐‐键盘显示‐‐‐‐‐‐‐‐‐‐‐//sbitP24=P2^4;//确定sbitP25=P2^5;//加 1sbitP26=P2^6;//减 1//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐DS18B20‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐//sbitDSPORT=P3^7;voidDelay1ms(uinty){ uintx; for(;y>0;y‐‐) { for(x=110;x>0;x‐‐); }}ucharDs18b20Init(){ uchari; DSPORT=0; //将总线拉低 480us~960us i=70; while(i‐‐);//延时 642us DSPORT=1; //然后拉高总线,如果 DS18B20 做出反应会将在 15us~60us 后总线拉低 i=0; while(DSPORT) //等待 DS18B20 拉低总线 { Delay1ms(1); i++; if(i>5)//等待>5MS { return0;//初始化失败 }

  } return1;//初始化成功}voidDs18b20WriteByte(uchardat){ uinti,j; for(j=0;j<8;j++) { DSPORT=0; //每写入一位数据之前先把总线拉低 1us i++; DSPORT=dat&0x01; //然后写入一个数据,从最低位开始 i=6; while(i‐‐);//延时 68us,持续时间最少 60us DSPORT=1; //然后释放总线,至少 1us 给总线恢复时间才能接着写入第二个数值 dat>>=1; }}ucharDs18b20ReadByte(){ ucharbyte,bi; uinti,j; for(j=8;j>0;j‐‐) { DSPORT=0;//先将总线拉低 1us i++; DSPORT=1;//然后释放总线 i++; i++;//延时 6us 等待数据稳定 bi=DSPORT; //读取数据,从最低位开始读取 /*将 byte 左移一位,然后与上右移 7 位后的 bi,注意移动之后移掉那位补 0。*/ byte=(byte>>1)|(bi<<7); i=4; //读取完之后等待 48us 再接着读取下一个数 while(i‐‐); } returnbyte;}void Ds18b20ChangTemp(){ Ds18b20Init(); Delay1ms(1); Ds18b20WriteByte(0xcc); //跳过 ROM 操作命令 Ds18b20WriteByte(0x44); //温度转换命令

 // Delay1ms(100); //等待转换成功,而如果你是一直刷着的话,就不用这个延时了 } void Ds18b20ReadTempCom(){ Ds18b20Init(); Delay1ms(1); Ds18b20WriteByte(0xcc); //跳过 ROM 操作命令 Ds18b20WriteByte(0xbe); //发送读取温度命令} intDs18b20ReadTemp(){ inttemp=0; uchartmh,tml; Ds18b20ChangTemp(); //先写入转换命令 Ds18b20ReadTempCom(); //然后等待转换完后发送读取温度命令 tml=Ds18b20ReadByte(); //读取温度值共 16 位,先读低字节 tmh=Ds18b20ReadByte(); //再读高字节 temp=tmh; temp<<=8; temp|=tml; returntemp;}//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ISD1760‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐////‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐报警模块‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐//sbitBeep= P1^5; //unsignedcharn=0; //n 为节拍常数变量 //unsignedcharcodemusic_tab[]={ voiddelay2(unsignedinti){ charj; for(i;i>0;i‐‐) for(j=200;j>0;j‐‐);}voidacction(){ Beep=1; delay2(5); Beep=0; delay2(5); } //*******************定义命令字**********************#defineWC0x00 //Writeconfigurationregistercommand#defineRC0x10 //Read configurationregistercommand

 #defineWTP0x20 //WriteTXPayload command#defineRTP0x21 //Read TXPayload command#defineWTA0x22 //WriteTXAddress command#defineRTA0x23//*******************管脚配置*********sbitMOSI=P1^6;sbitCSN=P1^7;sbitSCK=P1^0;sbitMISO=P1^1;sbitTRX_CE=P1^2;sbitTXEN=P1^3;sbitPWR=P1^4;sbitDR=P2^0;ucharTxbuf[4];ucharRfconfig[10]={0x4c,0x0e,0x44,0x04,0x04,0xe7,0xe7,0xe7,0xe7,0xde};//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐voiddelay(uintx){ uinti; for(i=0;i<x;i++) { _nop_(); }}//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐voidSpiwrite(uchardat){ uchari=8; while(i‐‐) { delay(10); SCK=0; MOSI=(bit)(dat&0x80); dat<<=1; delay(10); SCK=1; delay(10); SCK=0; } SCK=0;}//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐voidTxpacket(void)

 { TXEN=1; TRX_CE=1; CSN=0; Spiwrite(0x22); Spiwrite(0xe7); Spiwrite(0xe7); Spiwrite(0xe7); Spiwrite(0xe7); CSN=1; _nop_();_nop_(); CSN=0; Spiwrite(0x20); Spiwrite(Txbuf[0]); Spiwrite(Txbuf[1]); Spiwrite(Txbuf[2]); Spiwrite(Txbuf[3]); CSN=1; _nop_();_nop_(); delay(50); while(!DR); TRX_CE=0;}//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐voidini_system(void){ uchari; CSN=1; SCK=0; PWR=1; // PWR_UP |TRX_CE|TXEN|MODE TRX_CE=0; //1 | 0 | 0|SPIProgramming TXEN=0; _nop_(); CSN=0; Spiwrite(0x00); for(i=0;i<10;i++) { Spiwrite(Rfconfig[i]); } CSN=1;}//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐voidsetmode()

 { PWR=1; // PWR_UP TRX_CE TXEN MODE TRX_CE=1;// 1 1 1SHOCKBURSTTX TXEN=1; delay(1000);//timemustbe>=650us}//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐bitq;sbitP21=P2^1;voidmain(){ inttemp,temp1,m=0; floattp; ini_system(); m=0;q=0; while(1) { temp=Ds18b20ReadTemp()+m; tp=temp; temp1=tp*0.0625*100+0.5; if(P24==0){q=1;while(P24==0);} if(q==1){ while(q==1){ temp=Ds18b20ReadTemp(); if(P25==0){m++;while(P25==0);} if(P26==0){m‐‐;while(P26==0);} temp=temp+m; tp=temp;//因为数据处理有小数点所以将温度赋给一个浮点型变量 temp1=tp*0.0625*100+0.5; DisplayData[0]=DIG_CODE[temp1/1000]; DisplayData[1]=DIG_CODE[temp1%1000/100]|0x80; DisplayData[2]=DIG_CODE[temp1%100/10]; DisplayData[3]=DIG_CODE[temp1%10]; DigDisplay(); //扫描显示 if(P24==0)q=0; while(P24==0); if(temp1>=3500) acction(); if(temp1<=2500) acction(); } } if(q==0)LcdDisplay(temp);

  if(temp1>=3500) acction(); if(temp1<=2500) acction(); while(P21==0){ setmode(); Txbuf[0]=temp1/1000; Txbuf[1]=temp1%1000/100; Txbuf[2]=temp1%100/10; Txbuf[3]=temp1%10; Txpacket(); LcdDisplay(temp); if(temp1>=3500) acction(); if(temp1<=2500) acction(); } }}

推荐访问:NRF905发射温度 发射 温度 NRF905