野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 22813|回复: 4

如何生存 Led.c 和Led.h 文件

[复制链接]
发表于 2014-5-9 17:04:44 | 显示全部楼层 |阅读模式
int main(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOF,ENABLE); //使能GPIOB和GPIOF端口;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;         //GPIO设置为推挽模式
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;         //GPIO管脚的速度为50MHZ;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;                                    //LED1 链接PB0
GPIO_Init(GPIOB,&GPIO_InitStruct);            //初始化GPIOB
GPIO_SetBits(GPIOB, GPIO_Pin_0);                                          //初始化状态的时候LED1是熄灭的
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;                                    //LED2 链接PF7管脚
GPIO_Init(GPIOF,&GPIO_InitStruct);            //初始化GPIOB
GPIO_SetBits(GPIOF, GPIO_Pin_7);                                          //初始化状态的时候LED2是熄灭的
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8;                                    //LED3 链接PF8管脚
GPIO_Init(GPIOF,&GPIO_InitStruct);            //初始化GPIOB
GPIO_SetBits(GPIOF, GPIO_Pin_8);                                          //初始化状态的时候LED2是熄灭的
   while(1)
{
  GPIO_ResetBits(GPIOB,GPIO_Pin_0);           //点亮LED1灯
  Delay(3000000);
     GPIO_ResetBits(GPIOF,GPIO_Pin_7);           //点亮LED2灯
  Delay(3000000);
  GPIO_ResetBits(GPIOF,GPIO_Pin_8);           //点亮LED3灯
  Delay(3000000);
  GPIO_SetBits(GPIOB, GPIO_Pin_0);                                          //熄灭LED1灯
  Delay(3000000);
  GPIO_SetBits(GPIOF, GPIO_Pin_7);                                          //熄灭LED2灯
  Delay(3000000);
  GPIO_SetBits(GPIOF, GPIO_Pin_8);                                          //熄灭LED3灯
  Delay(3000000);
}
   /* add your code here ^_^. */
}
回复

使用道具 举报

发表于 2014-5-9 17:06:14 | 显示全部楼层
如何生存 Led.c 和Led.h 文件 ? 问题具体一点吧,不清楚你想表达什么
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-5-9 17:33:27 | 显示全部楼层

第一段代码如下 在代码中有 #include "led.h" #include "delay.h"  等头文件
#include "led.h"
#include "delay.h"
#include "sys.h"
int main(void)
{       
        delay_init();                     //延时函数初始化          
        LED_Init();                          //初始化与LED连接的硬件接口
        while(1)
        {
                GPIO_ResetBits(GPIOB,GPIO_Pin_5);
                GPIO_SetBits(GPIOE,GPIO_Pin_5);
                delay_ms(300);
                GPIO_SetBits(GPIOB,GPIO_Pin_5);
                GPIO_ResetBits(GPIOE,GPIO_Pin_5);
                delay_ms(300);
        }
}

第二段代码如下 没有#include "led.h" #include "delay.h"  等头文件
#include "stm32f10x.h"

void Delay(__IO uint32_t nCount)
{
  for(; nCount != 0; nCount--);
}

int main(void)
{
        GPIO_InitTypeDef GPIO_InitStruct;
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOF,ENABLE); //使能GPIOB和GPIOF端口;

        GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;                                                          //GPIO设置为推挽模式
        GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;                                                          //GPIO管脚的速度为50MHZ;

        GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;                                    //LED1 链接PB0
        GPIO_Init(GPIOB,&GPIO_InitStruct);                                                                                  //初始化GPIOB
        GPIO_SetBits(GPIOB, GPIO_Pin_0);                                          //初始化状态的时候LED1是熄灭的

        GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;                                    //LED2 链接PF7管脚
        GPIO_Init(GPIOF,&GPIO_InitStruct);                                                                                  //初始化GPIOB
        GPIO_SetBits(GPIOF, GPIO_Pin_7);                                          //初始化状态的时候LED2是熄灭的

        GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8;                                    //LED3 链接PF8管脚
        GPIO_Init(GPIOF,&GPIO_InitStruct);                                                                                  //初始化GPIOB
        GPIO_SetBits(GPIOF, GPIO_Pin_8);                                          //初始化状态的时候LED2是熄灭的
          while(1)
        {
                GPIO_ResetBits(GPIOB,GPIO_Pin_0);                                                                          //点亮LED1灯
                Delay(3000000);
                   GPIO_ResetBits(GPIOF,GPIO_Pin_7);                                                                          //点亮LED2灯
                Delay(3000000);
                GPIO_ResetBits(GPIOF,GPIO_Pin_8);                                                                          //点亮LED3灯
                Delay(3000000);
                GPIO_SetBits(GPIOB, GPIO_Pin_0);                                      //熄灭LED1灯
                Delay(3000000);
                GPIO_SetBits(GPIOF, GPIO_Pin_7);                                      //熄灭LED2灯
                Delay(3000000);
                GPIO_SetBits(GPIOF, GPIO_Pin_8);                                      //熄灭LED3灯
                Delay(3000000);
        }
          /* add your code here ^_^. */
}


这两段代码都是跑马灯的实验 我的问题是 如何将GPIO初始化部分向第一段代码那样一头文件的方式表示
回复 支持 反对

使用道具 举报

发表于 2014-5-9 18:44:00 | 显示全部楼层
BlueSky 发表于 2014-5-9 17:33
第一段代码如下 在代码中有 #include "led.h" #include "delay.h"  等头文件
#include "led.h"
#includ ...

新建文件,然后保存成.c  .h文件就可以了
回复 支持 反对

使用道具 举报

发表于 2014-5-10 09:38:15 | 显示全部楼层
看视频,里面有教如何新建工程。最好直接从新建工程开始把程序搞一遍,就知道怎么回事了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-9-22 18:12 , Processed in 0.039012 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表