文档详情

第4章 深入分析流水灯例程.ppt

发布:2017-05-24约1.66万字共59页下载文档
文本预览下载声明
* 嵌入式系统原理与应用 * void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) { /* Check the parameters */ assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); assert_param(IS_GPIO_PIN(GPIO_Pin)); GPIOx-BSRR = GPIO_Pin; } stm32f10x_conf.h文件中可以看到实际上assert_param是一个宏定义,它的作用就是检测传递给函数的参数是否是有效的参数。 GPIO_SetBits实现 1. #ifndef __LED_H 2. #define __LED_H 4. #include stm32f10x.h 5. 10. #define ON 0 11. #define OFF 1 12. 14. #define LED1(a) if (a) \ 15. GPIO_SetBits(GPIOC,GPIO_Pin_3);\ 16. else \ 17. GPIO_ResetBits(GPIOC,GPIO_Pin_3) 24. #define LED3(a) if (a) \ 25. GPIO_SetBits(GPIOC,GPIO_Pin_5);\ 26. else \ 27. GPIO_ResetBits(GPIOC,GPIO_Pin_5) 31. #endif /* __LED_H */ 4.5.8 led.h文件 4.5.9 main文件 #include stm32f10x.h #include led.h void Delay(__IO u32 nCount); 22. int main(void) 23. { 25. LED_GPIO_Config( ); /* LED 端口初始化 */ 26. 27. while (1) 28. { 29. LED1( ON ); // 亮 30. Delay(0x0FFFEF); 31. LED1( OFF ); // 灭 32. 37. LED3( ON ); 38. Delay(0x0FFFEF); 39. LED3( OFF ); 40. } 41. } 43. void Delay(__IO u32 nCount) //简单的延时函数 44. { 45. for(; nCount != 0; nCount--); 46. } * 嵌入式系统原理与应用 * GPIO的使用步骤 给相应GPIO端口时钟信号 RCC_APB2PeriphClockCmd(RCC_APB2_Periph_GPIOx,ENABLE) 初始化相应端口 工作模式?工作速度? 读取或设置相应IO端口 读取输入引脚 设置输出引脚 4.6.1 规范的位操作方法 1、将char型变量 a的第七位(bit6)清 0,其它位不变 a = ~(16); 2、将变量 a的第七位(bit6)置 1,其它位不变 a |= (16); 3、将变量a的第七位(bit6)取反,其它位不变 a ^=(16); * 嵌入式系统原理与应用 * 4.7 开发步骤总结 1)为控制LED灯,知道要使用GPIO外设。 2)了解GPIO外设有什么功能,要如何使用。 3)获知GPIO的地址映射,知道它所挂载的总线APB2。 4)了解ST官方库对寄存器的封装。 5)了解时钟树,査看GPIOC的时钟来源,即PCLK2。 6)stm32f10x_conf.h包含用到的头文件stm32f10x_gpio.h、stm32f10x_rcc.h。 7)在工程模板的基础
显示全部
相似文档