写个简单的LED程序试下,发现LED不能闪烁。程序如下: u16 i = 10000; //SysTick_Config(SystemCoreClock / 1000); /* GPIOE Periph clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* Configure PA5 Pin output pushpull mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; //GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); /* To achieve GPIO toggling maximum frequency, the following sequence is mandatory. You can monitor PE14 and PE15 on the scope to measure the output signal. If you need to fine tune this frequency, you can add more GPIO set/reset cycles to minimize more the infinite loop timing. This code needs to be compiled with high speed optimization option. */ while (1) { GPIO_SetBits(GPIOA, GPIO_Pin_5); while(i--); GPIO_ResetBits(GPIOA, GPIO_Pin_5); while(i--); } 请高手指点下。 |
{
i = 10000;
GPIO_SetBits(GPIOA, GPIO_Pin_5);
while(i--);
i = 10000;
GPIO_ResetBits(GPIOA, GPIO_Pin_5);
while(i--);
}
减到0后变成最大值,还是有延时效果的,只是时间太短:)
你的主频是多少?
如果是gcc之类的编译器,i的变量定义要加上volatile。
如果是48M的话,可以这样:
for(volatile int i=0;i<480000;i++);
延迟时间短吧,人眼能分辨的时间大于等于20MS,即50HZ以上的频率分辨不出来,延迟的短了,LED闪烁频率超过50HZ,人眼分辨不出来,看上去一直亮