測試條件:STM32F103VET6開發板


#include "stm32f10x.h"
void Delay_Nms(unsigned int n)
{
SysTick->LOAD=9000*n;//裝入初始值,定時時間為1/(72M/8) *9000 s
SysTick->CTRL=0x00000001; //設置始終源為系統始終八分頻,并打開定時器
while(!(SysTick->CTRL&0x00010000));//等待遞減計數器減到0
SysTick->CTRL=0x00000000;//關閉定時器
}
int main(void)
{
SystemInit();//配置系統時鐘
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);//使能APB2外設時鐘
GPIO_InitTypeDefGPIO_InitStructure; //定義I/O口結構體
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_Out_PP;//推挽輸出
GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_ResetBits(GPIOC, GPIO_Pin_6);
while(1)
{
GPIO_SetBits(GPIOC, GPIO_Pin_6);
Delay_Nms(1000); //延時1s
GPIO_ResetBits(GPIOC, GPIO_Pin_6);
Delay_Nms(1000);
}
}
//以下是報錯函數
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
while (1)
{
}
}
#endif
|