【望月追忆】带你入门STM32F0之二:点亮你的小灯
 
 
| 
 | 
 
 
【望月追忆】带你入门STM32F0之二:点亮你的小灯 
端口初始化:- void LedInit(void)
 
 - {
 
 -         /* GPIOC Periph clock enable */
 
 -   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
 
  
-   /* Configure PC8 and PC9 in output pushpull mode */
 
 -   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
 
 -   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
 
 -   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
 
 -   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 
 -   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
 -   GPIO_Init(GPIOC, &GPIO_InitStructure);
 
 - }
 
  复制代码 设置端口高低电平  使用GPIO_WriteBit 这个函数  函数原型  
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal) 
固件库函数的说明就很详细 
/** 
  * @brief  Sets or clears the selected data port bit. 
  * @param  GPIOx: where x can be (A, B, C, D or F) to select the GPIO peripheral. 
  * @param  GPIO_Pin: specifies the port bit to be written. 
  * @param  BitVal: specifies the value to be written to the selected bit. 
  *   This parameter can be one of the BitAction enumeration values: 
  *     @arg Bit_RESET: to clear the port pin 
  *     @arg Bit_SET: to set the port pin 
  * @note   The GPIO_Pin parameter can be GPIO_Pin_x where x can be: (0..15) for GPIOA,  
  *         GPIOB or GPIOC,(0..2) for GPIOD and(0..3) for GPIOF.   
  * @retval None 
  */- GPIO_WriteBit(GPIOA, GPIO_Pin_11, 0);
 
 - GPIO_WriteBit(GPIOA, GPIO_Pin_11, 1);
 
  复制代码 延时函数- void delay()
 
 - {
 
 -         int i,j;
 
 -   for(i=0;i<1000;i++)
 
 -           {
 
 -                         for(j=0;j<1000;j++);
 
 -                 }
 
 - }
 
 
  复制代码 这只是个粗略的延时,下个教程使用准确延时。 |   
 
  
  
  
 
 
 | 
| 
 | 
| 
 | 
| 
 | 
 |