嵌入式 【寄存器编程】

寄存器编程跟库函数的编程方式是一样的

 

 

//led.c

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

void LED_Init(void)
{
 //¼Ä´æÆ÷±à³Ì
    RCC->APB2ENR|=1<<3;
    RCC->APB2ENR|=1<<6;    //ʱÖÓ´ò¿ª
    
    
    //GPIOB.5
    GPIOB->CRL &= 0xFF0FFFFF;  //ËÄλÇåÁã
    GPIOB->CRL |= 0x00300000;  //ÉèÖµ
    GPIOB->ODR |= 1<<5;
    
  //GPIOE.5
    GPIOE->CRL &= 0xFF0FFFFF;  //ËÄλÇåÁã
    GPIOE->CRL |= 0x00300000;  //ÉèÖµ
    GPIOE->ODR |= 1<<5;
    
    
 
}

 

#ifndef __LED_H__
#define __LED_H__

void LED_Init(void);


#endif
led.h

 

//main.c

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

int main(void)
{
  delay_init();
    LED_Init();
    
    
    while(1)
    {
     //GPIO_SetBits(GPIOB,GPIO_Pin_5);
        GPIOB->ODR |=1<<5; 
     //GPIO_ResetBits(GPIOE,GPIO_Pin_5);
        GPIOE->ODR |=1<<5;
      delay_ms(5000);
    
     //GPIO_SetBits(GPIOE,GPIO_Pin_5);
        GPIOB->ODR =~(1<<5);
     //GPIO_ResetBits(GPIOB,GPIO_Pin_5);
        GPIOE->ODR =~(1<<5);
     delay_ms(5000);
    
    }

}

 

posted @ 2019-04-07 14:51  Crown-V  阅读(275)  评论(0)    收藏  举报