stm32:CT117E之LED篇

来源:互联网 发布:淘宝禁售商品有哪些 编辑:程序博客网 时间:2024/05/21 10:00
这里还是先附上大神师兄对led的分析以及寄存器代码http://blog.csdn.net/ieczw/article/details/15446847接下来是我的库程序:
<pre name="code" class="plain">//led.c #include"led.h"int LED_Conf(){GPIO_InitTypeDef GPIO_InitStructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All ;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_Init(GPIOC,&GPIO_InitStructure);GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2;GPIO_Init(GPIOD,&GPIO_InitStructure);   GPIO_SetBits(GPIOC,GPIO_Pin_All) ;GPIO_ResetBits(GPIOD,GPIO_Pin_2);//给锁存器一个脉冲    GPIO_SetBits(GPIOD,GPIO_Pin_2);return 0; }int  LED_On(u16 led,uint8_t state)//控制led亮和灭{if(state == 1){GPIO_ResetBits(GPIOC,led);GPIO_ResetBits(GPIOD,GPIO_Pin_2);GPIO_SetBits(GPIOD,GPIO_Pin_2);}if(state == 0){GPIO_SetBits(GPIOC,led);GPIO_ResetBits(GPIOD,GPIO_Pin_2);GPIO_SetBits(GPIOD,GPIO_Pin_2);}return 0;}//led.h#ifndef _LED_H_#define _LED_H_#include"stm32f10x.h"#include"stm32f10x_gpio.h"#include"stm32f10x_rcc.h"#include"misc.h"#define LED1 GPIO_Pin_8#define LED2 GPIO_Pin_9#define LED3 GPIO_Pin_10#define LED4 GPIO_Pin_11#define LED5 GPIO_Pin_12#define LED6 GPIO_Pin_13#define LED7 GPIO_Pin_14#define LED8 GPIO_Pin_15extern int LED_Conf(void);extern int  LED_On(uint16_t led,uint8_t state);#endif//main.c#include"stm32f10x.h"#include"led.h"void Delay(u32 Count);int main(){   LED_Conf();while(1){  LED_On(LED1,1);    Delay(0x0Fffff);LED_On(LED1,0); }}void Delay(u32 Count){for(; Count!=0; Count--);}



这是一个led闪烁的程序,这里就是一些gpio的基本配置没什么可说的,唯一需要注意的就是这块板子上加了一锁存器,所以在PD.4需要给他一个脉冲。还有就是尽量一个模块分为C文件和H文件写,之后一些比较多的模块也方便自己调试。

                                             
0 0
原创粉丝点击