Add Delay Function

This commit is contained in:
Uttam Bhavimani Bhavimani 2024-09-20 20:21:11 +05:30
parent 749fcb45ee
commit 4fd7019fd3
1 changed files with 9 additions and 0 deletions

9
main.c
View File

@ -29,3 +29,12 @@ void systick_setting(void) // SYSTICK SETUP FUNCTION
STCTRL |= (1 << 0) | (1 << 2); // Enable SysTick with system clock STCTRL |= (1 << 0) | (1 << 2); // Enable SysTick with system clock
STCURRENT = 0; // Clear current value STCURRENT = 0; // Clear current value
} }
void delay(int us) //DEFINING DELAY FUNCTION
{
STRELOAD = SYSTICK_RELOAD_VALUE(us); // RELOAD VALUE FOR REQUIRED DELAY
STCURRENT = 0; // Clear STCURRENT
STCTRL |= (1 << 0) | (1 << 2); // Enable SysTick
while ((STCTRL & (1 << 16)) == 0); // Wait until flag is set
STCTRL &= 0x0; // Stop the timer
}