#include "pub.h"
#include "sys
tick.h"
u32 aaw;
int main()
{
GPIO_InitTypeDef GPIO_InitStructure;
SystemInit(); //??????
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA,&GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_SetBits(GPIOC,GPIO_Pin_0);
while(1)
{
while(!(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)));
aaw=1;
}
}
无法读取io口的值,
仿真aaw一直是0;io口接了一个红外对管
1. SystemInit();不用在这里再初始化一下,因为这个函数在启动文件(.s)中已经初始化了
2.对IO口的初始化最好打包成一个函数,如:void GPIO_Config(void)等,你这样放在main里面太难看了
3.你设置PA0为浮空输入,它的初始电平可能是1也可能是0,你这句while(!(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0))); 如果它的初始状态为0,就死在这里了,所以aaw的 值不会改变
一周热门 更多>