工具/软件:Code Composer Studio
大家好、
我尝试将 温度/湿度传感器 DHT11与 TM4C123GH6PM 相连。 我成功-温度和湿度正常。 突然,当我再次尝试读取数据时,会出现一些问题。 请不要说“看连接”,因为我检查了很多次。 出现问题是因为传感器在0之后始终为高电平或1。 有 DHT11的人可以尝试我的代码了。 还有一点、我在数据线上使用10k 或5k 上拉电阻器。
还有一个问题:为什么我使用时不能生成代码 ?
#include #include #include //#include include "hw_memmap.h" #include "hw_types.h" #include "hw_gpio.h" #include "debug.h" #include "crc_tctl.h" #include "gpio.h" #include "rom_map.h" #include "包含"rom_prefix.h" #include "nterm.h"#include "包含"ctrab.h" #include "ns"#ctrab.h.h.h"#include "#include "ns"#include "#ctrab.h.h.h.h"#include "#include "#include "#ctrab.h.h"#include "#include "ns"#include "#include "#ctrab.h.h.h.h"#include "#include "#include "ns"#ctrab.h.h.h.h"#include "#include "#include "#include "#ctrab.h.h"#include "#include "#include "ns"# #include "interrupt.h" #include "inttypes.h" #include "lcd.h" #include "iso646.h" #include "lowlev.h" #include "locale.h" #include "muse.h" #include "pinvol.h.h" #include "pin_mh.md.h" #include "#include "md.h"#include "#md.h"#include "timer.h.md.h"#include "#include "#md.h"#include "#md.h"#md.h"#include "timer #md.eh.md.md.eh.md.md.md.eh"#include "#include "#include "#include "#include "#include "#include "#include "#md.eh.md.md.eh"#include "#include "#include "#include "#include "#t.md.h"#t.md.md.h"#include "#include "#t. 无符号长湿度、湿度解甲部分、温度、温度解甲部分、 验证; /******** PA3连接到 DHT11的 DATA 引脚 / //******** 在数据线和 Vcc 之间放置10k 上拉电阻器 / //******** 温度精度介于+-2C 和+-1C 之间 / //******** 温度测量范围0 - 50°C / //******** 湿度精度介于+-4%和+-5%之间 / //******** 湿度测量范围20 - 90% / 无符号长整型转换 BinaryToDecimal (int startBit){ int i = 0; unsigned long convertedNum = 0; for (i = startBit;i <=(startBit + 7);i++){ convertedNum = convertedNum + variable [i]* pow (2、i); } 返回 convertedNum; } void Interrupt_Function_GPIO_PORTF (void){ GPIOIntClear (GPIO_PORTF_BASE、GPIO_INT_PIN_0); GPIOPinWrite (GPIO_Porta_base、GPIO_PIN_3、~GPIO_PIN_3);// PA3上的低电压 SysCtlDelay (302000);// 18.12mS 延迟 GPIOPinWrite (GPIO_Porta_base、GPIO_PIN_3、GPIO_PIN_3);// PA3上的高电压 SysCtlDelay (500);// 500 = 30us GPIOPinTypeGPIOInput (GPIO_Porta_base、GPIO_PIN_3);//输入引脚 PF0和 PF4 GPIOPadConfigSet (GPIO_Porta_base、GPIO_PIN_3、GPIO_Strength _2mA、GPIO_PIN_TYPE_STD_WPU);//上拉电阻、最大2mA while (GPIOPinRead (GPIO_Porta_base、GPIO_PIN_3)=0){}; while (GPIOPinRead (GPIO_Porta_base、GPIO_PIN_3)=GPIO_PIN_3){}; int i; 对于(i = 0;i < 40;i++){ while (GPIOPinRead (GPIO_Porta_base、GPIO_PIN_3)=0){}; SysCtlDelay (450);// 45us = 750 if (GPIOPinRead (GPIO_Porta_base、GPIO_PIN_3)=GPIO_PIN_3){ 可变[i]= 1; while (GPIOPinRead (GPIO_Porta_base、GPIO_PIN_3)== 8){}; }否则{ Variable [i]= 0; } } //SysCtlDelay (50000000);// 1秒延迟 //湿度= ConversionBinaryToDecimal (0); HumidityDecimalPart = ConversionBinaryToDecimal (8); 温度=转换二进制到十进制(16); TemperatureDecimalPart = ConversionBinaryToDecimal (24); 验证=转换二进制到十进制(32); */ } void main (void){ /******** 时钟和使能外设 / SysCtlClockSet (SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHz | SYSCTL_SYSDIV_4);//时钟设置50MHz SysCtlPeripheralEnable (SYSCTL_Periph_GPIOF);//启用 portF SysCtlPeripheralEnable (sysctl_Periph_GPIOA);//启用 Porta /*************** //******** GPIO 配置 / GPIO_PORTF_LOCK_R = GPIO_LOCK_KEY; GPIO_PORTF_CR_R = 0x01; GPIO_PORta_lock_R = GPIO_LOCK_KEY; GPIO_PORta_CR_R = 0x08; GPIOPinTypeGPIOInput (GPIO_PORTF_BASE、GPIO_PIN_0);//输入引脚 PF0 GPIOPadConfigSet (GPIO_PORTF_BASE、GPIO_PIN_0、GPIO_Strength _2mA、GPIO_PIN_TYPE_STD_WPU);//上拉电阻、最大2mA GPIOPinTypeGPIOOutput (GPIO_Porta_base、GPIO_PIN_3);//输出引脚 PA3 GPIOPinWrite (GPIO_Porta_base、GPIO_PIN_3、GPIO_PIN_3);// PA3上的高电压 /********* //******** GPIO 中断配置 / IntMasterEnable(); IntEnable (INT_GPIOF); IntPrioritySet (INT_GPIOF、4); GPIOIntEnable (GPIO_PORTF_BASE、GPIO_INT_PIN_0); GPIOIntTypeSet (GPIO_PORTF_BASE、GPIO_PIN_0、GPIO_FALLING_EDGE); 内部寄存器(INT_GPIOF、Interrupt_Function_GPIO_PORTF); /************* / while (1){ } }