[stm32] LED

 

 1 /****************************************************************************
 2 * 文件名: main.c
 3 * 内容简述:    
 4 *       
 5 *    演示的是3个蓝色LED(LED1-LED3) 轮流闪烁
 6     
 7     定义:    
 8     LED1-LED3 ---V6——V8 
 9     V6----- PB5-LED1
10     V7----- PD6-LED2(仅V2,V2.1 V3板)
11     V8----- PD3-LED3(仅V2,V2.1 V3板)
12     
13     基于MDK版本:        3.8
14     基于官方外设库版本: 3.5
15 *
16 /* Includes ------------------------------------------------------------------*/
17 #include "stm32f10x.h"
18 
19 GPIO_InitTypeDef GPIO_InitStructure;//////////////////////222222222222222222222222
20 #define LED1_ON GPIO_SetBits(GPIOB, GPIO_Pin_5);//////////111111111111111111111111  
21 #define LED1_OFF GPIO_ResetBits(GPIOB,GPIO_Pin_5); 
22 
23 #define LED2_ON GPIO_SetBits(GPIOD, GPIO_Pin_6);  
24 #define LED2_OFF GPIO_ResetBits(GPIOD, GPIO_Pin_6); 
25 
26 #define LED3_ON GPIO_SetBits(GPIOD, GPIO_Pin_3);  
27 #define LED3_OFF GPIO_ResetBits(GPIOD, GPIO_Pin_3);  
28 
29 void RCC_Configuration(void);
30 void LED_Config(void);
31 void Delay(__IO uint32_t nCount);
32 /****************************************************************************
33 * 名    称:void LED_Config(void)
34 * 功    能:LED 控制初始化函数
35 * 入口参数:无
36 * 出口参数:无
37 * 说    明:
38 * 调用方法:无 
39 ****************************************************************************/ 
40 void LED_Config(void){
41   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD , ENABLE);////////////333333333333333
42   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;                     //LED1  V6       //将V6,V7,V8 配置为通用推挽输出  
43   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
44   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;             //口线翻转速度为50MHz
45   GPIO_Init(GPIOB, &GPIO_InitStructure);//////////////4444444444444444444444444                     
46 
47   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_3;         //LED2, LED3     V7 V8
48   GPIO_Init(GPIOD, &GPIO_InitStructure);
49 }
50 /****************************************************************************
51 * 名    称:int main(void)
52 * 功    能:主函数
53 * 入口参数:无
54 * 出口参数:无
55 * 说    明:
56 * 调用方法:无 
57 ****************************************************************************/ 
58 int main(void)
59 {
60   RCC_Configuration();                   //系统时钟配置
61   LED_Config();                            //LED控制配置
62   while (1)
63   {
64       LED1_ON; LED2_OFF; LED3_OFF;        //LED1亮  LED2,LED3灭(LED2,LED3 仅V3,V2,V2.1板有)
65     Delay(0xAFFFF);
66     LED1_OFF; LED2_ON; LED3_OFF;        //LED2亮  LED1,LED3灭(LED2,LED3 仅V3,V2,V2.1板有)
67     Delay(0xAFFFF);
68     LED1_OFF; LED2_OFF; LED3_ON;        //LED3亮  LED1,LED2灭(LED2,LED3 仅V3,V2,V2.1板有)
69     Delay(0xAFFFF);    
70   }
71 }
72 /****************************************************************************
73 * 名    称:void RCC_Configuration(void)
74 * 功    能:系统时钟配置为72MHZ
75 * 入口参数:无
76 * 出口参数:无
77 * 说    明:
78 * 调用方法:无 
79 ****************************************************************************/ 
80 void RCC_Configuration(void)
81 {   
82   SystemInit();
83 }
84 /****************************************************************************
85 * 名    称:void Delay(__IO uint32_t nCount)
86 * 功    能:延时函数
87 * 入口参数:无
88 * 出口参数:无
89 * 说    明:
90 * 调用方法:无 
91 ****************************************************************************/ 
92 void Delay(__IO uint32_t nCount)
93 {
94    for(; nCount != 0; nCount--);
95 }
96 /******************* (C) COPYRIGHT 2011 奋斗STM32 *****END OF FILE****/

 

posted @ 2014-04-28 20:45  beautifulzzzz  阅读(639)  评论(0编辑  收藏  举报