stm32:CT117E之LED篇

这里还是先附上大神师兄对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_15

extern 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值