初學stm32,用推挽模式 讓 A0口01循環,led左側必須接電源才亮,如A0口,若左側接地則完全沒反應,如B1口,是代碼的問題還是仿真的問題
看教程說推挽輸出是強驅動,不應該連個led都驅動不了
51hei圖片20221117140926.png (31.43 KB, 下載次數: 12)
下載附件
2022-11-17 14:22 上傳
代碼如下
#include "stm32f10x.h" // Device header
#include "Delay.h"
int main(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_Init(GPIOB, &GPIO_InitStructure);
while (1)
{
GPIO_WriteBit(GPIOB, GPIO_Pin_1, (BitAction)1);
Delay_ms(500);
GPIO_ResetBits(GPIOA, GPIO_Pin_0);
Delay_ms(500);
GPIO_SetBits(GPIOA, GPIO_Pin_0);
Delay_ms(500);
}
}
|