手在前面晃,只能输出低电平,无法拉高IO
#include "stm32f4xx.h"
#include "led.h"
#include "delay.h"
//#include "beep.h"
#include "usart.h"
int main(void)
{
delay_init(156);
uart_init(115200);
// beep_Init();
LED_Init();
while(1)
{
if(L_XHG==1)
{
LED=0;
printf("true\r\n");
}
if(L_XHG==0)
{
LED=1;
printf("error");
delay_ms(100);
}
}
}
#include "led.h"
#include "stm32f4xx.h"
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_Initstrtype;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
GPIO_Initstrtype.GPIO_Mode=GPIO_Mode_OUT;
GPIO_Initstrtype.GPIO_OType=GPIO_OType_PP;
GPIO_Initstrtype.GPIO_Pin=GPIO_Pin_9;
GPIO_Initstrtype.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_Initstrtype.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(GPIOF,&GPIO_Initstrtype);
GPIO_Initstrtype.GPIO_Mode=GPIO_Mode_IN;
GPIO_Initstrtype.GPIO_Pin=GPIO_Pin_0;
GPIO_Initstrtype.GPIO_PuPd=GPIO_PuPd_DOWN;
GPIO_Initstrtype.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(GPIOA,&GPIO_Initstrtype);
}
#ifndef __LED_H
#define __LED_H
#define L_XHG PAin(0)
#define LED PFout(9)
void LED_Init(void);
#endif