Marquee Experiment-Register Version

Preface

  • Because I didn't learn the 51 microcontroller well at the beginning, it is now very difficult to learn the 32 microcontroller. Listening to the teacher's lecture, I feel like I am in outer space. The following is a series of knowledge points through the example of marquee.

Briefly understand GPIO

  • Battleship and Elite Edition (stm32f103zet6) are both 144-pin chips with seven groups of IOs, GPIOA-GPIOG. Each group of IO has 16 IOs, a total of 16*7=112 IOs.

  • The mini version (STM32F103RCT6) has a total of four groups of IO ports, with a total of 16*3+3 io
    GPIOA0——GPIOA15
    GPIOB0——GPIOB15
    GPIOC0——GPIOC15
    GPIOD0——GPIOD2

  • GPIO working mode
    four input modes:
    input floating input pull-
    up input
    pull-down four output modes of
    analog input open-drain output (only strong low level can be output, high level must be pulled high by an external resistor) open-drain multiplexing function push-pull Type output (can output strong high and low levels, connected to digital devices) Push-pull multiplexing function Three maximum flip speeds -2MHZ -10MHz -50MHz The registers of each group of GPIO ports include: two 32-bit configuration registers (GPIOx-CRL, GPIOx-CRH), two 32-bit data registers (GPIOx-IDR, GPIO-ODR), (the lower 16 bits are used, the upper 16 bits are reserved. Control 16 ios)











    A 32-bit bit/reset register (GPIOx-BSRR), mainly controls the ODR register,
    a 16-bit reset register (GPIOx_BRR), and
    a 32-bit lock register (GPIOx-LCKR).

    Each I/O port bit can be freely programmed, however the I/O port register must be accessed as a 32-bit word
    (halfword or byte access is not allowed)
    stm32 pin description
    Most ports of STM32 have multiplexing functions .
    The so-called reuse means that some ports can not only be used as general IO ports, but also can reuse some
    peripheral pins, such as PA9 and PA10, which can be reused as STM32 serial port 1 pin
    . Function: maximize the use of port resources

    The port remapping function
    allows you to map certain function pins to other pins.
    For example, the default pin of serial port 1 is PA9. PA10 can be mapped to PB6 through configuration remapping.
    The function of PB7 is to facilitate wiring.

    All IO ports can be used as interrupt inputs

ticker code

  • led.h header file
#ifndef __LED_H
#define __LED_H
void LED_Init(void);


#endif


  • led.c source file
#include "led.h"
#include "stm32f10x.h"

void LED_Init(void){
    
    
	RCC->APB2ENR|=1<<3;   //A=A|B ,设置IO端口B的时钟开启
	RCC->APB2ENR|=1<<6;	  //A=A|B ,设置IO端口E的时钟开启
	
	//GPIOB.5
	GPIOB->CRL&=0xFF0FFFFF; //先清零,与0
	GPIOB->CRL|=0x00300000; //设置工作模式为推挽输出,50MHZ
	GPIOB->ODR|=1<<5;   //初始化PB5为高电平
	
	GPIOE->CRL&=0xFF0FFFFF; //先清零,与0
	GPIOE->CRL|=0x00300000; //设置工作模式为推挽输出,50MHZ
	GPIOE->ODR|=1<<5;    //初始化PE5为高电平
}

  • main.c
#include "stm32f10x.h"
#include "delay.h"
#include "led.h"
int main(void)
{
    
    
delay_init();
LED_Init();
	while(1){
    
    
		GPIOB->ODR|=1<<5;	//设置PB5为高电平
		GPIOE->ODR|=1<<5;	//设置PE5为高电平
		delay_ms(500);
		
		GPIOB->ODR&=~(1<<5);   //设置PB5为低电平
		GPIOE->ODR&=~(1<<5);  //设置PE5为低电平
		delay_ms(500);

}
	


}

Guess you like

Origin blog.csdn.net/sx17860543449/article/details/109705926