野火stm32指南者开发板点亮LED
目录[*]1.芯片手册中的LED电路图
[*]2.官网手册
[*]3.代码演示
[*]3.1 stm32f10x.h头文件
[*]3.2 点亮绿灯
[*]3.3 点亮蓝灯
[*]3.4 点亮红灯
[*]3.5 LED灯闪烁,绿灯闪烁 。
[*]3.6 红绿蓝三色LED灯切换闪烁
1.芯片手册中的LED电路图
https://img-blog.csdnimg.cn/34c2a95aa89c4cbe8a7904429d889564.png
2.官网手册
https://img-blog.csdnimg.cn/e9b1131dcc0f48b6919e8ed8778c7d03.png
https://img-blog.csdnimg.cn/33cf1877147049cab17b0152c42e151c.png
3.代码演示
3.1 stm32f10x.h头文件
#ifndef _STM32F10X_H
#define _STM32F10X_H
/*片上外设基地址 */
#define PERIPH_BASE ((unsigned int)0x40000000)
// APB1 总线基地址
#define APB1PERIPH_BASE PERIPH_BASE
// APB2 总线基地址
#define APB2PERIPH_BASE (PERIPH_BASE + 0x10000)
// AHB 总线基地址
#define AHBPERIPH_BASE (PERIPH_BASE + 0x20000)
/* GPIOB */
#define GPIOB_BASE (APB2PERIPH_BASE + 0x0C00)
// 端口配置低寄存器 PB0-PB7 配置是输入还是输出
#define GPIOB_CRL *(unsigned int*)(GPIOB_BASE+0x00)
// 端口配置高寄存器 PB8-PB15 配置是输入还是输出
#define GPIOB_CRH *(unsigned int*)(GPIOB_BASE+0x04)
#define GPIOB_IDR *(unsigned int*)(GPIOB_BASE+0x08)
// 端口输出数据寄存器 配置PB0-PB15是高电平还是低电平
#define GPIOB_ODR *(unsigned int*)(GPIOB_BASE+0x0C)
#define GPIOB_BSRR *(unsigned int*)(GPIOB_BASE+0x10)
#define GPIOB_BRR *(unsigned int*)(GPIOB_BASE+0x14)
#define GPIOB_LCKR *(unsigned int*)(GPIOB_BASE+0x18)
/* 时钟端口 */
#define RCC_BASE (AHBPERIPH_BASE + 0x1000)
// GPIOB所在的时钟端口
#define RCC_APB2ENR(*(unsigned int *)(RCC_BASE + 0X18))
#endif3.2 点亮绿灯
#include "stm32f10x.h"void SystemInit(void){}int main(void){ // 打开 GPIOB 端口的时钟 RCC_APB2ENR|=( (1)
页:
[1]