GPIO_Pin = GPIO_Pin_All;//直接用All初始化所有端口 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA,&GPIO_InitStructure); while(1){ //实现LED流水灯,可用循环和移位优化代码,8个等按顺序点亮 //甚至可以定义一个数组依次给第二个参数位置实现花式点灯 GPIO_Write(GPIOA,~0x0001)...
GPIO_Pin:指定需要输出的IO引脚,可以通过位或运算符(|)来同时选择多个引脚。例如,若要使GPIOA的12和13号引脚输出高电平,可以调用以下函数:GPIO_SetBits(GPIOA, GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13);读取输入电平函数 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)...
u16 prescaler){ // GPIO 初始化 GPIO_InitTypeDef GPIO_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure....
GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化KEY12->PC12, KEY11->PC11, KEY10->PC10,设置为输入 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_11|GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOC, &GPIO_InitStructure); //设置KEY12->PC12, KEY11->...
uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx); 再下面跟着的四个就是GPIO的写入函数,这些函数就可以实现读写GPIO口的功能 void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); ...
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;//开漏输出 GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化外设GPIOx寄存器 // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;//SDA // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;//最高输出速率10MHz ...
GPIO_ResetBits(GPIOC, GPIO_Pin_11); Delay(0x8ffff); GPIO_SetBits(GPIOC, GPIO_Pin_12); Delay(0x8ffff); GPIO_ResetBits(GPIOC, GPIO_Pin_12); Delay(0x8ffff); } } 注意:在这里用到了RCC和GPIO的库函数,所以必须把这两个函数加入工程。
GPIO_Pin_11是个宏定义,假设等于00000001(二进制),而GPIO_Pin_12假设等于00000010(二进制),它两个或就等于00000011,判定使用哪些io口时,就是根据这个数的各个位来分析,当最低位为1要用GPIO_Pin_11,第二位为1表示也要用GPIO_Pin_12口。所有是或运算符。
GPIO_InitTypeDef GPIO_InitStructure; //RCC->APB2ENR|=1<<4;//先使能外设IO PORTC时钟 RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE ); //使能GPIOC时钟 //IIC SCL(PC12)IIC SDA(PC11) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_11;//change the channel ...