各位大佬,有驱动过ZPH01传感器的么?我用PWM驱动为什么不对呀,大佬们帮忙看一下代码啊,我是直接读取RXD口高电平的时间,再计算PM2.5的,难道这种思路不正确么?代码如下:
- #include "msp.h"
- #include "driverlib.h"
- #include "config.h"
- #include "zph01.h"
- uint16_t tim = 0;
- /**
- * main.c
- */
- void main(void)
- {
- uint16_t r, flag;
- WDT_A_holdTimer(); // stop watchdog timer
- MAP_CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
- MAP_SysTick_enableModule();
- MAP_SysTick_setPeriod(3000);//1ms 计时一次
- MAP_Interrupt_enableSleepOnIsrExit();
- MAP_Interrupt_enableMaster();
- MAP_GPIO_setAsInputPin(GPIO_PORT_P2,GPIO_PIN5);
- {
- if(MAP_GPIO_getInputPinValue(GPIO_PORT_P2,GPIO_PIN5) == 1 )
- {
- MAP_SysTick_enableInterrupt();
- while(P2IN & BIT5 ){}
- MAP_SysTick_disableInterrupt();
- flag = 1;
- }
- if(flag == 1)
- {
- r = (1000-tim)/tim * 1000;
- flag = 0;tim = 0;
- }
- }
- }
- void SysTick_Handler(void)
- {//1ms
- tim = tim + 1;
- }