初级会员

- 积分
- 156
- 金钱
- 156
- 注册时间
- 2021-7-22
- 在线时间
- 28 小时
|
2金钱
(一)将以下代码添加在sys.c末端:
- void GPIO_QuickInit(GPIO_TypeDef * GPIOx, uint16_t GPIO_Pin, GPIOMode_TypeDef GPIO_Mode)
- {
- GPIO_InitTypeDef GPIO_InitStruct1;
-
- switch((uint32_t)GPIOx)
- {
- case (uint32_t)GPIOA:
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
- break;
- case (uint32_t)GPIOB:
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
- break;
- case (uint32_t)GPIOC:
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
- break;
- case (uint32_t)GPIOD:
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
- break;
- case (uint32_t)GPIOE:
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);
- break;
- case (uint32_t)GPIOF:
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);
- break;
- }
- if(GPIOx == GPIOB)
- {
- if((GPIO_Pin == GPIO_Pin_3)|(GPIO_Pin == GPIO_Pin_4))
- GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
- }
- if(GPIOx == GPIOA)
- {
- if(GPIO_Pin == GPIO_Pin_15)
- GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
- }
-
- if(GPIOx == GPIOA)
- {
- if((GPIO_Pin == GPIO_Pin_13)|(GPIO_Pin == GPIO_Pin_14))
- GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
- }
-
- GPIO_InitStruct1.GPIO_Mode = GPIO_Mode;
- GPIO_InitStruct1.GPIO_Pin = GPIO_Pin;
- GPIO_Init(GPIOx, &GPIO_InitStruct1);
- }
复制代码
(二)然后在sys.h中添加如下的代码:
- void GPIO_QuickInit(GPIO_TypeDef * GPIOx, uint16_t GPIO_Pin, GPIOMode_TypeDef GPIO_Mode);
复制代码 具体位置如图所示:
(三)最后在led.c中加入如下代码:
- GPIO_QuickInit(GPIOA, GPIO_Pin_8, GPIO_Mode_Out_PP);
- GPIO_QuickInit(GPIOD, GPIO_Pin_2, GPIO_Mode_Out_PP);
复制代码 并在此文件引入sys.h
具体位置如图所示:
以上是整个改写过程。
但是烧录到板子上led灯不亮(板子的led是好的)。还请能够指点一下。
|
最佳答案
查看完整内容[请看2#楼]
仿真器 进调试 看一下有没有符合自己的逻辑运行就知道了!最后还是得设置到寄存器里边!还有控制LED灯正常是用推挽输出吧!没看到有配置输出!强制类型转换的最好是自己定义一个变量读取之后,再转别去转原来的变量 不然容易出问题!
|