硬件平台:正点原子——mini版
一、用ODR寄存器
main.c
#include"stm32f10x.h"
#include "led.h"
#include "delay.h"
int main()
{
LED_Init();
delay_init();
while(1)
{
GPIOA->ODR|=1<<8;
GPIOD->ODR|=1<<2;
delay_ms(500);
GPIOA->ODR&=~(1<<8);//先非再与,只改变移动位
GPIOD->ODR&=~(1<<2);
delay_ms(500);
}
return 0;
}
led.c
#include "led.h"
#include "stm32f10x.h"
void LED_Init(void)
{
RCC->APB2ENR |=1<<2;//左移2位(对应数据手册的GPIOA口)
RCC->APB2ENR |=1<<5;//左移5位(对应数据手册的GPIOD口)
//GPIO A8 mini要配置的是A9 0-7为CRL配置 8-15CRH配置
GPIOA->CRH&=0xFFFFFFF0;//在赋值前先将要赋值的位清零(因为是与运算,其他位我们给1,清零为给0)
GPIOA->CRH|=0x00000003;//为什么是3,在CRH中4-7位配置我们要输出的gpio9口