支持了位带操作后,可以使用普通的加载
/
存储指令来对单一的比特进行读写。
在前面的库函数点灯的基础上进行修改
一、数据手册
二、地址选取(标黄区域)
三、代码
#include "led.h"
GPIO_InitTypeDef GPIO_InitStructure;
/*
PA ODR端口输出数据寄存器地址 0x40010800 + 0x0C = 0x4001080C
AliasAddr = 0x42000000 + ((A - 0x40000000) * 32 + n * 4)
A=0x4001080C ODR端口输出数据寄存器地址
n=引脚值
*/
/*******新添加的代码*********/
#define PA2 *(volatile uint32_t *)(0x42000000 + ((0x4001080C - 0x40000000) * 32 + 2 * 4))
void led_init(void)
{
/* GPIOD Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
/* Configure PC13 in output pushpull mode */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/*******更新的代码*********/
PA2=1;
}
void led_on(void)
{
/*******更新的代码*********/
PA2=0;
}
void led_off(void)
{
/*******更新的代码*********/
PA2=1;
}