完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好,我正努力让DH11工作正常。我在代码中尽可能多地固定,但是我一直都有奇偶校验错误,我尝试从在线代码中遵循不同的风格,我也从以前的NEC解码策略中得到了很多。但是这里我需要一些帮助。它提到了传感器需要一个上拉电阻,但是我读了一个SMD的传感器,所以我没有连接任何一个,即使我连接了一个,结果也不会有太大的变化。这是我的代码:这是一个读取每一个8位数据:这是主要功能:注:我是Coun。tiN奇偶错误部分,因为我一直都有错误,函数返回1。
以上来自于百度翻译 以下为原文 Hello, I'm trying to get the DH11 working precisely. I fixed as much as I could in the code, but I still get parity error all the time. I tried to follow different styles from online codes, I also got a lot from my previous NEC decoding strategy. But here I need some help. It's mentioned that the sensor need a pull-up resistor but I read the breakout sensor has an SMD one, so I'm not connecting any, even if I connect one the result doesn't change much. Here's my code: This one to read each 8-bits data: uint8_t DH11_read_8bits(void) { DH11_code = 0; for (i=7;i>=0;i--) { while(!PORTDbits.RD1); // wait for 0 leading bit TMR2 = 0; while(PORTDbits.RD1); // high bit 0 or 1 TMR2_temp = TMR2; if((TMR2_temp < 40) && (TMR2_temp > 20))// 0 bit is 26-28us DH11_code &= ~(1<<(i)); else DH11_code |= (1<<(i)); } return DH11_code; } This is the main function: Note: I'm commenting the parity error part because I get error all the time and the function returns 1. uint8_t DH11_read(void) { TRISDbits.RD1=0; LATDbits.LATD1=0; __delay_ms(18); // user 18ms low LATDbits.LATD1=1; __delay_us(40); // user 40us high TRISDbits.RD1=1; while(!PORTDbits.RD1);// sensor response 80us low while(PORTDbits.RD1);// sensor response 80us high HumHigh = DH11_read_8bits(); HumDeci = DH11_read_8bits(); TempHigh = DH11_read_8bits(); TempDeci = DH11_read_8bits(); parity_sum = DH11_read_8bits(); parity_check = HumHigh+HumDeci+TempHigh+TempDeci; /*if (parity_check != parity_sum) { LCD_string("parity error"); __delay_ms(500); sendCMD(clear_display); return 1; }*/ LCD_string("Humi: "); move_cursor(1,6); sprintf(val_arr,"%.2d",HumHigh); LCD_string(val_arr); move_cursor(1,8); sprintf(val_arr,".%.2d",HumDeci); LCD_string(val_arr); LCD_string("%"); move_cursor(2,0); LCD_string("Temp: "); move_cursor(2,6); sprintf(val_arr,"%.2d",TempHigh); LCD_string(val_arr); move_cursor(2,8); sprintf(val_arr,".%.2d",TempDeci); LCD_string(val_arr); move_cursor(2,11);sendData(0xDF); move_cursor(2,12);sendData(0x43); move_cursor(2,13); __delay_ms(1000); sendCMD(clear_display); } |
|
相关推荐
4个回答
|
|
我对这一点代码有点怀疑。当数据表说要把它放低时,你会驱动RD1高,然后你提高TrISD1让PIN浮动,然后立即做一次测试,看看它是否低。没有延迟,第一个测试总是直接下降到SECO。你写了这个代码,还是从某个图书馆拿走的?
以上来自于百度翻译 以下为原文 I am a bit suspicious of this bit of code. __delay_ms(18); // user 18ms low LATDbits.LATD1=1; __delay_us(40); // user 40us high TRISDbits.RD1=1; while(!PORTDbits.RD1);// sensor response 80us low while(PORTDbits.RD1);// sensor response 80us high You drive RD1 high for 18ms, when the datasheet says to drive it low. You then raise TRISD1 to let the pin float, then immediately do a while test to see if it is low. Without a delay there, that first test is always going to fall straight through to the second while. Did you write this code, or is it taken from some library? |
|
|
|
这实际上是在18MS延迟之前驱动引脚低,然后高40s。1的指令。配置RD1 OutPuts2。驱动引脚低18MS3。把它开高40s。配置RD1作为接收传感器响应的输入,并遵循40位数据
以上来自于百度翻译 以下为原文 It's actually the instruction before the 18ms delay which drives the pin low, then high for 40us. 1. Configure RD1 output 2. Drive the pin low 18ms 3. Drive it high 40us 4. Configure RD1 as input for receiving the sensor response and following 40-bits data TRISDbits.RD1=0; LATDbits.LATD1=0; __delay_ms(18); // user 18ms low LATDbits.LATD1=1; __delay_us(40); // user 40us high TRISDbits.RD1=1; |
|
|
|
道歉,在我第一天的咖啡前发表!正如你所说的,你的18Ms低是正确的。我仍然怀疑最后两个指令。正如我提到的,在浮动RD1之后直接进入第一个WHER()循环。PIN仍然是高的,所以while条件将是假的,所以它将直接通过该循环。它看到一个低电平,这将发生在“DHT响应和拉低”脉冲开始在你的图表。这意味着你将进入你的“DH11AdvRe8BIT”功能有点太早。
以上来自于百度翻译 以下为原文 Apologies, posted before my first coffee for the day! ;) As you say, your 18ms low is correct. I'm still suspicious of the last two instructions. TRISDbits.RD1=1; while(!PORTDbits.RD1);// sensor response 80us low As I mentioned fall into the first while() loop straight after floating RD1. The pin will still be high, so the while condition will be false, so it will fall straight through that loop. while(PORTDbits.RD1);// sensor response 80us high This loop will exit when it sees a low, which will happen at the start of the "DHT responds and pulls LOW" pulse in your diagram. That means you will enter your "DH11_read_8bits" function one bit too early. |
|
|
|
嗯,这是我今天做的第二个自制卡布奇诺杯,所以我知道你在说什么:对不起,我计划描述所有关于我的设置的细节。这个引脚被传感器拉高了,就像红外接收器一样,但不是在低脉冲期间接收数据,而是在高P。ULSE和低脉冲领先0位,你知道吗?我甚至不认为拉针后再拉高18Ms是必要的,因为销已经被传感器拉高了。在18MS之后,传感器应该通过将引脚拉低到80US然后再高到80s来响应。因此,第一次循环测试低状态是:对于低80US,下一个循环测试时,高状态是高80US。根据该图,在低/高80US响应之后。其中包括2个低/高while循环测试。数据接收的开始是通过为80US拉低PIN,这就是我在40位函数“DH11A Read 8BIT”中所做的测试。我不知道这一点,也许我正陷入这个错误!
以上来自于百度翻译 以下为原文 Well, it's my 2nd home made cappuccino cup for today, so I know what are you talking about :) Sorry, I planned to describe all the necessary details about my setup. The pin is pulled HIGH by the sensor, it's like the IR receiver, but instead of receiving data during the LOW pulses, it's in the HIGH pulses and the LOW pulses are leading 0 bits. You know what? I even don't think it's necessary to pull the pin HIGH again after pulling it LOW for 18ms, because the pin is already pulled HIGH by the sensor. After the 18ms, the sensor should respond by pulling the pin LOW for 80us and then HIGH for another 80us. So, the first while loop testing the LOW state is for the LOW 80us. The next while loop testing the HIGH state is for the HIGH 80us. According to the diagram, after the LOW/HIGH 80us response. Which I included the 2 LOW/HIGH while loops tests for. The start of the data receiving is by pulling the pin LOW for 80us, and this is what I'm testing in the 40-bits function "DH11_read_8bits". I don't know about this point, maybe I'm falling into this mistake! |
|
|
|
只有小组成员才能发言,加入小组>>
5209 浏览 9 评论
2017 浏览 8 评论
1943 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3189 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2244 浏览 5 评论
758浏览 1评论
646浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
564浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
657浏览 0评论
556浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-10 05:53 , Processed in 1.136173 second(s), Total 49, Slave 42 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号