Update Group21_Lab06_Task1/main.c

Add Delay Function
This commit is contained in:
Uttam Bhavimani Bhavimani 2024-09-22 19:41:56 +05:30
parent b44cc3d7d4
commit 3304d13223
1 changed files with 9 additions and 0 deletions

View File

@ -39,3 +39,12 @@ void systick_setting(void)
STCTRL |= (CLKINT | ENABLE | INTEN); // Set internal clock, enable the timer STCTRL |= (CLKINT | ENABLE | INTEN); // Set internal clock, enable the timer
STCURRENT = 0; // Clear STCURRENT value STCURRENT = 0; // Clear STCURRENT 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
}