.H文件中定义结构体如下
typedef struct {
float Distance; /*!< 用厘米测量传感器的距离*/
GPIO_TypeDef* ECHO_GPIOx; /*!< 指向用于 ECHO port /
uint16_t ECHO_GPIO_Pin; /!< ECHO Pin /
GPIO_TypeDef TRIGGER_GPIOx; /*!< 指向用于 TRIGGER port /
uint16_t TRIGGER_GPIO_Pin; /!< TRIG Pin */
} TM_HCSR04_t; 函数申明如下:
uint8_t HCSR04_Init( TM_HCSR04_t *HCSR04 , GPIO_TypeDef ECHO_GPIOx, uint16_t ECHO_GPIO_Pin, GPIO_TypeDef* TRIGGER_GPIOx, uint16_t TRIGGER_GPIO_Pin); float HCSR04_Read(TM_HCSR04_t *HCSR04); 主函数如下:
int main(void)
{
float result=0;
TM_HCSR04_t *HCSR04_1; //定义结构体指针
HCSR04_Init(HCSR04_1,echo_gpio,echo_pin,trig_gpio,trig_pin);//初始化赋值
for(;;)
{
result=HCSR04_Read( HCSR04_1 ); //读值
printf( "length is %f",result );
}
} 编译无错误,就是TM_HCSR04_Init函数中结构体指针作为函数参数无法赋值,如有知晓者,还望不吝赐教,万分感谢
|