main文件

#include "stm32f10x.h"
#include "usart1.h"
#include "delay.h"
#include <stdio.h>
#include "led.h"
#include "key.h"
#include "tim1.h"
void KEY_INIT(){
    RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;
    GPIOA->CRL |= GPIO_CRL_MODE6;
    GPIOA->CRL &= ~GPIO_CRL_CNF6;
    GPIOA->CRL |= GPIO_CRL_CNF6_1;
    GPIOA->ODR |= GPIO_ODR_ODR6;
}
uint8_t KEY_PressDecte(){
    return !(GPIOA->IDR & GPIO_IDR_IDR6);
}
void BKP_Init(){

    //使能BKP写入
    PWR->CR |= PWR_CR_DBP;
    //判断是否写入过值

    //复位备份域
    RCC->BDCR |= RCC_BDCR_BDRST;
    //解除备份域复位
    RCC->BDCR &= ~RCC_BDCR_BDRST;
    //使能RTC时钟
    RCC->BDCR |= RCC_BDCR_RTCEN;
    //使能LSE
    RCC->BDCR |= RCC_BDCR_LSEON;
    while ((RCC->BDCR & RCC_BDCR_LSERDY)==0);
    //配置RTC时钟位LSE
    RCC->BDCR &= ~RCC_BDCR_RTCSEL;
    RCC->BDCR |= RCC_BDCR_RTCSEL_0;
}
int main()
{    
    USART1_Init();
    printf("test\n");
    //电源控制器使能
    RCC->APB1ENR |= RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN;
    if(BKP->DR1==0){
    BKP_Init();
    BKP->DR1 =65535;
    }
       
    while (1)
    {
       if(KEY_PressDecte()){
        delay_ms(15);
        if(KEY_PressDecte()){
            printf("BKP_D1=%x\n",BKP->DR1);
        }
       }
    }
}
 

Logo

智能硬件社区聚焦AI智能硬件技术生态,汇聚嵌入式AI、物联网硬件开发者,打造交流分享平台,同步全国赛事资讯、开展 OPC 核心人才招募,助力技术落地与开发者成长。

更多推荐