0
我剛剛買了一個stm32l152RC,並想知道延遲是如何工作的。 系統時鐘爲16Mhz。延遲如何在stm32l152RC上工作?
代碼:
static volatile uint32_t TimingDelay;
void Delay(__IO uint32_t nCount);
int main(void) {
Config_Systick();
char *RCCp = (char*) 0x40023800;
int *PBp = (int *) 0x40020400;
// RCC Config
*((int*) (RCCp + 28)) |= 0x3f;
*((int*) (RCCp + 32)) |= 1;
*PBp = 0x5000;
while (1) {
GPIO_TOGGLE(GPIOB, LD_GREEN); //toggle green led
Delay(1000); // 1 second?
}
} // end of main
RCC_ClocksTypeDef RCC_Clocks;
void Config_Systick() {
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency/1000); // setting changed to/1000
}
void TimingDelay_Decrement(void) {
if (TimingDelay != 0x00) {
TimingDelay--;
}
}
void Delay(uint32_t nTime) {
TimingDelay = nTime;
while (TimingDelay != 0) {
};
}
當我在這種情況下延遲爲1秒執行Delay(1000);
,可能有人請解釋爲什麼延遲時間爲1秒?
@Olaf感謝您的回答,我確實讀過它。 –