• LED


    外设的基地址,STM32固件库,API函数

    学会看数据手册调用数据

    封装了好多寄存器

    指针类型,指针运算符

    宏定义放.h文件中

    外设时钟的设置,开启端口时钟

    低寄存器,输出模式

    端口位设置/清除寄存器

    运算

    看数据手册的8.2GPIO寄存器描述

    根据电路来写程序

    程序的移植

    帮助文档很重要(AD,STM32等)

    下载福昕和UE

     

     

     

     

     初始化

    #ifndef _led_H
    #define _led_H


    #endif        //不会报重复错误的错

    移植直接改宏,定义宏,代码移植性

     

    时序

    点亮LED3

     main.c

    #include "stm32f10x.h"
    #include "led.h"


    int main()
    {
    LED_Init();

    while(1)
    {
    GPIO_ResetBits(LED_PORT,GPIO_Pin_2);//点亮LED3
    }
    }

    LED.C

    #include "led.h"


    void LED_Init( )
    {
    GPIO_InitTypeDef GPIO_InitStructure;

    RCC_APB2PeriphClockCmd(LED_PORT_RCC,ENABLE);

    GPIO_InitStructure.GPIO_Pin=LED_PIN;
    GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_Init(LED_PORT,&GPIO_InitStructure);

    GPIO_SetBits(LED_PORT,LED_PIN);

    }

    LED.H

    #ifndef _led_H
    #define _led_H


    #include "stm32f10x.h"

    #define LED_PORT_RCC RCC_APB2Periph_GPIOC
    #define LED_PIN (GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7)
    #define LED_PORT GPIOC

    void LED_Init(void );

    #endif

    数码管随着点亮led灯,a到g亮一杠

  • 相关阅读:
    [Everyday Mathematics]20150208
    [Everyday Mathematics]20150207
    [Everyday Mathematics]20150206
    数学基本技艺100题
    这天,白云酒楼里来了两位客人
    [Everyday Mathematics]20150205
    [Everyday Mathematics]20150204
    数学书籍阅读
    国科金发计〔2014〕86号
    [Everyday Mathematics]20150203
  • 原文地址:https://www.cnblogs.com/296389183yy/p/9284404.html
Copyright © 2020-2023  润新知