之前申请过STM32F05Discovery套件,做过一些实验,虽然第一次接触STM32单片机,感觉非常好用,项目里现在已经在用STM32F051替代NXP的M0,这个是DHT11温湿度采集的例程,因为有外设库,配置起来还是比较容易的。 #include uint8_t buf[4]={0x00,0x00,0x00,0x00}; uint8_t crc; GPIO_TypeDef* dht11Port = GPIOA; const uint16_t dht11Pin = GPIO_Pin_10; const uint32_t dht11Clock = RCC_AHBPeriph_GPIOA; void Dht11SetPinIn(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = dht11Pin ; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_Init(dht11Port,&GPIO_InitStructure); } void Dht11SetPinOut(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = dht11Pin ; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_Init(dht11Port,&GPIO_InitStructure); } unsigned char Dht11Start(void) { Dht11SetPinOut(); GPIO_ResetBits(dht11Port,dht11Pin); Delay_ms(20); GPIO_SetBits(dht11Port,dht11Pin); Delay_5us(4); Dht11SetPinIn(); Delay_5us(1); if(!GPIO_ReadInputDataBit(dht11Port,dht11Pin)) { while(!GPIO_ReadInputDataBit(dht11Port,dht11Pin)); while(GPIO_ReadInputDataBit(dht11Port,dht11Pin)); return 1; } return 0; } uint8_t Dht11ReadByte(void) { uint8_t i; uint8_t buf=0; for(i = 0;i |
楼主可以加个好友探讨一下吗 最近需要这个代码 |
挺好的,恭喜楼主 |
【STM32F0开发日志/评测/笔记】+互补PWM波的产生
STM32F030 PB14和PB15无法输出PWM求助
【STM32F030探索套件】序列之五 外部中断
【STM32F0开发日志---二】+ucosii.2.92移植在STM32F030
上传个STM32F0+5110+内部温度传感器的菜鸟实例
【STM32F030探索套件使用问题】STM32F030 SPI方式驱动ST7565LCD失败
求一份STM32F051 I2C驱动LCD 12864的例程
STM32F0 M0 向结构体赋值进入HardFault异常
STM32F0 ADC-DMA方式采集2路数据时出现问题
STM32F030C8T6,TIM16定时慢很多问题?