查看: 3352|回复: 0

【望月追忆】带你入门STM32F0之二:点亮你的小灯

[复制链接]
发表于 2012-11-29 10:38:00 | 显示全部楼层 |阅读模式
分享到:
【望月追忆】带你入门STM32F0之二:点亮你的小灯
端口初始化:
  1. void LedInit(void)
  2. {
  3.         /* GPIOC Periph clock enable */
  4.   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

  5.   /* Configure PC8 and PC9 in output pushpull mode */
  6.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
  7.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  8.   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  9.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  10.   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  11.   GPIO_Init(GPIOC, &GPIO_InitStructure);
  12. }
复制代码
设置端口高低电平  使用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
  */
  1. GPIO_WriteBit(GPIOA, GPIO_Pin_11, 0);
  2. GPIO_WriteBit(GPIOA, GPIO_Pin_11, 1);
复制代码
延时函数
  1. void delay()
  2. {
  3.         int i,j;
  4.   for(i=0;i<1000;i++)
  5.           {
  6.                         for(j=0;j<1000;j++);
  7.                 }
  8. }
复制代码
这只是个粗略的延时,下个教程使用准确延时。
回复

使用道具 举报

关闭

站长推荐上一条 /2 下一条



手机版|小黑屋|与非网

GMT+8, 2024-5-4 12:07 , Processed in 0.098685 second(s), 13 queries , MemCache On.

ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

苏公网安备 32059002001037号

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.