TIM初始化和gpio初始化如下
/*
* fsmc.c
*
* Created on: 2022年3月25日
* Author: 10050
*/
#include "fsmc.h"
void fsmc_lcd_init(void)
{
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
GPIO_InitTypeDef gpiox = {
.GPIO_Mode = GPIO_Mode_AF_PP,
.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_7|GPIO_Pin_12|GPIO_Pin_14|GPIO_Pin_15,
.GPIO_Speed = GPIO_Speed_50MHz
};
GPIO_Init(GPIOD, &gpiox);
gpiox.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;
GPIO_Init(GPIOE, &gpiox);
gpiox.GPIO_Pin = GPIO_Pin_14;
GPIO_Init(GPIOB, &gpiox);
TIM_TimeBaseInitTypeDef timx = {
.TIM_CounterMode = TIM_CounterMode_Up,
.TIM_Period = 999,
.TIM_Prescaler = 49,
.TIM_RepetitionCounter = 1
};
TIM_TimeBaseInit(TIM1, &timx);
TIM_OCInitTypeDef ocx = {
.TIM_OCMode = TIM_OCMode_PWM1,
.TIM_OCNIdleState = TIM_OCNIdleState_Set,
.TIM_OCNPolarity = TIM_OCNPolarity_High,
.TIM_Pulse = 500
};
TIM_OC1Init(TIM1, &ocx);
TIM_CCxNCmd(TIM1,TIM_Channel_2,ENABLE);
TIM_Cmd(TIM1,ENABLE);
}
`
main
`/********************************** (C) COPYRIGHT *******************************
* File Name : main.c
* Author : WCH
* Version : V1.0.0
* Date : 2021/06/06
* Description : Main program body.
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/
/*
*@Note
串口打印调试例程:
USART1_Tx(PA9)。
本例程演示使用 USART1(PA9) 作打印调试口输出。
*/
#include "debug.h"
#include "key.h"
#include "fsmc.h"
/* Global typedef */
/* Global define */
/* Global Variable */
/*********************************************************************
* @fn main
*
* @brief Main program.
*
* @return none
*/
uint8_t key_temp=0x00;
int main(void)
{
key_init();
Delay_Init();
USART_Printf_Init(115200);
fsmc_lcd_init();
while(1)
{
key_temp = key_read();
Delay_Ms(100);
printf("key_test = %X\r\n",key_temp);
}
}
而且外设调试还看不了,完全不动