新手入门
- 积分
- 7
- 金钱
- 7
- 注册时间
- 2026-1-10
- 在线时间
- 0 小时
|
1金钱
小编小白一个,刚刚开始接触,目前用正点原子的M100Z-M3小板,(搭载STM32F103VET6),用2个小发光二极管(led),正极连在3.3V引脚,负极先各连一个1k的电阻后分别连在B4,B7引脚。以下程序编译和下载都没有问题,但只有B7引脚的LED亮,为什么?
求大神解惑,
//---------------------stm32f10x.h------------------------
#define PERIPH_BASE ((uint32_t)0x40000000) /*!< Peripheral base address in the bit-band region */
#define AHBPERIPH_BASE (PERIPH_BASE + 0x20000)
#define APB2PERIPH_BASE (PERIPH_BASE + 0x10000)
#define GPIOB_BASE (APB2PERIPH_BASE + 0x0C00)
#define GPIOB_CRL *(unsigned int *)(GPIOB_BASE+0x00)
#define GPIOB_CRH *(unsigned int *)(GPIOB_BASE+0x04)
#define GPIOB_IDR *(unsigned int *)(GPIOB_BASE+0x08)
#define GPIOB_ODR *(unsigned int *)(GPIOB_BASE+0x0C)
#define GPIOB_BSRR *(unsigned int *)(GPIOB_BASE+0x10)
#define GPIOB_BRR *(unsigned int *)(GPIOB_BASE+0x14)
#define GPIOB_LCKR *(unsigned int *)(GPIOB_BASE+0x18)
#define RCC_BASE (AHBPERIPH_BASE + 0x1000)
#define RCC_APB2ENR *(unsigned int *)(RCC_BASE +0x18)
//--------------------------------main.c----------------------------
#include "stm32f10x.h"
#include <stdint.h>
void SystemInit(void)
{
}
int main(void)
{
RCC_APB2ENR |= (1<<3);
// 清除引脚4的配置
GPIOB_CRL &= ~(0x0F << (4*4)); // 清除CNF4和MODE4
// 设置引脚4为推挽输出,最大速度10MHz
GPIOB_CRL |= (1 << (4*4)); // MODE4[0]=1, MODE4[1]=0, CNF4[1:0]=00
// 清除引脚7的配置
GPIOB_CRL &= ~(0x0F << (4*7));
// 设置引脚7为推挽输出,最大速度10MHz
GPIOB_CRL |= (1 << (4*7));
// 将B4、B7都设置为低电平
GPIOB_ODR &= ~( (1<<4) | (1<<7) );
while(1);
}
|
|