STM32中SYSTEM文件夹
F1: delay_init()函数 void delay_init(uint16_t sysclk) { SysTick->CTRL=0; HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK_DIV8); g_fac_us=sysclk/8;//set Crossover factor as 8 } delay_us()函数: void delay_us(uint32_t nus) { uint32_t temp; SysTick->LOAD=nus*g_fac_us;//load time SysTick->VAL=0x00;//clear counter SysTick->CTRL|=1<<0;//start count back do { temp=SysTick->CTRL; }while((temp&0x01)&&!(temp&(1<<16))); SysTick->CTRL&=~(1<<0);//closeSYSTICK SysTick->VAL=0X00;//clear counter } delay_ms()函数: void delay_ms(uint16_t nms) { uint32_t repeat =nms/1000; uint32_t remain=nms%1000; while(repeat) { delay_us(1000*1000); repeat--; } if(remain) { delay_us(remain*1000); } }
嵌入式入门 文章被收录于专栏
嵌入式入门合集